eslint 5.2.0 → 5.6.0
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 +63 -0
- package/conf/eslint-recommended.js +4 -0
- package/lib/cli-engine.js +13 -14
- package/lib/code-path-analysis/code-path-analyzer.js +1 -1
- package/lib/config/config-initializer.js +7 -7
- package/lib/config.js +1 -1
- package/lib/formatters/codeframe.js +2 -2
- package/lib/ignored-paths.js +125 -37
- package/lib/linter.js +1 -1
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +1 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/camelcase.js +1 -1
- package/lib/rules/capitalized-comments.js +1 -1
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +2 -2
- package/lib/rules/complexity.js +3 -3
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/for-direction.js +5 -2
- package/lib/rules/func-call-spacing.js +8 -4
- package/lib/rules/func-name-matching.js +13 -7
- package/lib/rules/func-names.js +82 -21
- package/lib/rules/func-style.js +8 -4
- package/lib/rules/function-paren-newline.js +12 -6
- package/lib/rules/generator-star-spacing.js +18 -9
- package/lib/rules/getter-return.js +8 -6
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +43 -7
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/keyword-spacing.js +1 -1
- package/lib/rules/line-comment-position.js +3 -3
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-depth.js +2 -2
- package/lib/rules/max-len.js +1 -1
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-nested-callbacks.js +2 -2
- package/lib/rules/max-params.js +5 -4
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +3 -3
- package/lib/rules/multiline-comment-style.js +1 -1
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-async-promise-executor.js +33 -0
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constant-condition.js +2 -0
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +2 -2
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-magic-numbers.js +7 -3
- package/lib/rules/no-misleading-character-class.js +189 -0
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-globals.js +1 -1
- package/lib/rules/no-restricted-imports.js +1 -1
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -3
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +2 -11
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var.js +6 -6
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padded-blocks.js +6 -6
- package/lib/rules/padding-line-between-statements.js +2 -2
- package/lib/rules/prefer-const.js +2 -11
- package/lib/rules/prefer-object-spread.js +9 -3
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +239 -0
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/require-unicode-regexp.js +65 -0
- package/lib/rules/semi-spacing.js +3 -3
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +1 -1
- package/lib/rules/sort-keys.js +1 -1
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-unary-ops.js +2 -2
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/testers/rule-tester.js +7 -7
- package/lib/token-store/index.js +1 -1
- package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
- package/lib/{file-finder.js → util/file-finder.js} +2 -2
- package/lib/util/fix-tracker.js +1 -1
- package/lib/util/{glob-util.js → glob-utils.js} +4 -4
- package/lib/util/lint-result-cache.js +2 -2
- package/lib/util/naming.js +2 -2
- package/lib/util/node-event-generator.js +3 -3
- package/lib/util/{npm-util.js → npm-utils.js} +0 -0
- package/lib/util/{path-util.js → path-utils.js} +1 -1
- package/lib/util/source-code-fixer.js +1 -1
- package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
- package/lib/util/source-code.js +1 -1
- package/lib/util/unicode/index.js +11 -0
- package/lib/util/unicode/is-combining-character.js +13 -0
- package/lib/util/unicode/is-emoji-modifier.js +13 -0
- package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
- package/lib/util/unicode/is-surrogate-pair.js +14 -0
- package/package.json +13 -14
- package/lib/rules/.eslintrc.yml +0 -4
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,66 @@
|
|
1
|
+
v5.6.0 - September 14, 2018
|
2
|
+
|
3
|
+
* c5b688e Update: Added generators option to func-names (fixes #9511) (#10697) (Oscar Barrett)
|
4
|
+
* 7da36d5 Fix: respect generator function expressions in no-constant-condition (#10827) (Julian Rosse)
|
5
|
+
* 0a65844 Chore: quote enable avoidEscape option in eslint-config-eslint (#10626) (薛定谔的猫)
|
6
|
+
* 32f41bd Chore: Add configuration wrapper markdown for the bug report template (#10669) (Iulian Onofrei)
|
7
|
+
|
8
|
+
v5.5.0 - August 31, 2018
|
9
|
+
|
10
|
+
* 6e110e6 Fix: camelcase duplicate warning bug (fixes #10801) (#10802) (Julian Rosse)
|
11
|
+
* 5103ee7 Docs: Add Brackets integration (#10813) (Jan Pilzer)
|
12
|
+
* b61d2cd Update: max-params to only highlight function header (#10815) (Ian Obermiller)
|
13
|
+
* 2b2f11d Upgrade: babel-code-frame to version 7 (#10808) (Rouven Weßling)
|
14
|
+
* 2824d43 Docs: fix comment placement in a code example (#10799) (Vse Mozhet Byt)
|
15
|
+
* 10690b7 Upgrade: devdeps and deps to latest (#10622) (薛定谔的猫)
|
16
|
+
* 80c8598 Docs: gitignore syntax updates (fixes #8139) (#10776) (Gustavo Santana)
|
17
|
+
* cb946af Chore: use meta.messages in some rules (1/4) (#10764) (薛定谔的猫)
|
18
|
+
|
19
|
+
v5.4.0 - August 17, 2018
|
20
|
+
|
21
|
+
* a70909f Docs: Add jscs-dev.github.io links (#10771) (Gustavo Santana)
|
22
|
+
* 034690f Fix: no-invalid-meta crashes for non Object values (fixes #10750) (#10753) (Sandeep Kumar Ranka)
|
23
|
+
* 11a462d Docs: Broken jscs.info URLs (fixes #10732) (#10770) (Gustavo Santana)
|
24
|
+
* 985567d Chore: rm unused dep string.prototype.matchall (#10756) (薛定谔的猫)
|
25
|
+
* f3d8454 Update: Improve no-extra-parens error message (#10748) (Timo Tijhof)
|
26
|
+
* 562a03f Fix: consistent-docs-url crashes if meta.docs is empty (fixes #10722) (#10749) (Sandeep Kumar Ranka)
|
27
|
+
* 6492233 Chore: enable no-prototype-builtins in codebase (fixes #10660) (#10664) (薛定谔的猫)
|
28
|
+
* 137140f Chore: use eslintrc overrides (#10677) (薛定谔的猫)
|
29
|
+
|
30
|
+
v5.3.0 - August 3, 2018
|
31
|
+
|
32
|
+
* dd6cb19 Docs: Updated no-return-await Rule Documentation (fixes #9695) (#10699) (Marla Foreman)
|
33
|
+
* 6009239 Chore: rename utils for consistency (#10727) (薛定谔的猫)
|
34
|
+
* 6eb972c New: require-unicode-regexp rule (fixes #9961) (#10698) (Toru Nagashima)
|
35
|
+
* 5c5d64d Fix: ignored-paths for Windows path (fixes #10687) (#10691) (Toru Nagashima)
|
36
|
+
* 5f6a765 Build: ensure URL fragments remain in documentation links (fixes #10717) (#10720) (Teddy Katz)
|
37
|
+
* 863aa78 Docs: add another example for when not to use no-await-in-loop (#10714) (Valeri Karpov)
|
38
|
+
* 6e78b7d Docs: remove links to terminated jscs.info domain (#10706) (Piotr Kuczynski)
|
39
|
+
* d56c39d Fix: ESLint cache no longer stops autofix (fixes #10679) (#10694) (Kevin Partington)
|
40
|
+
* 2cc3240 New: add no-misleading-character-class (fixes #10049) (#10511) (Toru Nagashima)
|
41
|
+
* 877f4b8 Fix: The "../.." folder is always ignored (fixes #10675) (#10682) (Sridhar)
|
42
|
+
* 5984820 Chore: Move lib/file-finder.js to lib/util/ (refs #10559) (#10695) (Kevin Partington)
|
43
|
+
* e37a593 Update: Fix incorrect default value for position (#10670) (Iulian Onofrei)
|
44
|
+
* 8084bfc Docs: change when not to use object spread (#10621) (Benny Powers)
|
45
|
+
* 7f496e2 Chore: Update require path for ast-utils (#10693) (Kevin Partington)
|
46
|
+
* 648a33a Chore: reorganize code structure of utilities (refs #10599) (#10680) (薛定谔的猫)
|
47
|
+
* f026fe1 Update: Fix 'function' in padding-line-between-statements (fixes #10487) (#10676) (Kevin Partington)
|
48
|
+
* c2bb8bb Docs: Remove superfluous object option sample code (#10652) (Iulian Onofrei)
|
49
|
+
* d34a13b Docs: add subheader in configuring/configuring-rules (#10686) (薛定谔的猫)
|
50
|
+
* d8aea28 Chore: rm unnecessary plugin in eslint-config-eslint (#10685) (薛定谔的猫)
|
51
|
+
* 9e76be7 Update: indent comments w/ nearby code if no blank lines (fixes #9733) (#10640) (Kevin Partington)
|
52
|
+
* 9e93d46 New: add no-async-promise-executor rule (fixes #10217) (#10661) (Teddy Katz)
|
53
|
+
* 5a2538c New: require-atomic-updates rule (fixes #10405) (#10655) (Teddy Katz)
|
54
|
+
* 8b83d2b Fix: always resolve default ignore patterns from CWD (fixes #9227) (#10638) (Teddy Katz)
|
55
|
+
* acb6658 Fix: ESLint crash with prefer-object-spread (fixes #10646) (#10649) (薛定谔的猫)
|
56
|
+
* 99fb7d3 Docs: fix misleading no-prototype-builtins description (#10666) (薛定谔的猫)
|
57
|
+
* 005b849 Docs: fix outdated description of `baseConfig` option (#10657) (Teddy Katz)
|
58
|
+
* 15a77c4 Docs: fix broken links (fixes eslint/eslint-jp#6) (#10658) (Toru Nagashima)
|
59
|
+
* 87cd344 Docs: Make marking a default option consistent with other rules (#10650) (Iulian Onofrei)
|
60
|
+
* 0cb5e3e Chore: Replace some function application with spread operators (#10645) (Kevin Partington)
|
61
|
+
* b6daf0e Docs: Remove superfluous section from no-unsafe-negation (#10648) (Iulian Onofrei)
|
62
|
+
* e1a3cac Chore: rm deprecated experimentalObjectRestSpread option in tests (#10647) (薛定谔的猫)
|
63
|
+
|
1
64
|
v5.2.0 - July 20, 2018
|
2
65
|
|
3
66
|
* 81283d0 Update: Cache files that failed linting (fixes #9948) (#10571) (Kevin Partington)
|
@@ -83,6 +83,7 @@ module.exports = {
|
|
83
83
|
"newline-per-chained-call": "off",
|
84
84
|
"no-alert": "off",
|
85
85
|
"no-array-constructor": "off",
|
86
|
+
"no-async-promise-executor": "off",
|
86
87
|
"no-await-in-loop": "off",
|
87
88
|
"no-bitwise": "off",
|
88
89
|
"no-buffer-constructor": "off",
|
@@ -139,6 +140,7 @@ module.exports = {
|
|
139
140
|
"no-lonely-if": "off",
|
140
141
|
"no-loop-func": "off",
|
141
142
|
"no-magic-numbers": "off",
|
143
|
+
"no-misleading-character-class": "off",
|
142
144
|
"no-mixed-operators": "off",
|
143
145
|
"no-mixed-requires": "off",
|
144
146
|
"no-mixed-spaces-and-tabs": "error",
|
@@ -240,8 +242,10 @@ module.exports = {
|
|
240
242
|
"quote-props": "off",
|
241
243
|
quotes: "off",
|
242
244
|
radix: "off",
|
245
|
+
"require-atomic-updates": "off",
|
243
246
|
"require-await": "off",
|
244
247
|
"require-jsdoc": "off",
|
248
|
+
"require-unicode-regexp": "off",
|
245
249
|
"require-yield": "error",
|
246
250
|
"rest-spread-spacing": "off",
|
247
251
|
semi: "off",
|
package/lib/cli-engine.js
CHANGED
@@ -22,7 +22,7 @@ const fs = require("fs"),
|
|
22
22
|
IgnoredPaths = require("./ignored-paths"),
|
23
23
|
Config = require("./config"),
|
24
24
|
LintResultCache = require("./util/lint-result-cache"),
|
25
|
-
|
25
|
+
globUtils = require("./util/glob-utils"),
|
26
26
|
validator = require("./config/config-validator"),
|
27
27
|
hash = require("./util/hash"),
|
28
28
|
ModuleResolver = require("./util/module-resolver"),
|
@@ -30,7 +30,6 @@ const fs = require("fs"),
|
|
30
30
|
pkg = require("../package.json");
|
31
31
|
|
32
32
|
const debug = require("debug")("eslint:cli-engine");
|
33
|
-
|
34
33
|
const resolver = new ModuleResolver();
|
35
34
|
|
36
35
|
//------------------------------------------------------------------------------
|
@@ -41,7 +40,7 @@ const resolver = new ModuleResolver();
|
|
41
40
|
* The options to configure a CLI engine with.
|
42
41
|
* @typedef {Object} CLIEngineOptions
|
43
42
|
* @property {boolean} allowInlineConfig Enable or disable inline configuration comments.
|
44
|
-
* @property {
|
43
|
+
* @property {Object} baseConfig Base config object, extended by all configs used with this CLIEngine instance
|
45
44
|
* @property {boolean} cache Enable result caching.
|
46
45
|
* @property {string} cacheLocation The cache file to use instead of .eslintcache.
|
47
46
|
* @property {string} configFile The configuration file to use.
|
@@ -469,7 +468,7 @@ class CLIEngine {
|
|
469
468
|
* @returns {void}
|
470
469
|
*/
|
471
470
|
static outputFixes(report) {
|
472
|
-
report.results.filter(result =>
|
471
|
+
report.results.filter(result => Object.prototype.hasOwnProperty.call(result, "output")).forEach(result => {
|
473
472
|
fs.writeFileSync(result.filePath, result.output);
|
474
473
|
});
|
475
474
|
}
|
@@ -492,7 +491,7 @@ class CLIEngine {
|
|
492
491
|
* @returns {string[]} The equivalent glob patterns.
|
493
492
|
*/
|
494
493
|
resolveFileGlobPatterns(patterns) {
|
495
|
-
return
|
494
|
+
return globUtils.resolveFileGlobPatterns(patterns.filter(Boolean), this.options);
|
496
495
|
}
|
497
496
|
|
498
497
|
/**
|
@@ -511,25 +510,25 @@ class CLIEngine {
|
|
511
510
|
}
|
512
511
|
|
513
512
|
const startTime = Date.now();
|
514
|
-
const fileList =
|
513
|
+
const fileList = globUtils.listFilesToProcess(patterns, options);
|
515
514
|
const results = fileList.map(fileInfo => {
|
516
515
|
if (fileInfo.ignored) {
|
517
516
|
return createIgnoreResult(fileInfo.filename, options.cwd);
|
518
517
|
}
|
519
518
|
|
520
519
|
if (options.cache) {
|
521
|
-
|
522
|
-
/*
|
523
|
-
* get the descriptor for this file
|
524
|
-
* with the metadata and the flag that determines if
|
525
|
-
* the file has changed
|
526
|
-
*/
|
527
520
|
const cachedLintResults = lintResultCache.getCachedLintResults(fileInfo.filename);
|
528
521
|
|
529
522
|
if (cachedLintResults) {
|
530
|
-
|
523
|
+
const resultHadMessages = cachedLintResults.messages && cachedLintResults.messages.length;
|
524
|
+
|
525
|
+
if (resultHadMessages && options.fix) {
|
526
|
+
debug(`Reprocessing cached file to allow autofix: ${fileInfo.filename}`);
|
527
|
+
} else {
|
528
|
+
debug(`Skipping file since it hasn't changed: ${fileInfo.filename}`);
|
531
529
|
|
532
|
-
|
530
|
+
return cachedLintResults;
|
531
|
+
}
|
533
532
|
}
|
534
533
|
}
|
535
534
|
|
@@ -14,7 +14,7 @@ const assert = require("assert"),
|
|
14
14
|
CodePathSegment = require("./code-path-segment"),
|
15
15
|
IdGenerator = require("./id-generator"),
|
16
16
|
debug = require("./debug-helpers"),
|
17
|
-
astUtils = require("../ast-utils");
|
17
|
+
astUtils = require("../util/ast-utils");
|
18
18
|
|
19
19
|
//------------------------------------------------------------------------------
|
20
20
|
// Helpers
|
@@ -16,9 +16,9 @@ const util = require("util"),
|
|
16
16
|
autoconfig = require("./autoconfig.js"),
|
17
17
|
ConfigFile = require("./config-file"),
|
18
18
|
ConfigOps = require("./config-ops"),
|
19
|
-
getSourceCodeOfFiles = require("../util/source-code-
|
19
|
+
getSourceCodeOfFiles = require("../util/source-code-utils").getSourceCodeOfFiles,
|
20
20
|
ModuleResolver = require("../util/module-resolver"),
|
21
|
-
|
21
|
+
npmUtils = require("../util/npm-utils"),
|
22
22
|
recConfig = require("../../conf/eslint-recommended"),
|
23
23
|
log = require("../util/logging");
|
24
24
|
|
@@ -61,7 +61,7 @@ function writeFile(config, format) {
|
|
61
61
|
/**
|
62
62
|
* Get the peer dependencies of the given module.
|
63
63
|
* This adds the gotten value to cache at the first time, then reuses it.
|
64
|
-
* In a process, this function is called twice, but `
|
64
|
+
* In a process, this function is called twice, but `npmUtils.fetchPeerDependencies` needs to access network which is relatively slow.
|
65
65
|
* @param {string} moduleName The module name to get.
|
66
66
|
* @returns {Object} The peer dependencies of the given module.
|
67
67
|
* This object is the object of `peerDependencies` field of `package.json`.
|
@@ -73,7 +73,7 @@ function getPeerDependencies(moduleName) {
|
|
73
73
|
if (!result) {
|
74
74
|
log.info(`Checking peerDependencies of ${moduleName}`);
|
75
75
|
|
76
|
-
result =
|
76
|
+
result = npmUtils.fetchPeerDependencies(moduleName);
|
77
77
|
getPeerDependencies.cache.set(moduleName, result);
|
78
78
|
}
|
79
79
|
|
@@ -109,7 +109,7 @@ function getModulesList(config, installESLint) {
|
|
109
109
|
if (installESLint === false) {
|
110
110
|
delete modules.eslint;
|
111
111
|
} else {
|
112
|
-
const installStatus =
|
112
|
+
const installStatus = npmUtils.checkDevDeps(["eslint"]);
|
113
113
|
|
114
114
|
// Mark to show messages if it's new installation of eslint.
|
115
115
|
if (installStatus.eslint === false) {
|
@@ -373,7 +373,7 @@ function hasESLintVersionConflict(answers) {
|
|
373
373
|
*/
|
374
374
|
function installModules(modules) {
|
375
375
|
log.info(`Installing ${modules.join(", ")}`);
|
376
|
-
|
376
|
+
npmUtils.installSyncSaveDev(modules);
|
377
377
|
}
|
378
378
|
|
379
379
|
/* istanbul ignore next: no need to test inquirer */
|
@@ -438,7 +438,7 @@ function promptUser() {
|
|
438
438
|
{ name: "Google (https://github.com/google/eslint-config-google)", value: "google" }
|
439
439
|
],
|
440
440
|
when(answers) {
|
441
|
-
answers.packageJsonExists =
|
441
|
+
answers.packageJsonExists = npmUtils.checkPackageJson();
|
442
442
|
return answers.source === "guide" && answers.packageJsonExists;
|
443
443
|
}
|
444
444
|
},
|
package/lib/config.js
CHANGED
@@ -15,7 +15,7 @@ const path = require("path"),
|
|
15
15
|
ConfigFile = require("./config/config-file"),
|
16
16
|
ConfigCache = require("./config/config-cache"),
|
17
17
|
Plugins = require("./config/plugins"),
|
18
|
-
FileFinder = require("./file-finder"),
|
18
|
+
FileFinder = require("./util/file-finder"),
|
19
19
|
isResolvable = require("is-resolvable");
|
20
20
|
|
21
21
|
const debug = require("debug")("eslint:config");
|
@@ -5,7 +5,7 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const chalk = require("chalk");
|
8
|
-
const
|
8
|
+
const { codeFrameColumns } = require("@babel/code-frame");
|
9
9
|
const path = require("path");
|
10
10
|
|
11
11
|
//------------------------------------------------------------------------------
|
@@ -63,7 +63,7 @@ function formatMessage(message, parentResult) {
|
|
63
63
|
|
64
64
|
if (sourceCode) {
|
65
65
|
result.push(
|
66
|
-
|
66
|
+
codeFrameColumns(sourceCode, { start: { line: message.line, column: message.column } }, { highlightCode: false })
|
67
67
|
);
|
68
68
|
}
|
69
69
|
|
package/lib/ignored-paths.js
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
const fs = require("fs"),
|
13
13
|
path = require("path"),
|
14
14
|
ignore = require("ignore"),
|
15
|
-
|
15
|
+
pathUtils = require("./util/path-utils");
|
16
16
|
|
17
17
|
const debug = require("debug")("eslint:ignored-paths");
|
18
18
|
|
@@ -79,6 +79,40 @@ function mergeDefaultOptions(options) {
|
|
79
79
|
return Object.assign({}, DEFAULT_OPTIONS, options);
|
80
80
|
}
|
81
81
|
|
82
|
+
/* eslint-disable valid-jsdoc */
|
83
|
+
/**
|
84
|
+
* Normalize the path separators in a given string.
|
85
|
+
* On Windows environment, this replaces `\` by `/`.
|
86
|
+
* Otherwrise, this does nothing.
|
87
|
+
* @param {string} str The path string to normalize.
|
88
|
+
* @returns {string} The normalized path.
|
89
|
+
*/
|
90
|
+
const normalizePathSeps = path.sep === "/"
|
91
|
+
? (str => str)
|
92
|
+
: ((seps, str) => str.replace(seps, "/")).bind(null, new RegExp(`\\${path.sep}`, "g"));
|
93
|
+
/* eslint-enable valid-jsdoc */
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Converts a glob pattern to a new glob pattern relative to a different directory
|
97
|
+
* @param {string} globPattern The glob pattern, relative the the old base directory
|
98
|
+
* @param {string} relativePathToOldBaseDir A relative path from the new base directory to the old one
|
99
|
+
* @returns {string} A glob pattern relative to the new base directory
|
100
|
+
*/
|
101
|
+
function relativize(globPattern, relativePathToOldBaseDir) {
|
102
|
+
if (relativePathToOldBaseDir === "") {
|
103
|
+
return globPattern;
|
104
|
+
}
|
105
|
+
|
106
|
+
const prefix = globPattern.startsWith("!") ? "!" : "";
|
107
|
+
const globWithoutPrefix = globPattern.replace(/^!/, "");
|
108
|
+
|
109
|
+
if (globWithoutPrefix.startsWith("/")) {
|
110
|
+
return `${prefix}/${normalizePathSeps(relativePathToOldBaseDir)}${globWithoutPrefix}`;
|
111
|
+
}
|
112
|
+
|
113
|
+
return globPattern;
|
114
|
+
}
|
115
|
+
|
82
116
|
//------------------------------------------------------------------------------
|
83
117
|
// Public Interface
|
84
118
|
//------------------------------------------------------------------------------
|
@@ -96,41 +130,36 @@ class IgnoredPaths {
|
|
96
130
|
|
97
131
|
this.cache = {};
|
98
132
|
|
99
|
-
/**
|
100
|
-
* add pattern to node-ignore instance
|
101
|
-
* @param {Object} ig, instance of node-ignore
|
102
|
-
* @param {string} pattern, pattern do add to ig
|
103
|
-
* @returns {array} raw ignore rules
|
104
|
-
*/
|
105
|
-
function addPattern(ig, pattern) {
|
106
|
-
return ig.addPattern(pattern);
|
107
|
-
}
|
108
|
-
|
109
133
|
this.defaultPatterns = [].concat(DEFAULT_IGNORE_DIRS, options.patterns || []);
|
110
|
-
|
134
|
+
|
135
|
+
this.ignoreFileDir = options.ignore !== false && options.ignorePath
|
136
|
+
? path.dirname(path.resolve(options.cwd, options.ignorePath))
|
137
|
+
: options.cwd;
|
138
|
+
this.options = options;
|
139
|
+
this._baseDir = null;
|
111
140
|
|
112
141
|
this.ig = {
|
113
142
|
custom: ignore(),
|
114
143
|
default: ignore()
|
115
144
|
};
|
116
145
|
|
117
|
-
|
118
|
-
* Add a way to keep track of ignored files. This was present in node-ignore
|
119
|
-
* 2.x, but dropped for now as of 3.0.10.
|
120
|
-
*/
|
121
|
-
this.ig.custom.ignoreFiles = [];
|
122
|
-
this.ig.default.ignoreFiles = [];
|
123
|
-
|
146
|
+
this.defaultPatterns.forEach(pattern => this.addPatternRelativeToCwd(this.ig.default, pattern));
|
124
147
|
if (options.dotfiles !== true) {
|
125
148
|
|
126
149
|
/*
|
127
150
|
* ignore files beginning with a dot, but not files in a parent or
|
128
151
|
* ancestor directory (which in relative format will begin with `../`).
|
129
152
|
*/
|
130
|
-
|
153
|
+
this.addPatternRelativeToCwd(this.ig.default, ".*");
|
154
|
+
this.addPatternRelativeToCwd(this.ig.default, "!../");
|
131
155
|
}
|
132
156
|
|
133
|
-
|
157
|
+
/*
|
158
|
+
* Add a way to keep track of ignored files. This was present in node-ignore
|
159
|
+
* 2.x, but dropped for now as of 3.0.10.
|
160
|
+
*/
|
161
|
+
this.ig.custom.ignoreFiles = [];
|
162
|
+
this.ig.default.ignoreFiles = [];
|
134
163
|
|
135
164
|
if (options.ignore !== false) {
|
136
165
|
let ignorePath;
|
@@ -154,13 +183,11 @@ class IgnoredPaths {
|
|
154
183
|
debug(`Loaded ignore file ${ignorePath}`);
|
155
184
|
} catch (e) {
|
156
185
|
debug("Could not find ignore file in cwd");
|
157
|
-
this.options = options;
|
158
186
|
}
|
159
187
|
}
|
160
188
|
|
161
189
|
if (ignorePath) {
|
162
190
|
debug(`Adding ${ignorePath}`);
|
163
|
-
this.baseDir = path.dirname(path.resolve(options.cwd, ignorePath));
|
164
191
|
this.addIgnoreFile(this.ig.custom, ignorePath);
|
165
192
|
this.addIgnoreFile(this.ig.default, ignorePath);
|
166
193
|
} else {
|
@@ -187,8 +214,8 @@ class IgnoredPaths {
|
|
187
214
|
if (packageJSONOptions.eslintIgnore) {
|
188
215
|
if (Array.isArray(packageJSONOptions.eslintIgnore)) {
|
189
216
|
packageJSONOptions.eslintIgnore.forEach(pattern => {
|
190
|
-
|
191
|
-
|
217
|
+
this.addPatternRelativeToIgnoreFile(this.ig.custom, pattern);
|
218
|
+
this.addPatternRelativeToIgnoreFile(this.ig.default, pattern);
|
192
219
|
});
|
193
220
|
} else {
|
194
221
|
throw new TypeError("Package.json eslintIgnore property requires an array of paths");
|
@@ -202,12 +229,68 @@ class IgnoredPaths {
|
|
202
229
|
}
|
203
230
|
|
204
231
|
if (options.ignorePattern) {
|
205
|
-
|
206
|
-
|
232
|
+
this.addPatternRelativeToCwd(this.ig.custom, options.ignorePattern);
|
233
|
+
this.addPatternRelativeToCwd(this.ig.default, options.ignorePattern);
|
207
234
|
}
|
208
235
|
}
|
236
|
+
}
|
209
237
|
|
210
|
-
|
238
|
+
/*
|
239
|
+
* If `ignoreFileDir` is a subdirectory of `cwd`, all paths will be normalized to be relative to `cwd`.
|
240
|
+
* Otherwise, all paths will be normalized to be relative to `ignoreFileDir`.
|
241
|
+
* This ensures that the final normalized ignore rule will not contain `..`, which is forbidden in
|
242
|
+
* ignore rules.
|
243
|
+
*/
|
244
|
+
|
245
|
+
addPatternRelativeToCwd(ig, pattern) {
|
246
|
+
const baseDir = this.getBaseDir();
|
247
|
+
const cookedPattern = baseDir === this.options.cwd
|
248
|
+
? pattern
|
249
|
+
: relativize(pattern, path.relative(baseDir, this.options.cwd));
|
250
|
+
|
251
|
+
ig.addPattern(cookedPattern);
|
252
|
+
debug("addPatternRelativeToCwd:\n original = %j\n cooked = %j", pattern, cookedPattern);
|
253
|
+
}
|
254
|
+
|
255
|
+
addPatternRelativeToIgnoreFile(ig, pattern) {
|
256
|
+
const baseDir = this.getBaseDir();
|
257
|
+
const cookedPattern = baseDir === this.ignoreFileDir
|
258
|
+
? pattern
|
259
|
+
: relativize(pattern, path.relative(baseDir, this.ignoreFileDir));
|
260
|
+
|
261
|
+
ig.addPattern(cookedPattern);
|
262
|
+
debug("addPatternRelativeToIgnoreFile:\n original = %j\n cooked = %j", pattern, cookedPattern);
|
263
|
+
}
|
264
|
+
|
265
|
+
// Detect the common ancestor
|
266
|
+
getBaseDir() {
|
267
|
+
if (!this._baseDir) {
|
268
|
+
const a = path.resolve(this.options.cwd);
|
269
|
+
const b = path.resolve(this.ignoreFileDir);
|
270
|
+
let lastSepPos = 0;
|
271
|
+
|
272
|
+
// Set the shorter one (it's the common ancestor if one includes the other).
|
273
|
+
this._baseDir = a.length < b.length ? a : b;
|
274
|
+
|
275
|
+
// Set the common ancestor.
|
276
|
+
for (let i = 0; i < a.length && i < b.length; ++i) {
|
277
|
+
if (a[i] !== b[i]) {
|
278
|
+
this._baseDir = a.slice(0, lastSepPos);
|
279
|
+
break;
|
280
|
+
}
|
281
|
+
if (a[i] === path.sep) {
|
282
|
+
lastSepPos = i;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
// If it's only Windows drive letter, it needs \
|
287
|
+
if (/^[A-Z]:$/.test(this._baseDir)) {
|
288
|
+
this._baseDir += "\\";
|
289
|
+
}
|
290
|
+
|
291
|
+
debug("baseDir = %j", this._baseDir);
|
292
|
+
}
|
293
|
+
return this._baseDir;
|
211
294
|
}
|
212
295
|
|
213
296
|
/**
|
@@ -217,7 +300,7 @@ class IgnoredPaths {
|
|
217
300
|
*/
|
218
301
|
readIgnoreFile(filePath) {
|
219
302
|
if (typeof this.cache[filePath] === "undefined") {
|
220
|
-
this.cache[filePath] = fs.readFileSync(filePath, "utf8");
|
303
|
+
this.cache[filePath] = fs.readFileSync(filePath, "utf8").split(/\r?\n/g).filter(Boolean);
|
221
304
|
}
|
222
305
|
return this.cache[filePath];
|
223
306
|
}
|
@@ -226,11 +309,13 @@ class IgnoredPaths {
|
|
226
309
|
* add ignore file to node-ignore instance
|
227
310
|
* @param {Object} ig, instance of node-ignore
|
228
311
|
* @param {string} filePath, file to add to ig
|
229
|
-
* @returns {
|
312
|
+
* @returns {void}
|
230
313
|
*/
|
231
314
|
addIgnoreFile(ig, filePath) {
|
232
315
|
ig.ignoreFiles.push(filePath);
|
233
|
-
|
316
|
+
this
|
317
|
+
.readIgnoreFile(filePath)
|
318
|
+
.forEach(ignoreRule => this.addPatternRelativeToIgnoreFile(ig, ignoreRule));
|
234
319
|
}
|
235
320
|
|
236
321
|
/**
|
@@ -243,7 +328,7 @@ class IgnoredPaths {
|
|
243
328
|
|
244
329
|
let result = false;
|
245
330
|
const absolutePath = path.resolve(this.options.cwd, filepath);
|
246
|
-
const relativePath =
|
331
|
+
const relativePath = pathUtils.getRelativePath(absolutePath, this.getBaseDir());
|
247
332
|
|
248
333
|
if (typeof category === "undefined") {
|
249
334
|
result = (this.ig.default.filter([relativePath]).length === 0) ||
|
@@ -251,6 +336,9 @@ class IgnoredPaths {
|
|
251
336
|
} else {
|
252
337
|
result = (this.ig[category].filter([relativePath]).length === 0);
|
253
338
|
}
|
339
|
+
debug("contains:");
|
340
|
+
debug(" target = %j", filepath);
|
341
|
+
debug(" result = %j", result);
|
254
342
|
|
255
343
|
return result;
|
256
344
|
|
@@ -261,13 +349,15 @@ class IgnoredPaths {
|
|
261
349
|
* @returns {function()} method to check whether a folder should be ignored by glob.
|
262
350
|
*/
|
263
351
|
getIgnoredFoldersGlobChecker() {
|
352
|
+
const baseDir = this.getBaseDir();
|
353
|
+
const ig = ignore();
|
264
354
|
|
265
|
-
|
355
|
+
DEFAULT_IGNORE_DIRS.forEach(ignoreDir => this.addPatternRelativeToCwd(ig, ignoreDir));
|
266
356
|
|
267
357
|
if (this.options.dotfiles !== true) {
|
268
358
|
|
269
359
|
// Ignore hidden folders. (This cannot be ".*", or else it's not possible to unignore hidden files)
|
270
|
-
ig.add([".*/*", "
|
360
|
+
ig.add([".*/*", "!../*"]);
|
271
361
|
}
|
272
362
|
|
273
363
|
if (this.options.ignore) {
|
@@ -276,10 +366,8 @@ class IgnoredPaths {
|
|
276
366
|
|
277
367
|
const filter = ig.createFilter();
|
278
368
|
|
279
|
-
const base = this.baseDir;
|
280
|
-
|
281
369
|
return function(absolutePath) {
|
282
|
-
const relative =
|
370
|
+
const relative = pathUtils.getRelativePath(absolutePath, baseDir);
|
283
371
|
|
284
372
|
if (!relative) {
|
285
373
|
return false;
|
package/lib/linter.js
CHANGED
@@ -25,7 +25,7 @@ const eslintScope = require("eslint-scope"),
|
|
25
25
|
createReportTranslator = require("./report-translator"),
|
26
26
|
Rules = require("./rules"),
|
27
27
|
timing = require("./util/timing"),
|
28
|
-
astUtils = require("./ast-utils"),
|
28
|
+
astUtils = require("./util/ast-utils"),
|
29
29
|
pkg = require("../package.json"),
|
30
30
|
SourceCodeFixer = require("./util/source-code-fixer");
|
31
31
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
package/lib/rules/brace-style.js
CHANGED
package/lib/rules/camelcase.js
CHANGED
@@ -145,7 +145,7 @@ module.exports = {
|
|
145
145
|
const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
|
146
146
|
|
147
147
|
// prevent checking righthand side of destructured object
|
148
|
-
if (
|
148
|
+
if (node.parent.key === node && node.parent.value !== node) {
|
149
149
|
return;
|
150
150
|
}
|
151
151
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
const LETTER_PATTERN = require("../util/patterns/letters");
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|