Skip to content

Commit 2f3805e

Browse files
committed
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.* ESLint has a number of advantageous properties, compared to JSHint. Among those are: - The ability to find subtle bugs, thanks to more rules (e.g. PR 7881). - Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint. - Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary). - The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage. - More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead. By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want. Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much. I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations. Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%). A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible: - `comma-dangle`, controls trailing commas in Objects and Arrays (among others). - `object-curly-spacing`, controls spacing inside of Objects. - `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.) Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed. Useful links: - http://eslint.org/docs/user-guide/configuring - http://eslint.org/docs/rules/
1 parent b629be0 commit 2f3805e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+214
-107
lines changed
File renamed without changes.

.eslintrc

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5,
4+
},
5+
6+
"env": {
7+
"browser": true,
8+
"es6": true,
9+
"worker": true,
10+
"amd": true,
11+
},
12+
13+
globals: {
14+
"PDFJSDev": false,
15+
"require": false,
16+
"exports": false,
17+
},
18+
19+
"rules": {
20+
// Possible errors
21+
"no-cond-assign": ["error", "except-parens"],
22+
"no-constant-condition": ["error", { "checkLoops": false, }],
23+
"no-dupe-args": "error",
24+
"no-dupe-keys": "error",
25+
"no-duplicate-case": "error",
26+
"no-empty": ["error", { "allowEmptyCatch": true, }],
27+
"no-ex-assign": "error",
28+
"no-extra-boolean-cast": "error",
29+
"no-extra-semi": "error",
30+
"no-func-assign": "error",
31+
"no-inner-declarations": ["error", "functions"],
32+
"no-invalid-regexp": "error",
33+
"no-irregular-whitespace": "error",
34+
"no-obj-calls": "error",
35+
"no-regex-spaces": "error",
36+
"no-sparse-arrays": "error",
37+
"no-unexpected-multiline": "error",
38+
"no-unreachable": "error",
39+
"no-unsafe-negation": "error",
40+
"use-isnan": "error",
41+
"valid-typeof": ["error", { "requireStringLiterals": true, }],
42+
43+
// Best Practices
44+
"accessor-pairs": ["error", { "setWithoutGet": true, }],
45+
"curly": ["error", "all"],
46+
"eqeqeq": ["error", "always"],
47+
"no-caller": "error",
48+
"no-eval": "error",
49+
"no-extend-native": "error",
50+
"no-extra-bind": "error",
51+
"no-extra-label": "error",
52+
"no-fallthrough": "error",
53+
"no-global-assign": "error",
54+
"no-implied-eval": "error",
55+
"no-multi-spaces": "error",
56+
"no-multi-str": "error",
57+
"no-new-func": "error",
58+
"no-new-wrappers": "error",
59+
"no-new": "error",
60+
"no-octal-escape": "error",
61+
"no-redeclare": "error",
62+
"no-self-assign": "error",
63+
"no-unused-expressions": "error",
64+
"no-unused-labels": "error",
65+
"no-useless-concat": "error",
66+
"wrap-iife": ["error", "any"],
67+
"yoda": ["error", "never", { "onlyEquality": true, }],
68+
69+
// Strict Mode
70+
"strict": ["error", "global"],
71+
72+
// Variables
73+
"no-catch-shadow": "error",
74+
"no-label-var": "error",
75+
"no-shadow-restricted-names": "error",
76+
"no-undef-init": "error",
77+
"no-undef": ["error", { "typeof": true, }],
78+
79+
// Stylistic Issues
80+
"array-bracket-spacing": ["error", "never"],
81+
"block-spacing": ["error", "always"],
82+
"brace-style": ["error", "1tbs", { "allowSingleLine": true, }],
83+
"comma-spacing": ["error", { "before": false, "after": true, }],
84+
"comma-style": ["error", "last"],
85+
"eol-last": "error",
86+
"func-call-spacing": ["error", "never"],
87+
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict", }],
88+
"keyword-spacing": ["error", { "before": true, "after": true, }],
89+
"linebreak-style": ["error", "unix"],
90+
"max-len": ["error", 80],
91+
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, }],
92+
"new-parens": "error",
93+
"no-array-constructor": "error",
94+
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 0, "maxBOF": 1, }],
95+
"no-tabs": "error",
96+
"no-trailing-spaces": ["error", { "skipBlankLines": false, }],
97+
"no-whitespace-before-property": "error",
98+
"operator-linebreak": ["error", "after", { "overrides": { ":": "ignore", } }],
99+
"quotes": ["error", "single"],
100+
"semi-spacing": ["error", { "before": false, "after": true, }],
101+
"semi": ["error", "always"],
102+
"space-before-blocks": ["error", "always"],
103+
"space-before-function-paren": ["error", { "anonymous": "ignore", "named": "never", }],
104+
"space-in-parens": ["error", "never"],
105+
"space-infix-ops": ["error", { "int32Hint": false }],
106+
"space-unary-ops": ["error", { "words": true, "nonwords": false, "overrides": { "void": false, }, }],
107+
},
108+
}

.jshintrc

Lines changed: 0 additions & 33 deletions
This file was deleted.

extensions/chromium/options/migration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
/* eslint strict: ["error", "function"] */
1617
/* globals chrome */
1718

1819
(function() {

extensions/chromium/pdfHandler-vcros.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
/* eslint strict: ["error", "function"] */
1617
/* globals chrome, getViewerURL */
1718

1819
(function() {

extensions/chromium/telemetry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
/* eslint strict: ["error", "function"] */
1617
/* globals chrome, crypto, Headers, Request */
1718

1819
(function() {

extensions/firefox/.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": [
3+
../../.eslintrc
4+
],
5+
6+
"parserOptions": {
7+
"ecmaVersion": 6
8+
},
9+
}

extensions/firefox/bootstrap.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/* jshint esnext:true */
1615
/* globals Components, Services, dump, XPCOMUtils, PdfStreamConverter,
1716
APP_SHUTDOWN, PdfjsChromeUtils, PdfjsContentUtils */
1817

extensions/firefox/chrome/content.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/* jshint esnext:true */
1615
/* globals Components, Services, XPCOMUtils, PdfjsContentUtils,
1716
PdfjsContentUtils, PdfStreamConverter, addMessageListener */
1817

extensions/firefox/content/PdfJs-stub.jsm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
/* jshint esnext:true, maxlen:100 */
15+
/* eslint max-len: ["error", 100] */
1616

1717
'use strict';
1818

0 commit comments

Comments
 (0)