Skip to content

Commit

Permalink
Merge pull request mozilla#7897 from Snuffleupagus/eslint-switch
Browse files Browse the repository at this point in the history
Switch to using ESLint, instead of JSHint, for linting
  • Loading branch information
timvandermeij authored Dec 16, 2016
2 parents 78927b8 + ef60633 commit 6af6f21
Show file tree
Hide file tree
Showing 86 changed files with 252 additions and 166 deletions.
File renamed without changes.
108 changes: 108 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"parserOptions": {
"ecmaVersion": 5,
},

"env": {
"browser": true,
"es6": true,
"worker": true,
"amd": true,
},

globals: {
"PDFJSDev": false,
"require": false,
"exports": false,
},

"rules": {
// Possible errors
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", { "checkLoops": false, }],
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": ["error", { "allowEmptyCatch": true, }],
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-negation": "error",
"use-isnan": "error",
"valid-typeof": ["error", { "requireStringLiterals": true, }],

// Best Practices
"accessor-pairs": ["error", { "setWithoutGet": true, }],
"curly": ["error", "all"],
"eqeqeq": ["error", "always"],
"no-caller": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-new": "error",
"no-octal-escape": "error",
"no-redeclare": "error",
"no-self-assign": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-concat": "error",
"wrap-iife": ["error", "any"],
"yoda": ["error", "never", { "onlyEquality": true, }],

// Strict Mode
"strict": ["error", "global"],

// Variables
"no-catch-shadow": "error",
"no-label-var": "error",
"no-shadow-restricted-names": "error",
"no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }],

// Stylistic Issues
"array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true, }],
"comma-spacing": ["error", { "before": false, "after": true, }],
"comma-style": ["error", "last"],
"eol-last": "error",
"func-call-spacing": ["error", "never"],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict", }],
"keyword-spacing": ["error", { "before": true, "after": true, }],
"linebreak-style": ["error", "unix"],
"max-len": ["error", 80],
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, }],
"new-parens": "error",
"no-array-constructor": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 0, "maxBOF": 1, }],
"no-tabs": "error",
"no-trailing-spaces": ["error", { "skipBlankLines": false, }],
"no-whitespace-before-property": "error",
"operator-linebreak": ["error", "after", { "overrides": { ":": "ignore", } }],
"quotes": ["error", "single"],
"semi-spacing": ["error", { "before": false, "after": true, }],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", { "anonymous": "ignore", "named": "never", }],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["error", { "int32Hint": false }],
"space-unary-ops": ["error", { "words": true, "nonwords": false, "overrides": { "void": false, }, }],
},
}
33 changes: 0 additions & 33 deletions .jshintrc

This file was deleted.

3 changes: 1 addition & 2 deletions examples/mobile-viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* globals PDFJS, Promise */
/* globals PDFJS */

'use strict';

Expand Down
1 change: 1 addition & 0 deletions extensions/chromium/options/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* globals chrome */

(function() {
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* globals chrome, Promise */
/* globals chrome */

'use strict';
var storageAreaName = chrome.storage.sync ? 'sync' : 'local';
Expand Down
1 change: 1 addition & 0 deletions extensions/chromium/pdfHandler-vcros.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* globals chrome, getViewerURL */

(function() {
Expand Down
1 change: 1 addition & 0 deletions extensions/chromium/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* globals chrome, crypto, Headers, Request */

(function() {
Expand Down
9 changes: 9 additions & 0 deletions extensions/firefox/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
../../.eslintrc
],

"parserOptions": {
"ecmaVersion": 6
},
}
1 change: 0 additions & 1 deletion extensions/firefox/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, dump, XPCOMUtils, PdfStreamConverter,
APP_SHUTDOWN, PdfjsChromeUtils, PdfjsContentUtils */

Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/chrome/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsContentUtils,
PdfjsContentUtils, PdfStreamConverter, addMessageListener */

Expand Down
2 changes: 1 addition & 1 deletion extensions/firefox/content/PdfJs-stub.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true, maxlen:100 */
/* eslint max-len: ["error", 100] */

'use strict';

Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/content/PdfJs.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsChromeUtils,
PdfjsContentUtils, PdfStreamConverter */

Expand Down
2 changes: 1 addition & 1 deletion extensions/firefox/content/PdfJsTelemetry-addon.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true, maxlen:120 */
/* eslint max-len: ["error", 120] */
/* globals Components, Services */

'use strict';
Expand Down
2 changes: 1 addition & 1 deletion extensions/firefox/content/PdfJsTelemetry.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true, maxlen: 100 */
/* eslint max-len: ["error", 100] */
/* globals Components, Services */

'use strict';
Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils,
dump, NetworkManager, PdfJsTelemetry, PdfjsContentUtils */

Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/content/PdfjsChromeUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils */

'use strict';
Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/content/PdfjsContentUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils */

'use strict';
Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/content/pdfjschildbootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint esnext:true */
/* globals Components, PdfjsContentUtils, PdfJs, Services */

'use strict';
Expand Down
1 change: 0 additions & 1 deletion extensions/firefox/tools/l10n.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

// Small subset of the webL10n API by Fabien Cazenave for pdf.js extension.
Expand Down
10 changes: 10 additions & 0 deletions external/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
../.eslintrc
],

"env": {
"node": true,
"shelljs": true,
},
}
7 changes: 1 addition & 6 deletions external/builder/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint node:true */
/* globals cp, ls, test */

'use strict';

var fs = require('fs'),
Expand Down Expand Up @@ -107,10 +104,8 @@ function preprocess(inFilename, outFilename, defines) {
var line;
var state = STATE_NONE;
var stack = [];
var control =
/* jshint -W101 */
var control = // eslint-disable-next-line max-len
/^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
/* jshint +W101 */
var lineNumber = 0;
var loc = function() {
return fs.realpathSync(inFilename) + ':' + lineNumber;
Expand Down
11 changes: 11 additions & 0 deletions external/builder/fixtures/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
../../.eslintrc
],

"rules": {
"no-empty": "off",
"keyword-spacing": "off",
"space-infix-ops": "off",
},
}
14 changes: 8 additions & 6 deletions external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* jshint node:true */

'use strict';

var esprima = require('esprima');
Expand Down Expand Up @@ -197,21 +195,25 @@ function fixComments(ctx, node) {
}
// Fixes double comments in the escodegen output.
delete node.trailingComments;
// Removes jshint and other service comments.
// Removes ESLint and other service comments.
if (node.leadingComments) {
var CopyrightRegExp = /\bcopyright\b/i;
var BlockCommentRegExp = /^\s*(globals|eslint|falls through|umdutils)\b/;
var LineCommentRegExp = /^\s*eslint\b/;

var i = 0;
while (i < node.leadingComments.length) {
var type = node.leadingComments[i].type;
var value = node.leadingComments[i].value;

if (ctx.saveComments === 'copyright') {
// Remove all comments, except Copyright notices and License headers.
if (!(type === 'Block' && /\bcopyright\b/i.test(value))) {
if (!(type === 'Block' && CopyrightRegExp.test(value))) {
node.leadingComments.splice(i, 1);
continue;
}
} else if (type === 'Block' &&
/^\s*(globals|jshint|falls through|umdutils)\b/.test(value)) {
} else if ((type === 'Block' && BlockCommentRegExp.test(value)) ||
(type === 'Line' && LineCommentRegExp.test(value))) {
node.leadingComments.splice(i, 1);
continue;
}
Expand Down
2 changes: 0 additions & 2 deletions external/builder/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* jshint node:true */
/* globals cat, cd, echo, ls */
'use strict';

require('shelljs/make');
Expand Down
2 changes: 0 additions & 2 deletions external/builder/test2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* jshint node:true */
/* globals cat, cd, echo, ls */
'use strict';

require('shelljs/make');
Expand Down
3 changes: 0 additions & 3 deletions external/crlfchecker/crlfchecker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint node:true */
/* globals cat, echo, exit, ls */

'use strict';

function checkIfCrlfIsPresent(files) {
Expand Down
1 change: 0 additions & 1 deletion external/crlfchecker/normtext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint node:true */

'use strict';

Expand Down
1 change: 0 additions & 1 deletion external/importL10n/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint node:true */

'use strict';

Expand Down
Loading

0 comments on commit 6af6f21

Please sign in to comment.