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/
This commit is contained in:
Jonas Jenwald 2016-12-15 15:52:29 +01:00
parent b629be05bd
commit 2f3805efbc
63 changed files with 214 additions and 107 deletions

108
.eslintrc Normal file
View File

@ -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, }, }],
},
}

View File

@ -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
}

View File

@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* globals chrome */ /* globals chrome */
(function() { (function() {

View File

@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* globals chrome, getViewerURL */ /* globals chrome, getViewerURL */
(function() { (function() {

View File

@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* globals chrome, crypto, Headers, Request */ /* globals chrome, crypto, Headers, Request */
(function() { (function() {

View File

@ -0,0 +1,9 @@
{
"extends": [
../../.eslintrc
],
"parserOptions": {
"ecmaVersion": 6
},
}

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, dump, XPCOMUtils, PdfStreamConverter, /* globals Components, Services, dump, XPCOMUtils, PdfStreamConverter,
APP_SHUTDOWN, PdfjsChromeUtils, PdfjsContentUtils */ APP_SHUTDOWN, PdfjsChromeUtils, PdfjsContentUtils */

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsContentUtils, /* globals Components, Services, XPCOMUtils, PdfjsContentUtils,
PdfjsContentUtils, PdfStreamConverter, addMessageListener */ PdfjsContentUtils, PdfStreamConverter, addMessageListener */

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true, maxlen:100 */ /* eslint max-len: ["error", 100] */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, PdfjsChromeUtils, /* globals Components, Services, XPCOMUtils, PdfjsChromeUtils,
PdfjsContentUtils, PdfStreamConverter */ PdfjsContentUtils, PdfStreamConverter */

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true, maxlen:120 */ /* eslint max-len: ["error", 120] */
/* globals Components, Services */ /* globals Components, Services */
'use strict'; 'use strict';

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true, maxlen: 100 */ /* eslint max-len: ["error", 100] */
/* globals Components, Services */ /* globals Components, Services */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils, /* globals Components, Services, XPCOMUtils, NetUtil, PrivateBrowsingUtils,
dump, NetworkManager, PdfJsTelemetry, PdfjsContentUtils */ dump, NetworkManager, PdfJsTelemetry, PdfjsContentUtils */

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils */ /* globals Components, Services, XPCOMUtils */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, Services, XPCOMUtils */ /* globals Components, Services, XPCOMUtils */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint esnext:true */
/* globals Components, PdfjsContentUtils, PdfJs, Services */ /* globals Components, PdfjsContentUtils, PdfJs, Services */
'use strict'; 'use strict';

View File

@ -1,4 +1,3 @@
'use strict'; 'use strict';
// Small subset of the webL10n API by Fabien Cazenave for pdf.js extension. // Small subset of the webL10n API by Fabien Cazenave for pdf.js extension.

10
external/.eslintrc vendored Normal file
View File

@ -0,0 +1,10 @@
{
"extends": [
../.eslintrc
],
"env": {
"node": true,
"shelljs": true,
},
}

View File

@ -1,4 +1,3 @@
/* jshint node:true */
/* globals cp, ls, test */ /* globals cp, ls, test */
'use strict'; 'use strict';
@ -107,10 +106,8 @@ function preprocess(inFilename, outFilename, defines) {
var line; var line;
var state = STATE_NONE; var state = STATE_NONE;
var stack = []; var stack = [];
var control = var control = // eslint-disable-next-line max-len
/* jshint -W101 */
/^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/; /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
/* jshint +W101 */
var lineNumber = 0; var lineNumber = 0;
var loc = function() { var loc = function() {
return fs.realpathSync(inFilename) + ':' + lineNumber; return fs.realpathSync(inFilename) + ':' + lineNumber;

11
external/builder/fixtures/.eslintrc vendored Normal file
View File

@ -0,0 +1,11 @@
{
"extends": [
../../.eslintrc
],
"rules": {
"no-empty": "off",
"keyword-spacing": "off",
"space-infix-ops": "off",
},
}

View File

@ -1,5 +1,3 @@
/* jshint node:true */
'use strict'; 'use strict';
var esprima = require('esprima'); var esprima = require('esprima');
@ -197,8 +195,12 @@ function fixComments(ctx, node) {
} }
// Fixes double comments in the escodegen output. // Fixes double comments in the escodegen output.
delete node.trailingComments; delete node.trailingComments;
// Removes jshint and other service comments. // Removes ESLint and other service comments.
if (node.leadingComments) { 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; var i = 0;
while (i < node.leadingComments.length) { while (i < node.leadingComments.length) {
var type = node.leadingComments[i].type; var type = node.leadingComments[i].type;
@ -206,12 +208,12 @@ function fixComments(ctx, node) {
if (ctx.saveComments === 'copyright') { if (ctx.saveComments === 'copyright') {
// Remove all comments, except Copyright notices and License headers. // 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); node.leadingComments.splice(i, 1);
continue; continue;
} }
} else if (type === 'Block' && } else if ((type === 'Block' && BlockCommentRegExp.test(value)) ||
/^\s*(globals|jshint|falls through|umdutils)\b/.test(value)) { (type === 'Line' && LineCommentRegExp.test(value))) {
node.leadingComments.splice(i, 1); node.leadingComments.splice(i, 1);
continue; continue;
} }

View File

@ -1,4 +1,3 @@
/* jshint node:true */
/* globals cat, cd, echo, ls */ /* globals cat, cd, echo, ls */
'use strict'; 'use strict';

View File

@ -1,4 +1,3 @@
/* jshint node:true */
/* globals cat, cd, echo, ls */ /* globals cat, cd, echo, ls */
'use strict'; 'use strict';

View File

@ -1,4 +1,3 @@
/* jshint node:true */
/* globals cat, echo, exit, ls */ /* globals cat, echo, exit, ls */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint node:true */
'use strict'; 'use strict';

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint node:true */
'use strict'; 'use strict';

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint node:true */ /* eslint-env node */
/* globals target */ /* globals target */
'use strict'; 'use strict';
@ -529,12 +529,12 @@ gulp.task('lint', function (done) {
console.log(); console.log();
console.log('### Linting JS files'); console.log('### Linting JS files');
// Lint the Firefox specific *.jsm files. // Ensure that we lint the Firefox specific *.jsm files too.
var options = ['node_modules/jshint/bin/jshint', '--extra-ext', '.jsm', '.']; var options = ['node_modules/eslint/bin/eslint', '--ext', '.js,.jsm', '.'];
var jshintProcess = spawn('node', options, {stdio: 'inherit'}); var esLintProcess = spawn('node', options, {stdio: 'inherit'});
jshintProcess.on('close', function (code) { esLintProcess.on('close', function (code) {
if (code !== 0) { if (code !== 0) {
done(new Error('jshint failed.')); done(new Error('ESLint failed.'));
return; return;
} }

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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, /* globals cat, cd, cp, echo, env, exec, exit, find, ls, mkdir, mv, process, rm,
sed, target, test */ sed, target, test */

View File

@ -3,13 +3,13 @@
"version": "0.8.0", "version": "0.8.0",
"devDependencies": { "devDependencies": {
"escodegen": "^1.8.0", "escodegen": "^1.8.0",
"eslint": "^3.11.1",
"esprima": "^2.7.2", "esprima": "^2.7.2",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"gulp-zip": "^3.2.0", "gulp-zip": "^3.2.0",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",
"jsdoc": "^3.3.0-alpha9", "jsdoc": "^3.3.0-alpha9",
"jshint": "~2.8.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"node-ensure": "^0.0.0", "node-ensure": "^0.0.0",
"requirejs": "^2.1.22", "requirejs": "^2.1.22",

View File

@ -983,7 +983,7 @@ var Font = (function FontClosure() {
// Split the sorted codes into ranges. // Split the sorted codes into ranges.
var ranges = []; var ranges = [];
var length = codes.length; 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 start = codes[n].fontCharCode;
var codeIndices = [codes[n].glyphId]; var codeIndices = [codes[n].glyphId];
++n; ++n;

View File

@ -423,7 +423,7 @@ var PDFFunction = (function PDFFunctionClosure() {
// Compiled function consists of simple expressions such as addition, // Compiled function consists of simple expressions such as addition,
// subtraction, Math.max, and also contains 'var' and 'return' // subtraction, Math.max, and also contains 'var' and 'return'
// statements. See the generation in the PostScriptCompiler below. // 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); return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
} }

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-multi-spaces */
'use strict'; 'use strict';

View File

@ -1,4 +1,3 @@
/* Copyright 2014 Opera Software ASA /* Copyright 2014 Opera Software ASA
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * 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')) { !PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
// old webkits have issues with non-aligned arrays // old webkits have issues with non-aligned arrays
try { try {
// eslint-disable-next-line no-new
new Uint32Array(new Uint8Array(5).buffer, 0, 1); new Uint32Array(new Uint8Array(5).buffer, 0, 1);
} catch (e) { } catch (e) {
alwaysUseUint32ArrayView = true; alwaysUseUint32ArrayView = true;

View File

@ -248,29 +248,29 @@ var Parser = (function ParserClosure() {
case 0xC1: // SOF1 case 0xC1: // SOF1
case 0xC2: // SOF2 case 0xC2: // SOF2
case 0xC3: // SOF3 case 0xC3: // SOF3
/* falls through */
case 0xC5: // SOF5 case 0xC5: // SOF5
case 0xC6: // SOF6 case 0xC6: // SOF6
case 0xC7: // SOF7 case 0xC7: // SOF7
/* falls through */
case 0xC9: // SOF9 case 0xC9: // SOF9
case 0xCA: // SOF10 case 0xCA: // SOF10
case 0xCB: // SOF11 case 0xCB: // SOF11
/* falls through */
case 0xCD: // SOF13 case 0xCD: // SOF13
case 0xCE: // SOF14 case 0xCE: // SOF14
case 0xCF: // SOF15 case 0xCF: // SOF15
/* falls through */
case 0xC4: // DHT case 0xC4: // DHT
case 0xCC: // DAC case 0xCC: // DAC
/* falls through */
case 0xDA: // SOS case 0xDA: // SOS
case 0xDB: // DQT case 0xDB: // DQT
case 0xDC: // DNL case 0xDC: // DNL
case 0xDD: // DRI case 0xDD: // DRI
case 0xDE: // DHP case 0xDE: // DHP
case 0xDF: // EXP case 0xDF: // EXP
/* falls through */
case 0xE0: // APP0 case 0xE0: // APP0
case 0xE1: // APP1 case 0xE1: // APP1
case 0xE2: // APP2 case 0xE2: // APP2
@ -287,7 +287,7 @@ var Parser = (function ParserClosure() {
case 0xED: // APP13 case 0xED: // APP13
case 0xEE: // APP14 case 0xEE: // APP14
case 0xEF: // APP15 case 0xEF: // APP15
/* falls through */
case 0xFE: // COM case 0xFE: // COM
// The marker should be followed by the length of the segment. // The marker should be followed by the length of the segment.
markerLength = stream.getUint16(); markerLength = stream.getUint16();

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-multi-spaces */
'use strict'; 'use strict';

View File

@ -83,14 +83,13 @@ var WorkerTask = (function WorkerTaskClosure() {
})(); })();
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
/*jshint -W082 */
/** /**
* Interface that represents PDF data transport. If possible, it allows * Interface that represents PDF data transport. If possible, it allows
* progressively load entire or fragment of the PDF binary data. * progressively load entire or fragment of the PDF binary data.
* *
* @interface * @interface
* */ */
function IPDFStream() {} function IPDFStream() {} // eslint-disable-line no-inner-declarations
IPDFStream.prototype = { IPDFStream.prototype = {
/** /**
* Gets a reader for the entire PDF data. * Gets a reader for the entire PDF data.
@ -118,7 +117,7 @@ IPDFStream.prototype = {
* *
* @interface * @interface
*/ */
function IPDFStreamReader() {} function IPDFStreamReader() {} // eslint-disable-line no-inner-declarations
IPDFStreamReader.prototype = { IPDFStreamReader.prototype = {
/** /**
* Gets a promise that is resolved when the headers and other metadata of * Gets a promise that is resolved when the headers and other metadata of
@ -179,7 +178,7 @@ IPDFStreamReader.prototype = {
* *
* @interface * @interface
*/ */
function IPDFStreamRangeReader() {} function IPDFStreamRangeReader() {} // eslint-disable-line no-inner-declarations
IPDFStreamRangeReader.prototype = { IPDFStreamRangeReader.prototype = {
/** /**
* Gets ability of the stream to progressively load binary data. * Gets ability of the stream to progressively load binary data.

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
/* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild, requirejs, pdfjsLibs, /* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild, requirejs, pdfjsLibs,
WeakMap */ __webpack_require__ */
'use strict'; 'use strict';

View File

@ -426,7 +426,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
js += 'c.' + current.cmd + '(' + args + ');\n'; js += 'c.' + current.cmd + '(' + args + ');\n';
} }
/* jshint -W054 */ // eslint-disable-next-line no-new-func
this.compiledGlyphs[character] = new Function('c', 'size', js); this.compiledGlyphs[character] = new Function('c', 'size', js);
} else { } else {
// But fall back on using Function.prototype.apply() if we're // But fall back on using Function.prototype.apply() if we're

View File

@ -460,7 +460,7 @@ var SVGGraphics = (function SVGGraphicsClosure() {
convertOpList: function SVGGraphics_convertOpList(operatorList) { convertOpList: function SVGGraphics_convertOpList(operatorList) {
var argsArray = operatorList.argsArray; var argsArray = operatorList.argsArray;
var fnArray = operatorList.fnArray; var fnArray = operatorList.fnArray;
var fnArrayLen = fnArray.length; var fnArrayLen = fnArray.length;
var REVOPS = []; var REVOPS = [];
var opList = []; var opList = [];

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint -W043 */ /* eslint-disable no-multi-str */
'use strict'; 'use strict';

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable strict */
/* /*
NOTE: This file is created as a helper to assist with JSDoc html files. NOTE: This file is created as a helper to assist with JSDoc html files.

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint globalstrict: false */ /* eslint strict: ["error", "function"] */
/* umdutils ignore */ /* umdutils ignore */
(function (root, factory) { (function (root, factory) {

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable strict */
(typeof window !== 'undefined' ? window : {}).pdfjsDistBuildPdfWorker = (typeof window !== 'undefined' ? window : {}).pdfjsDistBuildPdfWorker =
require('./pdf.worker.js'); require('./pdf.worker.js');

View File

@ -73,7 +73,7 @@ function readCharstringEncoding(aString) {
var charstringTokens = []; var charstringTokens = [];
var count = aString.length; 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 value = aString[i++] | 0;
var token = null; var token = null;

View File

@ -620,8 +620,7 @@ function isLittleEndian() {
// Checks if it's possible to eval JS expressions. // Checks if it's possible to eval JS expressions.
function isEvalSupported() { function isEvalSupported() {
try { try {
/* jshint evil: true */ new Function(''); // eslint-disable-line no-new, no-new-func
new Function('');
return true; return true;
} catch (e) { } catch (e) {
return false; return false;
@ -1756,6 +1755,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */ * http://creativecommons.org/publicdomain/zero/1.0/ */
(function checkURLConstructor(scope) { (function checkURLConstructor(scope) {
/* eslint-disable yoda */
// feature detect for URL constructor // feature detect for URL constructor
var hasWorkingUrl = false; var hasWorkingUrl = false;
try { try {
@ -2392,6 +2393,8 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
} }
scope.URL = JURL; scope.URL = JURL;
/* eslint-enable yoda */
})(globalScope); })(globalScope);
} }

11
test/.eslintrc Normal file
View File

@ -0,0 +1,11 @@
{
"extends": [
../.eslintrc
],
"env": {
"node": true,
"shelljs": true,
"jasmine": true,
},
}

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -1,5 +1,3 @@
/*jslint node: true */
'use strict'; 'use strict';
var fs = require('fs'); var fs = require('fs');

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -482,6 +482,7 @@ describe('CipherTransformFactory', function() {
function ensurePasswordNeeded(done, dict, fileId, password) { function ensurePasswordNeeded(done, dict, fileId, password) {
try { try {
// eslint-disable-next-line no-new
new CipherTransformFactory(dict, fileId, password); new CipherTransformFactory(dict, fileId, password);
} catch (ex) { } catch (ex) {
expect(ex instanceof PasswordException).toEqual(true); expect(ex instanceof PasswordException).toEqual(true);
@ -495,6 +496,7 @@ describe('CipherTransformFactory', function() {
function ensurePasswordIncorrect(done, dict, fileId, password) { function ensurePasswordIncorrect(done, dict, fileId, password) {
try { try {
// eslint-disable-next-line no-new
new CipherTransformFactory(dict, fileId, password); new CipherTransformFactory(dict, fileId, password);
} catch (ex) { } catch (ex) {
expect(ex instanceof PasswordException).toEqual(true); expect(ex instanceof PasswordException).toEqual(true);

View File

@ -433,7 +433,7 @@ describe('function', function() {
expect(compiledCode).toBeNull(); expect(compiledCode).toBeNull();
} else { } else {
expect(compiledCode).not.toBeNull(); expect(compiledCode).not.toBeNull();
/*jshint -W054 */ // eslint-disable-next-line no-new-func
var fn = new Function('src', 'srcOffset', 'dest', 'destOffset', var fn = new Function('src', 'srcOffset', 'dest', 'destOffset',
compiledCode); compiledCode);
for (var i = 0; i < samples.length; i++) { for (var i = 0; i < samples.length; i++) {

View File

@ -49,4 +49,4 @@ describe('MurmurHash3_64', function() {
hexdigest2 = hash.hexdigest(); hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2); expect(hexdigest1).not.toEqual(hexdigest2);
}); });
}); });

View File

@ -1,4 +1,3 @@
'use strict'; 'use strict';
var TestReporter = function(browser, appPath) { var TestReporter = function(browser, appPath) {

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*jslint node: true */
'use strict'; 'use strict';

View File

@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals chrome, DEFAULT_URL */ /* globals chrome, DEFAULT_URL */
'use strict'; 'use strict';
(function (root, factory) { (function (root, factory) {
@ -201,9 +201,11 @@
// Use Chrome's definition of UI language instead of PDF.js's #lang=..., // Use Chrome's definition of UI language instead of PDF.js's #lang=...,
// because the shown string should match the UI at chrome://extensions. // because the shown string should match the UI at chrome://extensions.
// These strings are from chrome/app/resources/generated_resources_*.xtb. // These strings are from chrome/app/resources/generated_resources_*.xtb.
/* eslint-disable no-unexpected-multiline */
var i18nFileAccessLabel = var i18nFileAccessLabel =
PDFJSDev.json('$ROOT/web/chrome-i18n-allow-access-to-file-urls.json') PDFJSDev.json('$ROOT/web/chrome-i18n-allow-access-to-file-urls.json')
[chrome.i18n.getUILanguage && chrome.i18n.getUILanguage()]; [chrome.i18n.getUILanguage && chrome.i18n.getUILanguage()];
/* eslint-enable no-unexpected-multiline */
if (i18nFileAccessLabel) { if (i18nFileAccessLabel) {
document.getElementById('chrome-file-access-label').textContent = document.getElementById('chrome-file-access-label').textContent =

View File

@ -12,6 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* eslint-disable no-extend-native */
/* globals VBArray, PDFJS */ /* globals VBArray, PDFJS */
(function compatibilityWrapper() { (function compatibilityWrapper() {

View File

@ -26,7 +26,7 @@
} }
}(this, function (exports, pdfjsLib) { }(this, function (exports, pdfjsLib) {
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) {
/* jshint -W082 */ // eslint-disable-next-line no-inner-declarations
function download(blobUrl, filename) { function download(blobUrl, filename) {
var a = document.createElement('a'); var a = document.createElement('a');
if (a.click) { 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 = { DownloadManager.prototype = {
downloadUrl: function DownloadManager_downloadUrl(url, filename) { downloadUrl: function DownloadManager_downloadUrl(url, filename) {

View File

@ -122,7 +122,7 @@
} }
if (event.originalTarget) { if (event.originalTarget) {
try { try {
/* jshint expr:true */ // eslint-disable-next-line no-unused-expressions
event.originalTarget.tagName; event.originalTarget.tagName;
} catch (e) { } catch (e) {
// Mozilla-specific: element is a scrollbar (XUL element) // Mozilla-specific: element is a scrollbar (XUL element)

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* jshint globalstrict: false */ /* eslint strict: ["error", "function"] */
/* umdutils ignore */ /* umdutils ignore */
(function (root, factory) { (function (root, factory) {