eslint 2.11.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/README.md +24 -0
- package/conf/eslint-all.js +29 -0
- package/conf/eslint.json +10 -6
- package/lib/ast-utils.js +91 -0
- package/lib/config/config-file.js +9 -4
- package/lib/config/config-ops.js +27 -2
- package/lib/eslint.js +34 -15
- package/lib/file-finder.js +3 -59
- package/lib/ignored-paths.js +38 -4
- package/lib/options.js +1 -1
- package/lib/rules/accessor-pairs.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/arrow-body-style.js +57 -15
- package/lib/rules/callback-return.js +25 -3
- package/lib/rules/default-case.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/func-names.js +15 -4
- package/lib/rules/max-len.js +3 -2
- package/lib/rules/max-lines.js +148 -0
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/newline-per-chained-call.js +16 -1
- package/lib/rules/no-extra-parens.js +1 -92
- package/lib/rules/no-extra-semi.js +10 -1
- package/lib/rules/no-mixed-operators.js +212 -0
- package/lib/rules/no-multiple-empty-lines.js +40 -9
- package/lib/rules/no-prototype-builtins.js +1 -1
- package/lib/rules/no-script-url.js +1 -1
- package/lib/rules/no-unsafe-finally.js +1 -1
- package/lib/rules/no-useless-rename.js +11 -3
- package/lib/rules/object-curly-newline.js +209 -0
- package/lib/rules/object-shorthand.js +75 -5
- package/lib/rules/one-var.js +3 -0
- package/lib/rules/padded-blocks.js +19 -1
- package/lib/rules/rest-spread-spacing.js +107 -0
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/util/glob-util.js +2 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,80 @@
|
|
1
|
+
v2.13.1 - June 20, 2016
|
2
|
+
|
3
|
+
* 434de7f Fix: wrong baseDir (fixes #6450) (#6457) (Toru Nagashima)
|
4
|
+
* 3c9ce09 Fix: Keep indentation when fixing `padded-blocks` "never" (fixes #6454) (#6456) (Ed Lee)
|
5
|
+
* a9d4cb2 Docs: Fix typo in max-params examples (#6471) (J. William Ashton)
|
6
|
+
* 1e185b9 Fix: no-multiple-empty-lines errors when no line breaks (fixes #6449) (#6451) (strawbrary)
|
7
|
+
|
8
|
+
v2.13.0 - June 17, 2016
|
9
|
+
|
10
|
+
* cf223dd Fix: add test for a syntax error (fixes #6013) (#6378) (Toru Nagashima)
|
11
|
+
* da30cf9 Update: Add fixer for object-shorthand (fixes #6412) (#6418) (Nick Heiner)
|
12
|
+
* 2cd90eb Chore: Fix rule meta description inconsistencies (refs #5417) (#6422) (Mark Pedrotti)
|
13
|
+
* d798b2c Added quotes around "classes" option key (#6441) (Guy Fraser)
|
14
|
+
* 852b6df Docs: Delete empty table of links from Code Path Analysis (#6423) (Mark Pedrotti)
|
15
|
+
* 5e9117e Chore: sort rules in eslint.json (fixes #6425) (#6426) (alberto)
|
16
|
+
* c2b5277 Docs: Add gitter chat link to Reporting Bugs (#6430) (Mark Pedrotti)
|
17
|
+
* 1316db0 Update: Add `never` option for `func-names` (fixes #6059) (#6392) (alberto)
|
18
|
+
* 1c123e2 Update: Add autofix for `padded-blocks` (fixes #6320) (#6393) (alberto)
|
19
|
+
* 8ec89c8 Fix: `--print-config` return config inside subdir (fixes #6329) (#6385) (alberto)
|
20
|
+
* 4f73240 Fix: `object-curly-newline` multiline with comments (fixes #6381) (#6396) (Toru Nagashima)
|
21
|
+
* 77697a7 Chore: Fake config hierarchy fixtures (fixes #6206) (#6402) (Gyandeep Singh)
|
22
|
+
* 73a9a6d Docs: Fix links in Configuring ESLint (#6421) (Mark Pedrotti)
|
23
|
+
* ed84c4c Fix: improve `newline-per-chained-call` message (fixes #6340) (#6360) (Toru Nagashima)
|
24
|
+
* 9ea4e44 Docs: Update parser reference to `espree` instead of `esprima` (#6404) (alberto)
|
25
|
+
* 7f57467 Docs: Make `fix` param clearer (fixes #6366) (#6367) (Nick Heiner)
|
26
|
+
* fb49c7f Fix: nested `extends` with relative path (fixes #6358) (#6359) (Toru Nagashima)
|
27
|
+
* 5122f73 Update: no-multiple-empty-lines fixer (fixes #6225) (#6226) (Ruurd Moelker)
|
28
|
+
* 0e7ce72 Docs: Fix rest-spread-spacing's name (#6365) (cody)
|
29
|
+
* cfdd524 Fix: allow semi as braceless body of statements (fixes #6386) (#6391) (alberto)
|
30
|
+
* 6b08cfc Docs: key-spacing fixable documenation notes (fixes #6375) (#6376) (Ruurd Moelker)
|
31
|
+
* 4b4be3b Docs: `max-lines` option: fix `skipComments` typo (#6374) (Jordan Harband)
|
32
|
+
* 20ab4f6 Docs: Fix wrong link in object-curly-newline (#6373) (Grant Snodgrass)
|
33
|
+
* 412ce8d Docs: Fix broken links in no-mixed-operators (#6372) (Grant Snodgrass)
|
34
|
+
|
35
|
+
v2.12.0 - June 10, 2016
|
36
|
+
|
37
|
+
* 54c30fb Update: Add explicit default option `always` for `eqeqeq` (refs #6144) (#6342) (alberto)
|
38
|
+
* 2d63370 Update: max-len will warn indented comment lines (fixes #6322) (#6324) (Kai Cataldo)
|
39
|
+
* dcd4ad7 Docs: clarify usage of inline disable comments (fixes #6335) (#6347) (Kai Cataldo)
|
40
|
+
* c03300b Docs: Clarified how plugin rules look in plugin configs (fixes #6346) (#6351) (Kevin Partington)
|
41
|
+
* 9c87709 Docs: Add semantic versioning policy (fixes #6244) (#6343) (Nicholas C. Zakas)
|
42
|
+
* 5affab1 Docs: Describe values under Extending Configuration Files (refs #6240) (#6336) (Mark Pedrotti)
|
43
|
+
* 2520f5a New: `max-lines` rule (fixes #6078) (#6321) (alberto)
|
44
|
+
* 9bfbc64 Update: Option for object literals in `arrow-body-style` (fixes #5936) (#6216) (alberto)
|
45
|
+
* 977cdd5 Chore: remove unused method from FileFinder (fixes #6344) (#6345) (alberto)
|
46
|
+
* 477fbc1 Docs: Add section about customizing RuleTester (fixes #6227) (#6331) (Jeroen Engels)
|
47
|
+
* 0e14016 New: `no-mixed-operators` rule (fixes #6023) (#6241) (Toru Nagashima)
|
48
|
+
* 6e03c4b Update: Add never option to arrow-body-style (fixes #6317) (#6318) (Andrew Hyndman)
|
49
|
+
* f804397 New: Add `eslint:all` option (fixes #6240) (#6248) (Robert Fletcher)
|
50
|
+
* dfe05bf Docs: Link JSCS rules to their corresponding page. (#6334) (alberto)
|
51
|
+
* 1cc4356 Docs: Remove reference to numeric config (fixes #6309) (#6327) (Kevin Partington)
|
52
|
+
* 2d4efbe Docs: Describe options in rule under Strict Mode (#6312) (Mark Pedrotti)
|
53
|
+
* c1953fa Docs: Typo fix 'and' -> 'any' (#6326) (Stephen Edgar)
|
54
|
+
* d49ab4b Docs: Code conventions improvements (#6313) (Kevin Partington)
|
55
|
+
* 316a507 Fix: one-var allows uninitialized vars in ForIn/ForOf (fixes #5744) (#6272) (Kai Cataldo)
|
56
|
+
* 6cbee31 Docs: Typo fix 'colum' -> 'column' (#6306) (Andrew Cobby)
|
57
|
+
* 2663569 New: `object-curly-newline` (fixes #6072) (#6223) (Toru Nagashima)
|
58
|
+
* 72c2ea5 Update: callback-return allows for object methods (fixes #4711) (#6277) (Kai Cataldo)
|
59
|
+
* 89580a4 Docs: Distinguish examples in rules under Stylistic Issues part 5 (#6291) (Kenneth Williams)
|
60
|
+
* 1313804 New: rest-spread-spacing rule (fixes #5391) (#6278) (Kai Cataldo)
|
61
|
+
* 61dfe68 Fix: `no-useless-rename` false positive in babel-eslint (fixes #6266) (#6290) (alberto)
|
62
|
+
* c78c8cb Build: Remove commit check from appveyor (fixes #6292) (#6294) (alberto)
|
63
|
+
* 3e38fc1 Chore: more tests for comments at the end of blocks (refs #6090) (#6273) (Kai Cataldo)
|
64
|
+
* 38dccdd Docs: `--no-ignore` disables all forms of ignore (fixes #6260) (#6304) (alberto)
|
65
|
+
* bb69380 Fix: no-useless-rename handles ExperimentalRestProperty (fixes #6284) (#6288) (Kevin Partington)
|
66
|
+
* fca0679 Update: Improve perf not traversing default ignored dirs (fixes #5679) (#6276) (alberto)
|
67
|
+
* 320e8b0 Docs: Describe options in rules under Possible Errors part 4 (#6270) (Mark Pedrotti)
|
68
|
+
* 3e052c1 Docs: Mark no-useless-rename as fixable in rules index (#6297) (Dalton Santos)
|
69
|
+
|
70
|
+
v2.11.1 - May 30, 2016
|
71
|
+
|
72
|
+
* 64b0d0c Fix: failed to parse `/*eslint` comments by colon (fixes #6224) (#6258) (Toru Nagashima)
|
73
|
+
* c8936eb Build: Don't check commit count (fixes #5935) (#6263) (Nicholas C. Zakas)
|
74
|
+
* 113c1a8 Fix: `max-statements-per-line` false positive at exports (fixes #6264) (#6268) (Toru Nagashima)
|
75
|
+
* 03beb27 Fix: `no-useless-rename` false positives (fixes #6266) (#6267) (alberto)
|
76
|
+
* fe89037 Docs: Fix rule name in example (#6279) (Kenneth Williams)
|
77
|
+
|
1
78
|
v2.11.0 - May 27, 2016
|
2
79
|
|
3
80
|
* 77dd2b4 Fix: On --init, print message when package.json is invalid (fixes #6257) (#6261) (Kai Cataldo)
|
package/README.md
CHANGED
@@ -104,6 +104,30 @@ Before filing an issue, please be sure to read the guidelines for what you're re
|
|
104
104
|
* [Proposing a Rule Change](http://eslint.org/docs/developer-guide/contributing/rule-changes)
|
105
105
|
* [Request a Change](http://eslint.org/docs/developer-guide/contributing/changes)
|
106
106
|
|
107
|
+
## Semantic Versioning Policy
|
108
|
+
|
109
|
+
ESLint follows [semantic versioning](http://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
|
110
|
+
|
111
|
+
* Patch release (intended to not break your lint build)
|
112
|
+
* A bug fix in a rule that results in ESLint reporting fewer errors.
|
113
|
+
* A bug fix to the CLI or core (including formatters).
|
114
|
+
* Improvements to documentation.
|
115
|
+
* Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
|
116
|
+
* Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
|
117
|
+
* Minor release (might break your lint build)
|
118
|
+
* A bug fix in a rule that results in ESLint reporting more errors.
|
119
|
+
* A new rule is created.
|
120
|
+
* A new option to an existing rule is created.
|
121
|
+
* An existing rule is deprecated.
|
122
|
+
* A new CLI capability is created.
|
123
|
+
* New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
|
124
|
+
* A new formatter is created.
|
125
|
+
* Major release (likely to break your lint build)
|
126
|
+
* `eslint:recommended` is updated.
|
127
|
+
* An existing rule is removed.
|
128
|
+
* An existing formatter is removed.
|
129
|
+
* Part of the public API is removed or changed in an incompatible way.
|
130
|
+
|
107
131
|
## Frequently Asked Questions
|
108
132
|
|
109
133
|
### How is ESLint different from JSHint?
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Config to enable all rules.
|
3
|
+
* @author Robert Fletcher
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
var fs = require("fs"),
|
13
|
+
path = require("path");
|
14
|
+
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
// Helpers
|
17
|
+
//------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
var ruleFiles = fs.readdirSync(path.resolve(__dirname, "../lib/rules"));
|
20
|
+
var enabledRules = ruleFiles.reduce(function(result, filename) {
|
21
|
+
result[path.basename(filename, ".js")] = "error";
|
22
|
+
return result;
|
23
|
+
}, {});
|
24
|
+
|
25
|
+
//------------------------------------------------------------------------------
|
26
|
+
// Public Interface
|
27
|
+
//------------------------------------------------------------------------------
|
28
|
+
|
29
|
+
module.exports = { rules: enabledRules };
|
package/conf/eslint.json
CHANGED
@@ -19,9 +19,9 @@
|
|
19
19
|
"no-debugger": "error",
|
20
20
|
"no-delete-var": "error",
|
21
21
|
"no-div-regex": "off",
|
22
|
+
"no-dupe-args": "error",
|
22
23
|
"no-dupe-class-members": "error",
|
23
24
|
"no-dupe-keys": "error",
|
24
|
-
"no-dupe-args": "error",
|
25
25
|
"no-duplicate-case": "error",
|
26
26
|
"no-duplicate-imports": "off",
|
27
27
|
"no-else-return": "off",
|
@@ -55,9 +55,10 @@
|
|
55
55
|
"no-lone-blocks": "off",
|
56
56
|
"no-lonely-if": "off",
|
57
57
|
"no-loop-func": "off",
|
58
|
+
"no-magic-numbers": "off",
|
59
|
+
"no-mixed-operators": "off",
|
58
60
|
"no-mixed-requires": "off",
|
59
61
|
"no-mixed-spaces-and-tabs": "error",
|
60
|
-
"linebreak-style": "off",
|
61
62
|
"no-multi-spaces": "off",
|
62
63
|
"no-multi-str": "off",
|
63
64
|
"no-multiple-empty-lines": "off",
|
@@ -125,7 +126,6 @@
|
|
125
126
|
"no-var": "off",
|
126
127
|
"no-warning-comments": "off",
|
127
128
|
"no-with": "off",
|
128
|
-
"no-magic-numbers": "off",
|
129
129
|
"array-bracket-spacing": "off",
|
130
130
|
"array-callback-return": "off",
|
131
131
|
"arrow-body-style": "off",
|
@@ -157,15 +157,19 @@
|
|
157
157
|
"global-require": "off",
|
158
158
|
"guard-for-in": "off",
|
159
159
|
"handle-callback-err": "off",
|
160
|
+
"id-blacklist": "off",
|
160
161
|
"id-length": "off",
|
162
|
+
"id-match": "off",
|
161
163
|
"indent": "off",
|
162
164
|
"init-declarations": "off",
|
163
165
|
"jsx-quotes": "off",
|
164
166
|
"key-spacing": "off",
|
165
167
|
"keyword-spacing": "off",
|
168
|
+
"linebreak-style": "off",
|
166
169
|
"lines-around-comment": "off",
|
167
170
|
"max-depth": "off",
|
168
171
|
"max-len": "off",
|
172
|
+
"max-lines": "off",
|
169
173
|
"max-nested-callbacks": "off",
|
170
174
|
"max-params": "off",
|
171
175
|
"max-statements": "off",
|
@@ -175,6 +179,7 @@
|
|
175
179
|
"newline-after-var": "off",
|
176
180
|
"newline-before-return": "off",
|
177
181
|
"newline-per-chained-call": "off",
|
182
|
+
"object-curly-newline": "off",
|
178
183
|
"object-curly-spacing": ["off", "never"],
|
179
184
|
"object-property-newline": "off",
|
180
185
|
"object-shorthand": "off",
|
@@ -192,14 +197,13 @@
|
|
192
197
|
"quote-props": "off",
|
193
198
|
"quotes": "off",
|
194
199
|
"radix": "off",
|
195
|
-
"id-match": "off",
|
196
|
-
"id-blacklist": "off",
|
197
200
|
"require-jsdoc": "off",
|
198
201
|
"require-yield": "off",
|
202
|
+
"rest-spread-spacing": "off",
|
199
203
|
"semi": "off",
|
200
204
|
"semi-spacing": "off",
|
201
|
-
"sort-vars": "off",
|
202
205
|
"sort-imports": "off",
|
206
|
+
"sort-vars": "off",
|
203
207
|
"space-before-blocks": "off",
|
204
208
|
"space-before-function-paren": "off",
|
205
209
|
"space-in-parens": "off",
|
package/lib/ast-utils.js
CHANGED
@@ -460,5 +460,96 @@ module.exports = {
|
|
460
460
|
|
461
461
|
/* istanbul ignore next */
|
462
462
|
return true;
|
463
|
+
},
|
464
|
+
|
465
|
+
/**
|
466
|
+
* Get the precedence level based on the node type
|
467
|
+
* @param {ASTNode} node node to evaluate
|
468
|
+
* @returns {int} precedence level
|
469
|
+
* @private
|
470
|
+
*/
|
471
|
+
getPrecedence: function(node) {
|
472
|
+
switch (node.type) {
|
473
|
+
case "SequenceExpression":
|
474
|
+
return 0;
|
475
|
+
|
476
|
+
case "AssignmentExpression":
|
477
|
+
case "ArrowFunctionExpression":
|
478
|
+
case "YieldExpression":
|
479
|
+
return 1;
|
480
|
+
|
481
|
+
case "ConditionalExpression":
|
482
|
+
return 3;
|
483
|
+
|
484
|
+
case "LogicalExpression":
|
485
|
+
switch (node.operator) {
|
486
|
+
case "||":
|
487
|
+
return 4;
|
488
|
+
case "&&":
|
489
|
+
return 5;
|
490
|
+
|
491
|
+
// no default
|
492
|
+
}
|
493
|
+
|
494
|
+
/* falls through */
|
495
|
+
|
496
|
+
case "BinaryExpression":
|
497
|
+
|
498
|
+
switch (node.operator) {
|
499
|
+
case "|":
|
500
|
+
return 6;
|
501
|
+
case "^":
|
502
|
+
return 7;
|
503
|
+
case "&":
|
504
|
+
return 8;
|
505
|
+
case "==":
|
506
|
+
case "!=":
|
507
|
+
case "===":
|
508
|
+
case "!==":
|
509
|
+
return 9;
|
510
|
+
case "<":
|
511
|
+
case "<=":
|
512
|
+
case ">":
|
513
|
+
case ">=":
|
514
|
+
case "in":
|
515
|
+
case "instanceof":
|
516
|
+
return 10;
|
517
|
+
case "<<":
|
518
|
+
case ">>":
|
519
|
+
case ">>>":
|
520
|
+
return 11;
|
521
|
+
case "+":
|
522
|
+
case "-":
|
523
|
+
return 12;
|
524
|
+
case "*":
|
525
|
+
case "/":
|
526
|
+
case "%":
|
527
|
+
return 13;
|
528
|
+
|
529
|
+
// no default
|
530
|
+
}
|
531
|
+
|
532
|
+
/* falls through */
|
533
|
+
|
534
|
+
case "UnaryExpression":
|
535
|
+
return 14;
|
536
|
+
|
537
|
+
case "UpdateExpression":
|
538
|
+
return 15;
|
539
|
+
|
540
|
+
case "CallExpression":
|
541
|
+
|
542
|
+
// IIFE is allowed to have parens in any position (#655)
|
543
|
+
if (node.callee.type === "FunctionExpression") {
|
544
|
+
return -1;
|
545
|
+
}
|
546
|
+
return 16;
|
547
|
+
|
548
|
+
case "NewExpression":
|
549
|
+
return 17;
|
550
|
+
|
551
|
+
// no default
|
552
|
+
}
|
553
|
+
return 18;
|
463
554
|
}
|
464
555
|
};
|
@@ -369,6 +369,12 @@ function applyExtends(config, filePath, relativeTo) {
|
|
369
369
|
* this lets us use the eslint.json file as the recommended rules
|
370
370
|
*/
|
371
371
|
parentPath = path.resolve(__dirname, "../../conf/eslint.json");
|
372
|
+
} else if (parentPath === "eslint:all") {
|
373
|
+
|
374
|
+
/*
|
375
|
+
* Add an explicit substitution for eslint:all to conf/eslint-all.js
|
376
|
+
*/
|
377
|
+
parentPath = path.resolve(__dirname, "../../conf/eslint-all.js");
|
372
378
|
} else if (isFilePath(parentPath)) {
|
373
379
|
|
374
380
|
/*
|
@@ -376,7 +382,7 @@ function applyExtends(config, filePath, relativeTo) {
|
|
376
382
|
* file as the reference point. Otherwise, use as-is.
|
377
383
|
*/
|
378
384
|
parentPath = (!isAbsolutePath(parentPath) ?
|
379
|
-
path.join(path.dirname(filePath), parentPath) :
|
385
|
+
path.join(relativeTo || path.dirname(filePath), parentPath) :
|
380
386
|
parentPath
|
381
387
|
);
|
382
388
|
}
|
@@ -489,7 +495,6 @@ function resolve(filePath, relativeTo) {
|
|
489
495
|
function load(filePath, applyEnvironments, relativeTo) {
|
490
496
|
var resolvedPath = resolve(filePath, relativeTo),
|
491
497
|
dirname = path.dirname(resolvedPath.filePath),
|
492
|
-
basedir = getBaseDir(dirname),
|
493
498
|
lookupPath = getLookupPath(dirname),
|
494
499
|
config = loadConfigFile(resolvedPath);
|
495
500
|
|
@@ -508,7 +513,7 @@ function load(filePath, applyEnvironments, relativeTo) {
|
|
508
513
|
// include full path of parser if present
|
509
514
|
if (config.parser) {
|
510
515
|
if (isFilePath(config.parser)) {
|
511
|
-
config.parser = path.resolve(
|
516
|
+
config.parser = path.resolve(dirname || "", config.parser);
|
512
517
|
} else {
|
513
518
|
config.parser = resolver.resolve(config.parser, lookupPath);
|
514
519
|
}
|
@@ -522,7 +527,7 @@ function load(filePath, applyEnvironments, relativeTo) {
|
|
522
527
|
* a "parent". Load the referenced file and merge the configuration recursively.
|
523
528
|
*/
|
524
529
|
if (config.extends) {
|
525
|
-
config = applyExtends(config, filePath,
|
530
|
+
config = applyExtends(config, filePath, dirname);
|
526
531
|
}
|
527
532
|
|
528
533
|
if (config.env && applyEnvironments) {
|
package/lib/config/config-ops.js
CHANGED
@@ -23,7 +23,8 @@ var RULE_SEVERITY_STRINGS = ["off", "warn", "error"],
|
|
23
23
|
RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce(function(map, value, index) {
|
24
24
|
map[value] = index;
|
25
25
|
return map;
|
26
|
-
}, {})
|
26
|
+
}, {}),
|
27
|
+
VALID_SEVERITIES = [0, 1, 2, "off", "warn", "error"];
|
27
28
|
|
28
29
|
//------------------------------------------------------------------------------
|
29
30
|
// Public Interface
|
@@ -248,6 +249,30 @@ module.exports = {
|
|
248
249
|
}
|
249
250
|
|
250
251
|
return (typeof severity === "number" && severity === 2);
|
251
|
-
}
|
252
|
+
},
|
252
253
|
|
254
|
+
/**
|
255
|
+
* Checks whether a given config has valid severity or not.
|
256
|
+
* @param {number|string|Array} ruleConfig - The configuration for an individual rule.
|
257
|
+
* @returns {boolean} `true` if the configuration has valid severity.
|
258
|
+
*/
|
259
|
+
isValidSeverity: function(ruleConfig) {
|
260
|
+
var severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
|
261
|
+
|
262
|
+
if (typeof severity === "string") {
|
263
|
+
severity = severity.toLowerCase();
|
264
|
+
}
|
265
|
+
return VALID_SEVERITIES.indexOf(severity) !== -1;
|
266
|
+
},
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Checks whether every rule of a given config has valid severity or not.
|
270
|
+
* @param {object} config - The configuration for rules.
|
271
|
+
* @returns {boolean} `true` if the configuration has valid severity.
|
272
|
+
*/
|
273
|
+
isEverySeverityValid: function(config) {
|
274
|
+
return Object.keys(config).every(function(ruleId) {
|
275
|
+
return this.isValidSeverity(config[ruleId]);
|
276
|
+
}, this);
|
277
|
+
}
|
253
278
|
};
|
package/lib/eslint.js
CHANGED
@@ -9,25 +9,25 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
var
|
13
|
-
|
12
|
+
var assert = require("assert"),
|
13
|
+
EventEmitter = require("events").EventEmitter,
|
14
14
|
escope = require("escope"),
|
15
|
-
|
15
|
+
levn = require("levn"),
|
16
|
+
lodash = require("lodash"),
|
16
17
|
blankScriptAST = require("../conf/blank-script.json"),
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
SourceCode = require("./util/source-code"),
|
21
|
-
NodeEventGenerator = require("./util/node-event-generator"),
|
22
|
-
CommentEventGenerator = require("./util/comment-event-generator"),
|
23
|
-
EventEmitter = require("events").EventEmitter,
|
18
|
+
DEFAULT_PARSER = require("../conf/eslint.json").parser,
|
19
|
+
replacements = require("../conf/replacements.json"),
|
20
|
+
CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"),
|
24
21
|
ConfigOps = require("./config/config-ops"),
|
25
22
|
validator = require("./config/config-validator"),
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
Environments = require("./config/environments"),
|
24
|
+
CommentEventGenerator = require("./util/comment-event-generator"),
|
25
|
+
NodeEventGenerator = require("./util/node-event-generator"),
|
26
|
+
SourceCode = require("./util/source-code"),
|
27
|
+
Traverser = require("./util/traverser"),
|
28
|
+
RuleContext = require("./rule-context"),
|
29
|
+
rules = require("./rules"),
|
30
|
+
timing = require("./timing");
|
31
31
|
|
32
32
|
//------------------------------------------------------------------------------
|
33
33
|
// Helpers
|
@@ -80,6 +80,25 @@ function parseBooleanConfig(string, comment) {
|
|
80
80
|
function parseJsonConfig(string, location, messages) {
|
81
81
|
var items = {};
|
82
82
|
|
83
|
+
// Parses a JSON-like comment by the same way as parsing CLI option.
|
84
|
+
try {
|
85
|
+
items = levn.parse("Object", string) || {};
|
86
|
+
|
87
|
+
// Some tests say that it should ignore invalid comments such as `/*eslint no-alert:abc*/`.
|
88
|
+
// Also, commaless notations have invalid severity:
|
89
|
+
// "no-alert: 2 no-console: 2" --> {"no-alert": "2 no-console: 2"}
|
90
|
+
// Should ignore that case as well.
|
91
|
+
if (ConfigOps.isEverySeverityValid(items)) {
|
92
|
+
return items;
|
93
|
+
}
|
94
|
+
} catch (ex) {
|
95
|
+
|
96
|
+
// ignore to parse the string by a fallback.
|
97
|
+
}
|
98
|
+
|
99
|
+
// Optionator cannot parse commaless notations.
|
100
|
+
// But we are supporting that. So this is a fallback for that.
|
101
|
+
items = {};
|
83
102
|
string = string.replace(/([a-zA-Z0-9\-\/]+):/g, "\"$1\":").replace(/(\]|[0-9])\s+(?=")/, "$1,");
|
84
103
|
try {
|
85
104
|
items = JSON.parse("{" + string + "}");
|
package/lib/file-finder.js
CHANGED
@@ -69,64 +69,6 @@ function normalizeDirectoryEntries(entries, directory, supportedConfigs) {
|
|
69
69
|
return fileHash;
|
70
70
|
}
|
71
71
|
|
72
|
-
/**
|
73
|
-
* Find one instance of a specified file name in directory or in a parent directory.
|
74
|
-
* Cache the results.
|
75
|
-
* Does not check if a matching directory entry is a file, and intentionally
|
76
|
-
* only searches for the first file name in this.fileNames.
|
77
|
-
* Is currently used by lib/ignored_paths.js to find an .eslintignore file.
|
78
|
-
* @param {string} directory The directory to start the search from.
|
79
|
-
* @returns {string} Path of the file found, or an empty string if not found.
|
80
|
-
*/
|
81
|
-
FileFinder.prototype.findInDirectoryOrParents = function(directory) {
|
82
|
-
var cache = this.cache,
|
83
|
-
child,
|
84
|
-
dirs,
|
85
|
-
filePath,
|
86
|
-
i,
|
87
|
-
names,
|
88
|
-
searched;
|
89
|
-
|
90
|
-
if (!directory) {
|
91
|
-
directory = this.cwd;
|
92
|
-
}
|
93
|
-
|
94
|
-
if (cache.hasOwnProperty(directory)) {
|
95
|
-
return cache[directory];
|
96
|
-
}
|
97
|
-
|
98
|
-
dirs = [];
|
99
|
-
searched = 0;
|
100
|
-
names = this.fileNames;
|
101
|
-
|
102
|
-
(function() {
|
103
|
-
while (directory !== child) {
|
104
|
-
dirs[searched++] = directory;
|
105
|
-
var filesMap = normalizeDirectoryEntries(getDirectoryEntries(directory), directory, names);
|
106
|
-
|
107
|
-
if (Object.keys(filesMap).length) {
|
108
|
-
for (var k = 0; k < names.length; k++) {
|
109
|
-
if (filesMap[names[k]]) {
|
110
|
-
filePath = filesMap[names[k]];
|
111
|
-
return;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
child = directory;
|
117
|
-
|
118
|
-
// Assign parent directory to directory.
|
119
|
-
directory = path.dirname(directory);
|
120
|
-
}
|
121
|
-
}());
|
122
|
-
|
123
|
-
for (i = 0; i < searched; i++) {
|
124
|
-
cache[dirs[i]] = filePath;
|
125
|
-
}
|
126
|
-
|
127
|
-
return filePath || String();
|
128
|
-
};
|
129
|
-
|
130
72
|
/**
|
131
73
|
* Find all instances of files with the specified file names, in directory and
|
132
74
|
* parent directories. Cache the results.
|
@@ -146,7 +88,9 @@ FileFinder.prototype.findAllInDirectoryAndParents = function(directory) {
|
|
146
88
|
j,
|
147
89
|
searched;
|
148
90
|
|
149
|
-
if (
|
91
|
+
if (directory) {
|
92
|
+
directory = path.resolve(this.cwd, directory);
|
93
|
+
} else {
|
150
94
|
directory = this.cwd;
|
151
95
|
}
|
152
96
|
|
package/lib/ignored-paths.js
CHANGED
@@ -24,9 +24,9 @@ debug = debug("eslint:ignored-paths");
|
|
24
24
|
//------------------------------------------------------------------------------
|
25
25
|
|
26
26
|
var ESLINT_IGNORE_FILENAME = ".eslintignore";
|
27
|
-
var
|
28
|
-
"/
|
29
|
-
"/
|
27
|
+
var DEFAULT_IGNORE_DIRS = [
|
28
|
+
"node_modules/",
|
29
|
+
"bower_components/"
|
30
30
|
];
|
31
31
|
var DEFAULT_OPTIONS = {
|
32
32
|
dotfiles: false,
|
@@ -97,7 +97,9 @@ function IgnoredPaths(options) {
|
|
97
97
|
return ig.add(fs.readFileSync(filepath, "utf8"));
|
98
98
|
}
|
99
99
|
|
100
|
-
this.defaultPatterns =
|
100
|
+
this.defaultPatterns = DEFAULT_IGNORE_DIRS.map(function(dir) {
|
101
|
+
return "/" + dir + "*";
|
102
|
+
}).concat(options.patterns || []);
|
101
103
|
this.baseDir = options.cwd;
|
102
104
|
|
103
105
|
this.ig = {
|
@@ -188,4 +190,36 @@ IgnoredPaths.prototype.contains = function(filepath, category) {
|
|
188
190
|
|
189
191
|
};
|
190
192
|
|
193
|
+
/**
|
194
|
+
* Returns a list of dir patterns for glob to ignore
|
195
|
+
* @returns {string[]} list of glob ignore patterns
|
196
|
+
*/
|
197
|
+
IgnoredPaths.prototype.getIgnoredFoldersGlobPatterns = function() {
|
198
|
+
var dirs = DEFAULT_IGNORE_DIRS;
|
199
|
+
|
200
|
+
if (this.options.ignore) {
|
201
|
+
|
202
|
+
/* eslint-disable no-underscore-dangle */
|
203
|
+
|
204
|
+
var patterns = this.ig.custom._rules.filter(function(rule) {
|
205
|
+
return rule.negative;
|
206
|
+
}).map(function(rule) {
|
207
|
+
return rule.origin;
|
208
|
+
});
|
209
|
+
|
210
|
+
/* eslint-enable no-underscore-dangle */
|
211
|
+
|
212
|
+
dirs = dirs.filter(function(dir) {
|
213
|
+
return patterns.every(function(p) {
|
214
|
+
return (p.indexOf("!" + dir) !== 0 && p.indexOf("!/" + dir) !== 0);
|
215
|
+
});
|
216
|
+
});
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
return dirs.map(function(dir) {
|
221
|
+
return dir + "**";
|
222
|
+
});
|
223
|
+
};
|
224
|
+
|
191
225
|
module.exports = IgnoredPaths;
|
package/lib/options.js
CHANGED
@@ -73,7 +73,7 @@ function isPropertyDescriptor(node) {
|
|
73
73
|
module.exports = {
|
74
74
|
meta: {
|
75
75
|
docs: {
|
76
|
-
description: "
|
76
|
+
description: "enforce getter and setter pairs in objects",
|
77
77
|
category: "Best Practices",
|
78
78
|
recommended: false
|
79
79
|
},
|
@@ -13,7 +13,7 @@ var astUtils = require("../ast-utils");
|
|
13
13
|
module.exports = {
|
14
14
|
meta: {
|
15
15
|
docs: {
|
16
|
-
description: "
|
16
|
+
description: "enforce consistent spacing inside array brackets",
|
17
17
|
category: "Stylistic Issues",
|
18
18
|
recommended: false
|
19
19
|
},
|