eslint 6.5.0 → 6.7.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 +115 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +51 -30
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +15 -7
- package/lib/rules/no-useless-return.js +8 -15
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +62 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -40,8 +40,8 @@ const getGlobParent = require("glob-parent");
|
|
40
40
|
const isGlob = require("is-glob");
|
41
41
|
const { escapeRegExp } = require("lodash");
|
42
42
|
const { Minimatch } = require("minimatch");
|
43
|
+
const { IgnorePattern } = require("./config-array");
|
43
44
|
const { CascadingConfigArrayFactory } = require("./cascading-config-array-factory");
|
44
|
-
const { IgnoredPaths } = require("./ignored-paths");
|
45
45
|
const debug = require("debug")("eslint:file-enumerator");
|
46
46
|
|
47
47
|
//------------------------------------------------------------------------------
|
@@ -64,7 +64,6 @@ const IGNORED = 2;
|
|
64
64
|
* @property {string[]} [extensions] The extensions to match files for directory patterns.
|
65
65
|
* @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
|
66
66
|
* @property {boolean} [ignore] The flag to check ignored files.
|
67
|
-
* @property {IgnoredPaths} [ignoredPaths] The ignored paths.
|
68
67
|
* @property {string[]} [rulePaths] The value of `--rulesdir` option.
|
69
68
|
*/
|
70
69
|
|
@@ -92,8 +91,7 @@ const IGNORED = 2;
|
|
92
91
|
* @property {RegExp} extensionRegExp The RegExp to test if a string ends with specific file extensions.
|
93
92
|
* @property {boolean} globInputPaths Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
|
94
93
|
* @property {boolean} ignoreFlag The flag to check ignored files.
|
95
|
-
* @property {
|
96
|
-
* @property {IgnoredPaths} ignoredPaths The ignored paths.
|
94
|
+
* @property {(filePath:string, dot:boolean) => boolean} defaultIgnores The default predicate function to ignore files.
|
97
95
|
*/
|
98
96
|
|
99
97
|
/** @type {WeakMap<FileEnumerator, FileEnumeratorInternalSlots>} */
|
@@ -149,9 +147,10 @@ function readdirSafeSync(directoryPath) {
|
|
149
147
|
*/
|
150
148
|
class NoFilesFoundError extends Error {
|
151
149
|
|
150
|
+
// eslint-disable-next-line jsdoc/require-description
|
152
151
|
/**
|
153
|
-
* @param {string} pattern
|
154
|
-
* @param {boolean} globDisabled
|
152
|
+
* @param {string} pattern The glob pattern which was not found.
|
153
|
+
* @param {boolean} globDisabled If `true` then the pattern was a glob pattern, but glob was disabled.
|
155
154
|
*/
|
156
155
|
constructor(pattern, globDisabled) {
|
157
156
|
super(`No files matching '${pattern}' were found${globDisabled ? " (glob was disabled)" : ""}.`);
|
@@ -165,8 +164,9 @@ class NoFilesFoundError extends Error {
|
|
165
164
|
*/
|
166
165
|
class AllFilesIgnoredError extends Error {
|
167
166
|
|
167
|
+
// eslint-disable-next-line jsdoc/require-description
|
168
168
|
/**
|
169
|
-
* @param {string} pattern
|
169
|
+
* @param {string} pattern The glob pattern which was not found.
|
170
170
|
*/
|
171
171
|
constructor(pattern) {
|
172
172
|
super(`All files matched by '${pattern}' are ignored.`);
|
@@ -190,12 +190,12 @@ class FileEnumerator {
|
|
190
190
|
configArrayFactory = new CascadingConfigArrayFactory({ cwd }),
|
191
191
|
extensions = [".js"],
|
192
192
|
globInputPaths = true,
|
193
|
-
ignore = true
|
194
|
-
ignoredPaths = new IgnoredPaths({ cwd, ignore })
|
193
|
+
ignore = true
|
195
194
|
} = {}) {
|
196
195
|
internalSlotsMap.set(this, {
|
197
196
|
configArrayFactory,
|
198
197
|
cwd,
|
198
|
+
defaultIgnores: IgnorePattern.createDefaultIgnore(cwd),
|
199
199
|
extensionRegExp: new RegExp(
|
200
200
|
`.\\.(?:${extensions
|
201
201
|
.map(ext => escapeRegExp(
|
@@ -208,12 +208,7 @@ class FileEnumerator {
|
|
208
208
|
"u"
|
209
209
|
),
|
210
210
|
globInputPaths,
|
211
|
-
ignoreFlag: ignore
|
212
|
-
ignoredPaths,
|
213
|
-
ignoredPathsWithDotfiles: new IgnoredPaths({
|
214
|
-
...ignoredPaths.options,
|
215
|
-
dotfiles: true
|
216
|
-
})
|
211
|
+
ignoreFlag: ignore
|
217
212
|
});
|
218
213
|
}
|
219
214
|
|
@@ -319,7 +314,7 @@ class FileEnumerator {
|
|
319
314
|
|
320
315
|
const { configArrayFactory } = internalSlotsMap.get(this);
|
321
316
|
const config = configArrayFactory.getConfigArrayForFile(filePath);
|
322
|
-
const ignored = this._isIgnoredFile(filePath, { direct: true });
|
317
|
+
const ignored = this._isIgnoredFile(filePath, { config, direct: true });
|
323
318
|
const flag = ignored ? IGNORED : NONE;
|
324
319
|
|
325
320
|
return [{ config, filePath, flag }];
|
@@ -351,7 +346,7 @@ class FileEnumerator {
|
|
351
346
|
_iterateFilesWithGlob(pattern, dotfiles) {
|
352
347
|
debug(`Glob: ${pattern}`);
|
353
348
|
|
354
|
-
const directoryPath = getGlobParent(pattern);
|
349
|
+
const directoryPath = path.resolve(getGlobParent(pattern));
|
355
350
|
const globPart = pattern.slice(directoryPath.length + 1);
|
356
351
|
|
357
352
|
/*
|
@@ -397,9 +392,18 @@ class FileEnumerator {
|
|
397
392
|
// Check if the file is matched.
|
398
393
|
if (stat && stat.isFile()) {
|
399
394
|
if (!config) {
|
400
|
-
config = configArrayFactory.getConfigArrayForFile(
|
395
|
+
config = configArrayFactory.getConfigArrayForFile(
|
396
|
+
filePath,
|
397
|
+
|
398
|
+
/*
|
399
|
+
* We must ignore `ConfigurationNotFoundError` at this
|
400
|
+
* point because we don't know if target files exist in
|
401
|
+
* this directory.
|
402
|
+
*/
|
403
|
+
{ ignoreNotFoundError: true }
|
404
|
+
);
|
401
405
|
}
|
402
|
-
const ignored = this._isIgnoredFile(filePath, options);
|
406
|
+
const ignored = this._isIgnoredFile(filePath, { ...options, config });
|
403
407
|
const flag = ignored ? IGNORED_SILENTLY : NONE;
|
404
408
|
const matched = options.selector
|
405
409
|
|
@@ -411,7 +415,11 @@ class FileEnumerator {
|
|
411
415
|
|
412
416
|
if (matched) {
|
413
417
|
debug(`Yield: ${filename}${ignored ? " but ignored" : ""}`);
|
414
|
-
yield {
|
418
|
+
yield {
|
419
|
+
config: configArrayFactory.getConfigArrayForFile(filePath),
|
420
|
+
filePath,
|
421
|
+
flag
|
422
|
+
};
|
415
423
|
} else {
|
416
424
|
debug(`Didn't match: ${filename}`);
|
417
425
|
}
|
@@ -429,24 +437,37 @@ class FileEnumerator {
|
|
429
437
|
* Check if a given file should be ignored.
|
430
438
|
* @param {string} filePath The path to a file to check.
|
431
439
|
* @param {Object} options Options
|
440
|
+
* @param {ConfigArray} [options.config] The config for this file.
|
432
441
|
* @param {boolean} [options.dotfiles] If `true` then this is not ignore dot files by default.
|
433
442
|
* @param {boolean} [options.direct] If `true` then this is a direct specified file.
|
434
443
|
* @returns {boolean} `true` if the file should be ignored.
|
435
444
|
* @private
|
436
445
|
*/
|
437
|
-
_isIgnoredFile(filePath, {
|
446
|
+
_isIgnoredFile(filePath, {
|
447
|
+
config: providedConfig,
|
448
|
+
dotfiles = false,
|
449
|
+
direct = false
|
450
|
+
}) {
|
438
451
|
const {
|
439
|
-
|
440
|
-
|
441
|
-
|
452
|
+
configArrayFactory,
|
453
|
+
defaultIgnores,
|
454
|
+
ignoreFlag
|
442
455
|
} = internalSlotsMap.get(this);
|
443
|
-
const adoptedIgnoredPaths = dotfiles
|
444
|
-
? ignoredPathsWithDotfiles
|
445
|
-
: ignoredPaths;
|
446
456
|
|
447
|
-
|
448
|
-
|
449
|
-
|
457
|
+
if (ignoreFlag) {
|
458
|
+
const config =
|
459
|
+
providedConfig ||
|
460
|
+
configArrayFactory.getConfigArrayForFile(
|
461
|
+
filePath,
|
462
|
+
{ ignoreNotFoundError: true }
|
463
|
+
);
|
464
|
+
const ignores =
|
465
|
+
config.extractConfig(filePath).ignores || defaultIgnores;
|
466
|
+
|
467
|
+
return ignores(filePath, dotfiles);
|
468
|
+
}
|
469
|
+
|
470
|
+
return !direct && defaultIgnores(filePath, dotfiles);
|
450
471
|
}
|
451
472
|
}
|
452
473
|
|
@@ -96,6 +96,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
|
|
96
96
|
}).join("\n");
|
97
97
|
}
|
98
98
|
|
99
|
+
// eslint-disable-next-line jsdoc/require-description
|
99
100
|
/**
|
100
101
|
* @param {Array} results Test results.
|
101
102
|
* @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis.
|
package/lib/init/autoconfig.js
CHANGED
@@ -31,7 +31,6 @@ const MAX_CONFIG_COMBINATIONS = 17, // 16 combinations + 1 for severity only
|
|
31
31
|
|
32
32
|
/**
|
33
33
|
* Information about a rule configuration, in the context of a Registry.
|
34
|
-
*
|
35
34
|
* @typedef {Object} registryItem
|
36
35
|
* @param {ruleConfig} config A valid configuration for the rule
|
37
36
|
* @param {number} specificity The number of elements in the ruleConfig array
|
@@ -70,6 +69,7 @@ function makeRegistryItems(rulesConfig) {
|
|
70
69
|
*/
|
71
70
|
class Registry {
|
72
71
|
|
72
|
+
// eslint-disable-next-line jsdoc/require-description
|
73
73
|
/**
|
74
74
|
* @param {rulesConfig} [rulesConfig] Hash of rule names and arrays of possible configurations
|
75
75
|
*/
|
@@ -82,7 +82,6 @@ class Registry {
|
|
82
82
|
*
|
83
83
|
* It will set the registry's `rule` property to an object having rule names
|
84
84
|
* as keys and an array of registryItems as values.
|
85
|
-
*
|
86
85
|
* @returns {void}
|
87
86
|
*/
|
88
87
|
populateFromCoreRules() {
|
@@ -101,7 +100,6 @@ class Registry {
|
|
101
100
|
* configurations.
|
102
101
|
*
|
103
102
|
* The length of the returned array will be <= MAX_CONFIG_COMBINATIONS.
|
104
|
-
*
|
105
103
|
* @returns {Object[]} "rules" configurations to use for linting
|
106
104
|
*/
|
107
105
|
buildRuleSets() {
|
@@ -114,7 +112,6 @@ class Registry {
|
|
114
112
|
*
|
115
113
|
* This is broken out into its own function so that it doesn't need to be
|
116
114
|
* created inside of the while loop.
|
117
|
-
*
|
118
115
|
* @param {string} rule The ruleId to add.
|
119
116
|
* @returns {void}
|
120
117
|
*/
|
@@ -162,7 +159,6 @@ class Registry {
|
|
162
159
|
*
|
163
160
|
* Note: this also removes rule configurations which were not linted
|
164
161
|
* (meaning, they have an undefined errorCount).
|
165
|
-
*
|
166
162
|
* @returns {void}
|
167
163
|
*/
|
168
164
|
stripFailingConfigs() {
|
@@ -185,7 +181,6 @@ class Registry {
|
|
185
181
|
|
186
182
|
/**
|
187
183
|
* Removes rule configurations which were not included in a ruleSet
|
188
|
-
*
|
189
184
|
* @returns {void}
|
190
185
|
*/
|
191
186
|
stripExtraConfigs() {
|
@@ -204,7 +199,6 @@ class Registry {
|
|
204
199
|
* Creates a registry of rules which had no error-free configs.
|
205
200
|
* The new registry is intended to be analyzed to determine whether its rules
|
206
201
|
* should be disabled or set to warning.
|
207
|
-
*
|
208
202
|
* @returns {Registry} A registry of failing rules.
|
209
203
|
*/
|
210
204
|
getFailingRulesRegistry() {
|
@@ -225,7 +219,6 @@ class Registry {
|
|
225
219
|
/**
|
226
220
|
* Create an eslint config for any rules which only have one configuration
|
227
221
|
* in the registry.
|
228
|
-
*
|
229
222
|
* @returns {Object} An eslint config with rules section populated
|
230
223
|
*/
|
231
224
|
createConfig() {
|
@@ -243,7 +236,6 @@ class Registry {
|
|
243
236
|
|
244
237
|
/**
|
245
238
|
* Return a cloned registry containing only configs with a desired specificity
|
246
|
-
*
|
247
239
|
* @param {number} specificity Only keep configs with this specificity
|
248
240
|
* @returns {Registry} A registry of rules
|
249
241
|
*/
|
@@ -261,7 +253,6 @@ class Registry {
|
|
261
253
|
|
262
254
|
/**
|
263
255
|
* Lint SourceCodes against all configurations in the registry, and record results
|
264
|
-
*
|
265
256
|
* @param {Object[]} sourceCodes SourceCode objects for each filename
|
266
257
|
* @param {Object} config ESLint config object
|
267
258
|
* @param {progressCallback} [cb] Optional callback for reporting execution status
|
@@ -327,7 +318,6 @@ class Registry {
|
|
327
318
|
*
|
328
319
|
* This will return a new config with `"extends": "eslint:recommended"` and
|
329
320
|
* only the rules which have configurations different from the recommended config.
|
330
|
-
*
|
331
321
|
* @param {Object} config config object
|
332
322
|
* @returns {Object} config object using `"extends": "eslint:recommended"`
|
333
323
|
*/
|
package/lib/init/config-file.js
CHANGED
@@ -23,7 +23,6 @@ const debug = require("debug")("eslint:config-file");
|
|
23
23
|
* Determines sort order for object keys for json-stable-stringify
|
24
24
|
*
|
25
25
|
* see: https://github.com/samn/json-stable-stringify#cmp
|
26
|
-
*
|
27
26
|
* @param {Object} a The first comparison object ({key: akey, value: avalue})
|
28
27
|
* @param {Object} b The second comparison object ({key: bkey, value: bvalue})
|
29
28
|
* @returns {number} 1 or -1, used in stringify cmp method
|
@@ -147,7 +147,6 @@ function getModulesList(config, installESLint) {
|
|
147
147
|
*
|
148
148
|
* Note: This clones the config object and returns a new config to avoid mutating
|
149
149
|
* the original config parameter.
|
150
|
-
*
|
151
150
|
* @param {Object} answers answers received from inquirer
|
152
151
|
* @param {Object} config config object
|
153
152
|
* @returns {Object} config object with configured rules
|
@@ -292,6 +291,7 @@ function processAnswers(answers) {
|
|
292
291
|
jsx: true
|
293
292
|
};
|
294
293
|
config.plugins = ["react"];
|
294
|
+
config.extends.push("plugin:react/recommended");
|
295
295
|
} else if (answers.framework === "vue") {
|
296
296
|
config.plugins = ["vue"];
|
297
297
|
config.extends.push("plugin:vue/essential");
|
@@ -523,9 +523,9 @@ function promptUser() {
|
|
523
523
|
name: "styleguide",
|
524
524
|
message: "Which style guide do you want to follow?",
|
525
525
|
choices: [
|
526
|
-
{ name: "Airbnb
|
527
|
-
{ name: "Standard
|
528
|
-
{ name: "Google
|
526
|
+
{ name: "Airbnb: https://github.com/airbnb/javascript", value: "airbnb" },
|
527
|
+
{ name: "Standard: https://github.com/standard/standard", value: "standard" },
|
528
|
+
{ name: "Google: https://github.com/google/eslint-config-google", value: "google" }
|
529
529
|
],
|
530
530
|
when(answers) {
|
531
531
|
answers.packageJsonExists = npmUtils.checkPackageJson();
|
package/lib/init/config-rule.js
CHANGED
@@ -33,7 +33,6 @@ function explodeArray(xs) {
|
|
33
33
|
*
|
34
34
|
* For example:
|
35
35
|
* combineArrays([a, [b, c]], [x, y]); // -> [[a, x], [a, y], [b, c, x], [b, c, y]]
|
36
|
-
*
|
37
36
|
* @param {Array} arr1 The first array to combine.
|
38
37
|
* @param {Array} arr2 The second array to combine.
|
39
38
|
* @returns {Array} A mixture of the elements of the first and second arrays.
|
@@ -71,7 +70,6 @@ function combineArrays(arr1, arr2) {
|
|
71
70
|
* [{before: true}, {before: false}],
|
72
71
|
* [{after: true}, {after: false}]
|
73
72
|
* ]
|
74
|
-
*
|
75
73
|
* @param {Object[]} objects Array of objects, each with one property/value pair
|
76
74
|
* @returns {Array[]} Array of arrays of objects grouped by property
|
77
75
|
*/
|
@@ -98,7 +96,6 @@ function groupByProperty(objects) {
|
|
98
96
|
* element in the array is the severity, and is the only required element.
|
99
97
|
* Configs may also have one or more additional elements to specify rule
|
100
98
|
* configuration or options.
|
101
|
-
*
|
102
99
|
* @typedef {Array|number} ruleConfig
|
103
100
|
* @param {number} 0 The rule's severity (0, 1, 2).
|
104
101
|
*/
|
@@ -134,7 +131,6 @@ function groupByProperty(objects) {
|
|
134
131
|
* {before: false, after: true},
|
135
132
|
* {before: false, after: false}
|
136
133
|
* ]
|
137
|
-
*
|
138
134
|
* @param {Object[]} objArr1 Single key/value objects, all with the same key
|
139
135
|
* @param {Object[]} objArr2 Single key/value objects, all with another key
|
140
136
|
* @returns {Object[]} Combined objects for each combination of input properties and values
|
@@ -178,6 +174,7 @@ function combinePropertyObjects(objArr1, objArr2) {
|
|
178
174
|
*/
|
179
175
|
class RuleConfigSet {
|
180
176
|
|
177
|
+
// eslint-disable-next-line jsdoc/require-description
|
181
178
|
/**
|
182
179
|
* @param {ruleConfig[]} configs Valid rule configurations
|
183
180
|
*/
|
@@ -193,7 +190,6 @@ class RuleConfigSet {
|
|
193
190
|
/**
|
194
191
|
* Add a severity level to the front of all configs in the instance.
|
195
192
|
* This should only be called after all configs have been added to the instance.
|
196
|
-
*
|
197
193
|
* @returns {void}
|
198
194
|
*/
|
199
195
|
addErrorSeverity() {
|
package/lib/init/npm-utils.js
CHANGED
@@ -21,7 +21,6 @@ const fs = require("fs"),
|
|
21
21
|
/**
|
22
22
|
* Find the closest package.json file, starting at process.cwd (by default),
|
23
23
|
* and working up to root.
|
24
|
-
*
|
25
24
|
* @param {string} [startDir=process.cwd()] Starting directory
|
26
25
|
* @returns {string} Absolute path to closest package.json file
|
27
26
|
*/
|
@@ -88,7 +87,6 @@ function fetchPeerDependencies(packageName) {
|
|
88
87
|
|
89
88
|
/**
|
90
89
|
* Check whether node modules are include in a project's package.json.
|
91
|
-
*
|
92
90
|
* @param {string[]} packages Array of node module names
|
93
91
|
* @param {Object} opt Options Object
|
94
92
|
* @param {boolean} opt.dependencies Set to true to check for direct dependencies
|
@@ -136,7 +134,6 @@ function check(packages, opt) {
|
|
136
134
|
* package.json.
|
137
135
|
*
|
138
136
|
* Convenience wrapper around check().
|
139
|
-
*
|
140
137
|
* @param {string[]} packages Array of node modules to check.
|
141
138
|
* @param {string} rootDir The directory contianing a package.json
|
142
139
|
* @returns {Object} An object whose keys are the module names
|
@@ -151,7 +148,6 @@ function checkDeps(packages, rootDir) {
|
|
151
148
|
* package.json.
|
152
149
|
*
|
153
150
|
* Convenience wrapper around check().
|
154
|
-
*
|
155
151
|
* @param {string[]} packages Array of node modules to check.
|
156
152
|
* @returns {Object} An object whose keys are the module names
|
157
153
|
* and values are booleans indicating installation.
|
@@ -162,7 +158,6 @@ function checkDevDeps(packages) {
|
|
162
158
|
|
163
159
|
/**
|
164
160
|
* Check whether package.json is found in current path.
|
165
|
-
*
|
166
161
|
* @param {string} [startDir] Starting directory
|
167
162
|
* @returns {boolean} Whether a package.json is found in current path.
|
168
163
|
*/
|
@@ -22,8 +22,7 @@ const assert = require("assert"),
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Checks whether or not a given node is a `case` node (not `default` node).
|
25
|
-
*
|
26
|
-
* @param {ASTNode} node - A `SwitchCase` node to check.
|
25
|
+
* @param {ASTNode} node A `SwitchCase` node to check.
|
27
26
|
* @returns {boolean} `true` if the node is a `case` node (not `default` node).
|
28
27
|
*/
|
29
28
|
function isCaseNode(node) {
|
@@ -33,8 +32,7 @@ function isCaseNode(node) {
|
|
33
32
|
/**
|
34
33
|
* Checks whether the given logical operator is taken into account for the code
|
35
34
|
* path analysis.
|
36
|
-
*
|
37
|
-
* @param {string} operator - The operator found in the LogicalExpression node
|
35
|
+
* @param {string} operator The operator found in the LogicalExpression node
|
38
36
|
* @returns {boolean} `true` if the operator is "&&" or "||"
|
39
37
|
*/
|
40
38
|
function isHandledLogicalOperator(operator) {
|
@@ -43,8 +41,7 @@ function isHandledLogicalOperator(operator) {
|
|
43
41
|
|
44
42
|
/**
|
45
43
|
* Gets the label if the parent node of a given node is a LabeledStatement.
|
46
|
-
*
|
47
|
-
* @param {ASTNode} node - A node to get.
|
44
|
+
* @param {ASTNode} node A node to get.
|
48
45
|
* @returns {string|null} The label or `null`.
|
49
46
|
*/
|
50
47
|
function getLabel(node) {
|
@@ -57,8 +54,7 @@ function getLabel(node) {
|
|
57
54
|
/**
|
58
55
|
* Checks whether or not a given logical expression node goes different path
|
59
56
|
* between the `true` case and the `false` case.
|
60
|
-
*
|
61
|
-
* @param {ASTNode} node - A node to check.
|
57
|
+
* @param {ASTNode} node A node to check.
|
62
58
|
* @returns {boolean} `true` if the node is a test of a choice statement.
|
63
59
|
*/
|
64
60
|
function isForkingByTrueOrFalse(node) {
|
@@ -86,8 +82,7 @@ function isForkingByTrueOrFalse(node) {
|
|
86
82
|
* This is used to detect infinity loops (e.g. `while (true) {}`).
|
87
83
|
* Statements preceded by an infinity loop are unreachable if the loop didn't
|
88
84
|
* have any `break` statement.
|
89
|
-
*
|
90
|
-
* @param {ASTNode} node - A node to get.
|
85
|
+
* @param {ASTNode} node A node to get.
|
91
86
|
* @returns {boolean|undefined} a boolean value if the node is a Literal node,
|
92
87
|
* otherwise `undefined`.
|
93
88
|
*/
|
@@ -102,8 +97,7 @@ function getBooleanValueIfSimpleConstant(node) {
|
|
102
97
|
* Checks that a given identifier node is a reference or not.
|
103
98
|
*
|
104
99
|
* This is used to detect the first throwable node in a `try` block.
|
105
|
-
*
|
106
|
-
* @param {ASTNode} node - An Identifier node to check.
|
100
|
+
* @param {ASTNode} node An Identifier node to check.
|
107
101
|
* @returns {boolean} `true` if the node is a reference.
|
108
102
|
*/
|
109
103
|
function isIdentifierReference(node) {
|
@@ -153,9 +147,8 @@ function isIdentifierReference(node) {
|
|
153
147
|
*
|
154
148
|
* In this process, both "onCodePathSegmentStart" and "onCodePathSegmentEnd"
|
155
149
|
* events are fired.
|
156
|
-
*
|
157
|
-
* @param {
|
158
|
-
* @param {ASTNode} node - The current AST node.
|
150
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
151
|
+
* @param {ASTNode} node The current AST node.
|
159
152
|
* @returns {void}
|
160
153
|
*/
|
161
154
|
function forwardCurrentToHead(analyzer, node) {
|
@@ -211,9 +204,8 @@ function forwardCurrentToHead(analyzer, node) {
|
|
211
204
|
/**
|
212
205
|
* Updates the current segment with empty.
|
213
206
|
* This is called at the last of functions or the program.
|
214
|
-
*
|
215
|
-
* @param {
|
216
|
-
* @param {ASTNode} node - The current AST node.
|
207
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
208
|
+
* @param {ASTNode} node The current AST node.
|
217
209
|
* @returns {void}
|
218
210
|
*/
|
219
211
|
function leaveFromCurrentSegment(analyzer, node) {
|
@@ -242,9 +234,8 @@ function leaveFromCurrentSegment(analyzer, node) {
|
|
242
234
|
*
|
243
235
|
* For example, if the node is `parent.consequent`, this creates a fork from the
|
244
236
|
* current path.
|
245
|
-
*
|
246
|
-
* @param {
|
247
|
-
* @param {ASTNode} node - The current AST node.
|
237
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
238
|
+
* @param {ASTNode} node The current AST node.
|
248
239
|
* @returns {void}
|
249
240
|
*/
|
250
241
|
function preprocess(analyzer, node) {
|
@@ -352,9 +343,8 @@ function preprocess(analyzer, node) {
|
|
352
343
|
|
353
344
|
/**
|
354
345
|
* Updates the code path due to the type of a given node in entering.
|
355
|
-
*
|
356
|
-
* @param {
|
357
|
-
* @param {ASTNode} node - The current AST node.
|
346
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
347
|
+
* @param {ASTNode} node The current AST node.
|
358
348
|
* @returns {void}
|
359
349
|
*/
|
360
350
|
function processCodePathToEnter(analyzer, node) {
|
@@ -449,9 +439,8 @@ function processCodePathToEnter(analyzer, node) {
|
|
449
439
|
|
450
440
|
/**
|
451
441
|
* Updates the code path due to the type of a given node in leaving.
|
452
|
-
*
|
453
|
-
* @param {
|
454
|
-
* @param {ASTNode} node - The current AST node.
|
442
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
443
|
+
* @param {ASTNode} node The current AST node.
|
455
444
|
* @returns {void}
|
456
445
|
*/
|
457
446
|
function processCodePathToExit(analyzer, node) {
|
@@ -563,9 +552,8 @@ function processCodePathToExit(analyzer, node) {
|
|
563
552
|
|
564
553
|
/**
|
565
554
|
* Updates the code path to finalize the current code path.
|
566
|
-
*
|
567
|
-
* @param {
|
568
|
-
* @param {ASTNode} node - The current AST node.
|
555
|
+
* @param {CodePathAnalyzer} analyzer The instance.
|
556
|
+
* @param {ASTNode} node The current AST node.
|
569
557
|
* @returns {void}
|
570
558
|
*/
|
571
559
|
function postprocess(analyzer, node) {
|
@@ -609,8 +597,9 @@ function postprocess(analyzer, node) {
|
|
609
597
|
*/
|
610
598
|
class CodePathAnalyzer {
|
611
599
|
|
600
|
+
// eslint-disable-next-line jsdoc/require-description
|
612
601
|
/**
|
613
|
-
* @param {EventGenerator} eventGenerator
|
602
|
+
* @param {EventGenerator} eventGenerator An event generator to wrap.
|
614
603
|
*/
|
615
604
|
constructor(eventGenerator) {
|
616
605
|
this.original = eventGenerator;
|
@@ -624,8 +613,7 @@ class CodePathAnalyzer {
|
|
624
613
|
/**
|
625
614
|
* Does the process to enter a given AST node.
|
626
615
|
* This updates state of analysis and calls `enterNode` of the wrapped.
|
627
|
-
*
|
628
|
-
* @param {ASTNode} node - A node which is entering.
|
616
|
+
* @param {ASTNode} node A node which is entering.
|
629
617
|
* @returns {void}
|
630
618
|
*/
|
631
619
|
enterNode(node) {
|
@@ -651,8 +639,7 @@ class CodePathAnalyzer {
|
|
651
639
|
/**
|
652
640
|
* Does the process to leave a given AST node.
|
653
641
|
* This updates state of analysis and calls `leaveNode` of the wrapped.
|
654
|
-
*
|
655
|
-
* @param {ASTNode} node - A node which is leaving.
|
642
|
+
* @param {ASTNode} node A node which is leaving.
|
656
643
|
* @returns {void}
|
657
644
|
*/
|
658
645
|
leaveNode(node) {
|
@@ -676,9 +663,8 @@ class CodePathAnalyzer {
|
|
676
663
|
/**
|
677
664
|
* This is called on a code path looped.
|
678
665
|
* Then this raises a looped event.
|
679
|
-
*
|
680
|
-
* @param {CodePathSegment}
|
681
|
-
* @param {CodePathSegment} toSegment - A segment of next.
|
666
|
+
* @param {CodePathSegment} fromSegment A segment of prev.
|
667
|
+
* @param {CodePathSegment} toSegment A segment of next.
|
682
668
|
* @returns {void}
|
683
669
|
*/
|
684
670
|
onLooped(fromSegment, toSegment) {
|