From 2f3805efbc0822fc326afeca2ca2b0d4936a097d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 15 Dec 2016 15:52:29 +0100 Subject: [PATCH] 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/ --- .jshintignore => .eslintignore | 0 .eslintrc | 108 ++++++++++++++++++ .jshintrc | 33 ------ extensions/chromium/options/migration.js | 1 + extensions/chromium/pdfHandler-vcros.js | 1 + extensions/chromium/telemetry.js | 1 + extensions/firefox/.eslintrc | 9 ++ extensions/firefox/bootstrap.js | 1 - extensions/firefox/chrome/content.js | 1 - extensions/firefox/content/PdfJs-stub.jsm | 2 +- extensions/firefox/content/PdfJs.jsm | 1 - .../firefox/content/PdfJsTelemetry-addon.jsm | 2 +- extensions/firefox/content/PdfJsTelemetry.jsm | 2 +- .../firefox/content/PdfStreamConverter.jsm | 1 - .../firefox/content/PdfjsChromeUtils.jsm | 1 - .../firefox/content/PdfjsContentUtils.jsm | 1 - .../firefox/content/pdfjschildbootstrap.js | 1 - extensions/firefox/tools/l10n.js | 1 - external/.eslintrc | 10 ++ external/builder/builder.js | 5 +- external/builder/fixtures/.eslintrc | 11 ++ external/builder/preprocessor2.js | 14 ++- external/builder/test.js | 1 - external/builder/test2.js | 1 - external/crlfchecker/crlfchecker.js | 1 - external/crlfchecker/normtext.js | 1 - external/importL10n/locales.js | 1 - gulpfile.js | 12 +- make.js | 2 +- package.json | 2 +- src/core/fonts.js | 2 +- src/core/function.js | 2 +- src/core/jpg.js | 1 + src/core/murmurhash3.js | 2 +- src/core/parser.js | 14 +-- src/core/pattern.js | 1 + src/core/worker.js | 9 +- src/display/api.js | 2 +- src/display/font_loader.js | 2 +- src/display/svg.js | 2 +- src/display/webgl.js | 2 +- src/doc_helper.js | 1 + src/pdf.js | 2 +- src/pdf.worker.entry.js | 2 +- src/shared/fonts_utils.js | 2 +- src/shared/util.js | 7 +- test/.eslintrc | 11 ++ test/downloadutils.js | 1 - test/font/ttxdriver.js | 1 - test/stats/statcmp.js | 2 - test/test.js | 1 - test/testutils.js | 1 - test/unit/crypto_spec.js | 2 + test/unit/function_spec.js | 2 +- test/unit/murmurhash3_spec.js | 2 +- test/unit/testreporter.js | 1 - test/webbrowser.js | 1 - test/webserver.js | 1 - web/chromecom.js | 4 +- web/compatibility.js | 2 + web/download_manager.js | 4 +- web/grab_to_pan.js | 2 +- web/pdf_viewer.component.js | 2 +- 63 files changed, 214 insertions(+), 107 deletions(-) rename .jshintignore => .eslintignore (100%) create mode 100644 .eslintrc delete mode 100644 .jshintrc create mode 100644 extensions/firefox/.eslintrc create mode 100644 external/.eslintrc create mode 100644 external/builder/fixtures/.eslintrc create mode 100644 test/.eslintrc diff --git a/.jshintignore b/.eslintignore similarity index 100% rename from .jshintignore rename to .eslintignore diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..c89b03de --- /dev/null +++ b/.eslintrc @@ -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, }, }], + }, +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 34b5e699..00000000 --- a/.jshintrc +++ /dev/null @@ -1,33 +0,0 @@ -{ - // Environments - "browser": true, - "devel": true, - "worker": true, - "predef": [ - "Promise", - "PDFJSDev", - "require", - "define", - "exports" - ], - - // Enforcing - "maxlen": 80, - "quotmark": "single", - "trailing": true, - "curly": true, - "undef": true, - "noarg": true, - "nonbsp": true, - "eqeqeq": true, - - // Relaxing - "boss": true, - "funcscope": true, - "globalstrict": true, - "loopfunc": true, - "maxerr": 1000, - "nonstandard": true, - "sub": true, - "validthis": true -} diff --git a/extensions/chromium/options/migration.js b/extensions/chromium/options/migration.js index 6d9f4c51..32577fbd 100644 --- a/extensions/chromium/options/migration.js +++ b/extensions/chromium/options/migration.js @@ -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() { diff --git a/extensions/chromium/pdfHandler-vcros.js b/extensions/chromium/pdfHandler-vcros.js index ca4855bd..4ed54630 100644 --- a/extensions/chromium/pdfHandler-vcros.js +++ b/extensions/chromium/pdfHandler-vcros.js @@ -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() { diff --git a/extensions/chromium/telemetry.js b/extensions/chromium/telemetry.js index b23cac53..fa03b912 100644 --- a/extensions/chromium/telemetry.js +++ b/extensions/chromium/telemetry.js @@ -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() { diff --git a/extensions/firefox/.eslintrc b/extensions/firefox/.eslintrc new file mode 100644 index 00000000..71258ac5 --- /dev/null +++ b/extensions/firefox/.eslintrc @@ -0,0 +1,9 @@ +{ + "extends": [ + ../../.eslintrc + ], + + "parserOptions": { + "ecmaVersion": 6 + }, +} diff --git a/extensions/firefox/bootstrap.js b/extensions/firefox/bootstrap.js index 0ff82985..fcb1d0ce 100644 --- a/extensions/firefox/bootstrap.js +++ b/extensions/firefox/bootstrap.js @@ -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 */ diff --git a/extensions/firefox/chrome/content.js b/extensions/firefox/chrome/content.js index 143ed30d..b9afd982 100644 --- a/extensions/firefox/chrome/content.js +++ b/extensions/firefox/chrome/content.js @@ -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 */ diff --git a/extensions/firefox/content/PdfJs-stub.jsm b/extensions/firefox/content/PdfJs-stub.jsm index e89ad975..84d13258 100644 --- a/extensions/firefox/content/PdfJs-stub.jsm +++ b/extensions/firefox/content/PdfJs-stub.jsm @@ -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'; diff --git a/extensions/firefox/content/PdfJs.jsm b/extensions/firefox/content/PdfJs.jsm index 454b1f8b..b86cbbcd 100644 --- a/extensions/firefox/content/PdfJs.jsm +++ b/extensions/firefox/content/PdfJs.jsm @@ -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 */ diff --git a/extensions/firefox/content/PdfJsTelemetry-addon.jsm b/extensions/firefox/content/PdfJsTelemetry-addon.jsm index a31687dd..06097eb1 100644 --- a/extensions/firefox/content/PdfJsTelemetry-addon.jsm +++ b/extensions/firefox/content/PdfJsTelemetry-addon.jsm @@ -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'; diff --git a/extensions/firefox/content/PdfJsTelemetry.jsm b/extensions/firefox/content/PdfJsTelemetry.jsm index 275da9d8..0d34cd50 100644 --- a/extensions/firefox/content/PdfJsTelemetry.jsm +++ b/extensions/firefox/content/PdfJsTelemetry.jsm @@ -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'; diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm index a89cc5e7..29838719 100644 --- a/extensions/firefox/content/PdfStreamConverter.jsm +++ b/extensions/firefox/content/PdfStreamConverter.jsm @@ -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 */ diff --git a/extensions/firefox/content/PdfjsChromeUtils.jsm b/extensions/firefox/content/PdfjsChromeUtils.jsm index 2ce62461..16bb0d9c 100644 --- a/extensions/firefox/content/PdfjsChromeUtils.jsm +++ b/extensions/firefox/content/PdfjsChromeUtils.jsm @@ -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'; diff --git a/extensions/firefox/content/PdfjsContentUtils.jsm b/extensions/firefox/content/PdfjsContentUtils.jsm index 92e7ade2..aec9f8c7 100644 --- a/extensions/firefox/content/PdfjsContentUtils.jsm +++ b/extensions/firefox/content/PdfjsContentUtils.jsm @@ -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'; diff --git a/extensions/firefox/content/pdfjschildbootstrap.js b/extensions/firefox/content/pdfjschildbootstrap.js index 2cab05f4..c44cd3bd 100644 --- a/extensions/firefox/content/pdfjschildbootstrap.js +++ b/extensions/firefox/content/pdfjschildbootstrap.js @@ -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'; diff --git a/extensions/firefox/tools/l10n.js b/extensions/firefox/tools/l10n.js index 04346ee1..e45cf200 100644 --- a/extensions/firefox/tools/l10n.js +++ b/extensions/firefox/tools/l10n.js @@ -1,4 +1,3 @@ - 'use strict'; // Small subset of the webL10n API by Fabien Cazenave for pdf.js extension. diff --git a/external/.eslintrc b/external/.eslintrc new file mode 100644 index 00000000..3692bbae --- /dev/null +++ b/external/.eslintrc @@ -0,0 +1,10 @@ +{ + "extends": [ + ../.eslintrc + ], + + "env": { + "node": true, + "shelljs": true, + }, +} diff --git a/external/builder/builder.js b/external/builder/builder.js index 31f07fa9..a80a7a5a 100644 --- a/external/builder/builder.js +++ b/external/builder/builder.js @@ -1,4 +1,3 @@ -/* jshint node:true */ /* globals cp, ls, test */ 'use strict'; @@ -107,10 +106,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 /^(?:\/\/|)?$)?/; - /* jshint +W101 */ var lineNumber = 0; var loc = function() { return fs.realpathSync(inFilename) + ':' + lineNumber; diff --git a/external/builder/fixtures/.eslintrc b/external/builder/fixtures/.eslintrc new file mode 100644 index 00000000..94eb4f06 --- /dev/null +++ b/external/builder/fixtures/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": [ + ../../.eslintrc + ], + + "rules": { + "no-empty": "off", + "keyword-spacing": "off", + "space-infix-ops": "off", + }, +} diff --git a/external/builder/preprocessor2.js b/external/builder/preprocessor2.js index 9967e1a5..ed05d2f5 100644 --- a/external/builder/preprocessor2.js +++ b/external/builder/preprocessor2.js @@ -1,5 +1,3 @@ -/* jshint node:true */ - 'use strict'; var esprima = require('esprima'); @@ -197,8 +195,12 @@ 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; @@ -206,12 +208,12 @@ function fixComments(ctx, node) { 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; } diff --git a/external/builder/test.js b/external/builder/test.js index 8d4007fb..e3e4d276 100644 --- a/external/builder/test.js +++ b/external/builder/test.js @@ -1,4 +1,3 @@ -/* jshint node:true */ /* globals cat, cd, echo, ls */ 'use strict'; diff --git a/external/builder/test2.js b/external/builder/test2.js index f29b434e..ce525fba 100644 --- a/external/builder/test2.js +++ b/external/builder/test2.js @@ -1,4 +1,3 @@ -/* jshint node:true */ /* globals cat, cd, echo, ls */ 'use strict'; diff --git a/external/crlfchecker/crlfchecker.js b/external/crlfchecker/crlfchecker.js index f331daeb..3358aaa8 100644 --- a/external/crlfchecker/crlfchecker.js +++ b/external/crlfchecker/crlfchecker.js @@ -1,4 +1,3 @@ -/* jshint node:true */ /* globals cat, echo, exit, ls */ 'use strict'; diff --git a/external/crlfchecker/normtext.js b/external/crlfchecker/normtext.js index ef8a919c..bbcd6e89 100644 --- a/external/crlfchecker/normtext.js +++ b/external/crlfchecker/normtext.js @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint node:true */ 'use strict'; diff --git a/external/importL10n/locales.js b/external/importL10n/locales.js index 1336545b..1290101c 100644 --- a/external/importL10n/locales.js +++ b/external/importL10n/locales.js @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint node:true */ 'use strict'; diff --git a/gulpfile.js b/gulpfile.js index 430ba60d..1cdc1c12 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint node:true */ +/* eslint-env node */ /* globals target */ 'use strict'; @@ -529,12 +529,12 @@ gulp.task('lint', function (done) { console.log(); console.log('### Linting JS files'); - // Lint the Firefox specific *.jsm files. - var options = ['node_modules/jshint/bin/jshint', '--extra-ext', '.jsm', '.']; - var jshintProcess = spawn('node', options, {stdio: 'inherit'}); - jshintProcess.on('close', function (code) { + // Ensure that we lint the Firefox specific *.jsm files too. + var options = ['node_modules/eslint/bin/eslint', '--ext', '.js,.jsm', '.']; + var esLintProcess = spawn('node', options, {stdio: 'inherit'}); + esLintProcess.on('close', function (code) { if (code !== 0) { - done(new Error('jshint failed.')); + done(new Error('ESLint failed.')); return; } diff --git a/make.js b/make.js index 80cf970d..906c83f9 100644 --- a/make.js +++ b/make.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint node:true */ +/* eslint-env node, shelljs */ /* globals cat, cd, cp, echo, env, exec, exit, find, ls, mkdir, mv, process, rm, sed, target, test */ diff --git a/package.json b/package.json index 2bf86aaf..35042a05 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,13 @@ "version": "0.8.0", "devDependencies": { "escodegen": "^1.8.0", + "eslint": "^3.11.1", "esprima": "^2.7.2", "gulp": "^3.9.1", "gulp-util": "^3.0.7", "gulp-zip": "^3.2.0", "jasmine-core": "^2.4.1", "jsdoc": "^3.3.0-alpha9", - "jshint": "~2.8.0", "mkdirp": "^0.5.1", "node-ensure": "^0.0.0", "requirejs": "^2.1.22", diff --git a/src/core/fonts.js b/src/core/fonts.js index 6364ba85..cbd9c1f3 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -983,7 +983,7 @@ var Font = (function FontClosure() { // Split the sorted codes into ranges. var ranges = []; var length = codes.length; - for (var n = 0; n < length; ) { + for (var n = 0; n < length; ) { // eslint-disable-line space-in-parens var start = codes[n].fontCharCode; var codeIndices = [codes[n].glyphId]; ++n; diff --git a/src/core/function.js b/src/core/function.js index 6d05d443..24d28198 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -423,7 +423,7 @@ var PDFFunction = (function PDFFunctionClosure() { // Compiled function consists of simple expressions such as addition, // subtraction, Math.max, and also contains 'var' and 'return' // statements. See the generation in the PostScriptCompiler below. - /*jshint -W054 */ + // eslint-disable-next-line no-new-func return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled); } diff --git a/src/core/jpg.js b/src/core/jpg.js index d5a9bf83..cae72d49 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable no-multi-spaces */ 'use strict'; diff --git a/src/core/murmurhash3.js b/src/core/murmurhash3.js index c45bcc03..ccb4c9c1 100644 --- a/src/core/murmurhash3.js +++ b/src/core/murmurhash3.js @@ -1,4 +1,3 @@ - /* Copyright 2014 Opera Software ASA * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -48,6 +47,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure(seed) { !PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) { // old webkits have issues with non-aligned arrays try { + // eslint-disable-next-line no-new new Uint32Array(new Uint8Array(5).buffer, 0, 1); } catch (e) { alwaysUseUint32ArrayView = true; diff --git a/src/core/parser.js b/src/core/parser.js index 378d3085..88ad7038 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -248,29 +248,29 @@ var Parser = (function ParserClosure() { case 0xC1: // SOF1 case 0xC2: // SOF2 case 0xC3: // SOF3 - + /* falls through */ case 0xC5: // SOF5 case 0xC6: // SOF6 case 0xC7: // SOF7 - + /* falls through */ case 0xC9: // SOF9 case 0xCA: // SOF10 case 0xCB: // SOF11 - + /* falls through */ case 0xCD: // SOF13 case 0xCE: // SOF14 case 0xCF: // SOF15 - + /* falls through */ case 0xC4: // DHT case 0xCC: // DAC - + /* falls through */ case 0xDA: // SOS case 0xDB: // DQT case 0xDC: // DNL case 0xDD: // DRI case 0xDE: // DHP case 0xDF: // EXP - + /* falls through */ case 0xE0: // APP0 case 0xE1: // APP1 case 0xE2: // APP2 @@ -287,7 +287,7 @@ var Parser = (function ParserClosure() { case 0xED: // APP13 case 0xEE: // APP14 case 0xEF: // APP15 - + /* falls through */ case 0xFE: // COM // The marker should be followed by the length of the segment. markerLength = stream.getUint16(); diff --git a/src/core/pattern.js b/src/core/pattern.js index b69d9dd4..eaef6844 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable no-multi-spaces */ 'use strict'; diff --git a/src/core/worker.js b/src/core/worker.js index 5b9722ca..be23c732 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -83,14 +83,13 @@ var WorkerTask = (function WorkerTaskClosure() { })(); if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { -/*jshint -W082 */ /** * Interface that represents PDF data transport. If possible, it allows * progressively load entire or fragment of the PDF binary data. * * @interface - * */ -function IPDFStream() {} + */ +function IPDFStream() {} // eslint-disable-line no-inner-declarations IPDFStream.prototype = { /** * Gets a reader for the entire PDF data. @@ -118,7 +117,7 @@ IPDFStream.prototype = { * * @interface */ -function IPDFStreamReader() {} +function IPDFStreamReader() {} // eslint-disable-line no-inner-declarations IPDFStreamReader.prototype = { /** * Gets a promise that is resolved when the headers and other metadata of @@ -179,7 +178,7 @@ IPDFStreamReader.prototype = { * * @interface */ -function IPDFStreamRangeReader() {} +function IPDFStreamRangeReader() {} // eslint-disable-line no-inner-declarations IPDFStreamRangeReader.prototype = { /** * Gets ability of the stream to progressively load binary data. diff --git a/src/display/api.js b/src/display/api.js index cb4ad038..c60eae17 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -13,7 +13,7 @@ * limitations under the License. */ /* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild, requirejs, pdfjsLibs, - WeakMap */ + __webpack_require__ */ 'use strict'; diff --git a/src/display/font_loader.js b/src/display/font_loader.js index f15d1373..fa47a99b 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -426,7 +426,7 @@ var FontFaceObject = (function FontFaceObjectClosure() { js += 'c.' + current.cmd + '(' + args + ');\n'; } - /* jshint -W054 */ + // eslint-disable-next-line no-new-func this.compiledGlyphs[character] = new Function('c', 'size', js); } else { // But fall back on using Function.prototype.apply() if we're diff --git a/src/display/svg.js b/src/display/svg.js index 9530095c..ece7d907 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -460,7 +460,7 @@ var SVGGraphics = (function SVGGraphicsClosure() { convertOpList: function SVGGraphics_convertOpList(operatorList) { var argsArray = operatorList.argsArray; var fnArray = operatorList.fnArray; - var fnArrayLen = fnArray.length; + var fnArrayLen = fnArray.length; var REVOPS = []; var opList = []; diff --git a/src/display/webgl.js b/src/display/webgl.js index 4c02fd7c..dc2b9576 100644 --- a/src/display/webgl.js +++ b/src/display/webgl.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint -W043 */ +/* eslint-disable no-multi-str */ 'use strict'; diff --git a/src/doc_helper.js b/src/doc_helper.js index 86632b45..d6707e3a 100644 --- a/src/doc_helper.js +++ b/src/doc_helper.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable strict */ /* NOTE: This file is created as a helper to assist with JSDoc html files. diff --git a/src/pdf.js b/src/pdf.js index 0322f8b2..e70d6f0d 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint globalstrict: false */ +/* eslint strict: ["error", "function"] */ /* umdutils ignore */ (function (root, factory) { diff --git a/src/pdf.worker.entry.js b/src/pdf.worker.entry.js index 8ad5d5df..1950ad7d 100644 --- a/src/pdf.worker.entry.js +++ b/src/pdf.worker.entry.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable strict */ (typeof window !== 'undefined' ? window : {}).pdfjsDistBuildPdfWorker = require('./pdf.worker.js'); - diff --git a/src/shared/fonts_utils.js b/src/shared/fonts_utils.js index d282983d..555b18e1 100644 --- a/src/shared/fonts_utils.js +++ b/src/shared/fonts_utils.js @@ -73,7 +73,7 @@ function readCharstringEncoding(aString) { var charstringTokens = []; var count = aString.length; - for (var i = 0; i < count; ) { + for (var i = 0; i < count; ) { // eslint-disable-line space-in-parens var value = aString[i++] | 0; var token = null; diff --git a/src/shared/util.js b/src/shared/util.js index 4e3e5019..915c5266 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -620,8 +620,7 @@ function isLittleEndian() { // Checks if it's possible to eval JS expressions. function isEvalSupported() { try { - /* jshint evil: true */ - new Function(''); + new Function(''); // eslint-disable-line no-new, no-new-func return true; } catch (e) { return false; @@ -1756,6 +1755,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) { /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ (function checkURLConstructor(scope) { + /* eslint-disable yoda */ + // feature detect for URL constructor var hasWorkingUrl = false; try { @@ -2392,6 +2393,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) { } scope.URL = JURL; + + /* eslint-enable yoda */ })(globalScope); } diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 00000000..692abd31 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": [ + ../.eslintrc + ], + + "env": { + "node": true, + "shelljs": true, + "jasmine": true, + }, +} diff --git a/test/downloadutils.js b/test/downloadutils.js index d2f4333b..10e8f4e7 100644 --- a/test/downloadutils.js +++ b/test/downloadutils.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/test/font/ttxdriver.js b/test/font/ttxdriver.js index 9380666e..7284436c 100644 --- a/test/font/ttxdriver.js +++ b/test/font/ttxdriver.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/test/stats/statcmp.js b/test/stats/statcmp.js index 0b15dc5a..73ed7724 100644 --- a/test/stats/statcmp.js +++ b/test/stats/statcmp.js @@ -1,5 +1,3 @@ -/*jslint node: true */ - 'use strict'; var fs = require('fs'); diff --git a/test/test.js b/test/test.js index fa588fd2..2dcdeeec 100644 --- a/test/test.js +++ b/test/test.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/test/testutils.js b/test/testutils.js index 36409909..ca000f05 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/test/unit/crypto_spec.js b/test/unit/crypto_spec.js index f4b7aa2b..336317d8 100644 --- a/test/unit/crypto_spec.js +++ b/test/unit/crypto_spec.js @@ -482,6 +482,7 @@ describe('CipherTransformFactory', function() { function ensurePasswordNeeded(done, dict, fileId, password) { try { + // eslint-disable-next-line no-new new CipherTransformFactory(dict, fileId, password); } catch (ex) { expect(ex instanceof PasswordException).toEqual(true); @@ -495,6 +496,7 @@ describe('CipherTransformFactory', function() { function ensurePasswordIncorrect(done, dict, fileId, password) { try { + // eslint-disable-next-line no-new new CipherTransformFactory(dict, fileId, password); } catch (ex) { expect(ex instanceof PasswordException).toEqual(true); diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js index e699a551..691f779d 100644 --- a/test/unit/function_spec.js +++ b/test/unit/function_spec.js @@ -433,7 +433,7 @@ describe('function', function() { expect(compiledCode).toBeNull(); } else { expect(compiledCode).not.toBeNull(); - /*jshint -W054 */ + // eslint-disable-next-line no-new-func var fn = new Function('src', 'srcOffset', 'dest', 'destOffset', compiledCode); for (var i = 0; i < samples.length; i++) { diff --git a/test/unit/murmurhash3_spec.js b/test/unit/murmurhash3_spec.js index 69865da4..7523ff4e 100644 --- a/test/unit/murmurhash3_spec.js +++ b/test/unit/murmurhash3_spec.js @@ -49,4 +49,4 @@ describe('MurmurHash3_64', function() { hexdigest2 = hash.hexdigest(); expect(hexdigest1).not.toEqual(hexdigest2); }); -}); \ No newline at end of file +}); diff --git a/test/unit/testreporter.js b/test/unit/testreporter.js index 594ad939..c22a9edf 100644 --- a/test/unit/testreporter.js +++ b/test/unit/testreporter.js @@ -1,4 +1,3 @@ - 'use strict'; var TestReporter = function(browser, appPath) { diff --git a/test/webbrowser.js b/test/webbrowser.js index 0e693402..4cb1b4d1 100644 --- a/test/webbrowser.js +++ b/test/webbrowser.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/test/webserver.js b/test/webserver.js index 8149fd19..8f72760f 100644 --- a/test/webserver.js +++ b/test/webserver.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/*jslint node: true */ 'use strict'; diff --git a/web/chromecom.js b/web/chromecom.js index 89994803..31d567d5 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /* globals chrome, DEFAULT_URL */ + 'use strict'; (function (root, factory) { @@ -201,9 +201,11 @@ // Use Chrome's definition of UI language instead of PDF.js's #lang=..., // because the shown string should match the UI at chrome://extensions. // These strings are from chrome/app/resources/generated_resources_*.xtb. + /* eslint-disable no-unexpected-multiline */ var i18nFileAccessLabel = PDFJSDev.json('$ROOT/web/chrome-i18n-allow-access-to-file-urls.json') [chrome.i18n.getUILanguage && chrome.i18n.getUILanguage()]; + /* eslint-enable no-unexpected-multiline */ if (i18nFileAccessLabel) { document.getElementById('chrome-file-access-label').textContent = diff --git a/web/compatibility.js b/web/compatibility.js index 4300686e..9946c4b1 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint strict: ["error", "function"] */ +/* eslint-disable no-extend-native */ /* globals VBArray, PDFJS */ (function compatibilityWrapper() { diff --git a/web/download_manager.js b/web/download_manager.js index 75c15103..674dfb62 100644 --- a/web/download_manager.js +++ b/web/download_manager.js @@ -26,7 +26,7 @@ } }(this, function (exports, pdfjsLib) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) { - /* jshint -W082 */ + // eslint-disable-next-line no-inner-declarations function download(blobUrl, filename) { var a = document.createElement('a'); if (a.click) { @@ -63,7 +63,7 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) { } } - function DownloadManager() {} + function DownloadManager() {} // eslint-disable-line no-inner-declarations DownloadManager.prototype = { downloadUrl: function DownloadManager_downloadUrl(url, filename) { diff --git a/web/grab_to_pan.js b/web/grab_to_pan.js index 8eaae776..803bdaa6 100644 --- a/web/grab_to_pan.js +++ b/web/grab_to_pan.js @@ -122,7 +122,7 @@ } if (event.originalTarget) { try { - /* jshint expr:true */ + // eslint-disable-next-line no-unused-expressions event.originalTarget.tagName; } catch (e) { // Mozilla-specific: element is a scrollbar (XUL element) diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index 05f3fdea..14c22d1c 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* jshint globalstrict: false */ +/* eslint strict: ["error", "function"] */ /* umdutils ignore */ (function (root, factory) {