eslint 8.21.0 → 8.23.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/bin/eslint.js +2 -4
- package/conf/globals.js +6 -1
- package/lib/cli-engine/file-enumerator.js +4 -2
- package/lib/cli.js +123 -29
- package/lib/config/flat-config-array.js +53 -12
- package/lib/eslint/eslint-helpers.js +39 -16
- package/lib/eslint/flat-eslint.js +29 -17
- package/lib/linter/code-path-analysis/code-path-segment.js +2 -2
- package/lib/linter/code-path-analysis/code-path-state.js +7 -7
- package/lib/linter/code-path-analysis/debug-helpers.js +3 -3
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/config-comment-parser.js +1 -2
- package/lib/linter/timing.js +4 -4
- package/lib/options.js +290 -242
- package/lib/rule-tester/flat-rule-tester.js +1 -1
- package/lib/rule-tester/rule-tester.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/global-require.js +2 -1
- package/lib/rules/indent-legacy.js +4 -4
- package/lib/rules/indent.js +23 -15
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-parens.js +2 -2
- package/lib/rules/no-fallthrough.js +8 -3
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +24 -5
- package/lib/rules/object-shorthand.js +15 -0
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/prefer-arrow-callback.js +2 -2
- package/lib/rules/prefer-const.js +13 -1
- package/lib/rules/prefer-rest-params.js +1 -1
- package/lib/rules/require-yield.js +0 -1
- package/lib/rules/utils/ast-utils.js +10 -4
- package/lib/shared/logging.js +1 -1
- package/lib/shared/types.js +1 -1
- package/lib/source-code/token-store/cursor.js +1 -1
- package/package.json +9 -8
@@ -30,6 +30,7 @@ const {
|
|
30
30
|
const {
|
31
31
|
fileExists,
|
32
32
|
findFiles,
|
33
|
+
getCacheFile,
|
33
34
|
|
34
35
|
isNonEmptyString,
|
35
36
|
isArrayOfNonEmptyString,
|
@@ -41,6 +42,7 @@ const {
|
|
41
42
|
} = require("./eslint-helpers");
|
42
43
|
const { pathToFileURL } = require("url");
|
43
44
|
const { FlatConfigArray } = require("../config/flat-config-array");
|
45
|
+
const LintResultCache = require("../cli-engine/lint-result-cache");
|
44
46
|
|
45
47
|
/*
|
46
48
|
* This is necessary to allow overwriting writeFile for testing purposes.
|
@@ -71,7 +73,6 @@ const { FlatConfigArray } = require("../config/flat-config-array");
|
|
71
73
|
* @property {"metadata" | "content"} [cacheStrategy] The strategy used to detect changed files.
|
72
74
|
* @property {string} [cwd] The value to use for the current working directory.
|
73
75
|
* @property {boolean} [errorOnUnmatchedPattern] If `false` then `ESLint#lintFiles()` doesn't throw even if no target files found. Defaults to `true`.
|
74
|
-
* @property {string[]} [extensions] An array of file extensions to check.
|
75
76
|
* @property {boolean|Function} [fix] Execute in autofix mode. If a function, should return a boolean.
|
76
77
|
* @property {string[]} [fixTypes] Array of rule types to apply fixes for.
|
77
78
|
* @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.
|
@@ -319,8 +320,7 @@ async function calculateConfigArray(eslint, {
|
|
319
320
|
configFile,
|
320
321
|
ignore: shouldIgnore,
|
321
322
|
ignorePath,
|
322
|
-
ignorePatterns
|
323
|
-
extensions
|
323
|
+
ignorePatterns
|
324
324
|
}) {
|
325
325
|
|
326
326
|
// check for cached instance
|
@@ -363,13 +363,6 @@ async function calculateConfigArray(eslint, {
|
|
363
363
|
// add in any configured defaults
|
364
364
|
configs.push(...slots.defaultConfigs);
|
365
365
|
|
366
|
-
// if there are any extensions, create configs for them for easier matching
|
367
|
-
if (extensions && extensions.length) {
|
368
|
-
configs.push({
|
369
|
-
files: extensions.map(ext => `**/*${ext}`)
|
370
|
-
});
|
371
|
-
}
|
372
|
-
|
373
366
|
let allIgnorePatterns = [];
|
374
367
|
let ignoreFilePath;
|
375
368
|
|
@@ -513,6 +506,7 @@ function verifyText({
|
|
513
506
|
const result = {
|
514
507
|
filePath: filePath === "<text>" ? filePath : path.resolve(filePath),
|
515
508
|
messages,
|
509
|
+
suppressedMessages: linter.getSuppressedMessages(),
|
516
510
|
...calculateStatsPerFile(messages)
|
517
511
|
};
|
518
512
|
|
@@ -606,9 +600,20 @@ class FlatESLint {
|
|
606
600
|
configType: "flat"
|
607
601
|
});
|
608
602
|
|
603
|
+
const cacheFilePath = getCacheFile(
|
604
|
+
processedOptions.cacheLocation,
|
605
|
+
processedOptions.cwd
|
606
|
+
);
|
607
|
+
|
608
|
+
const lintResultCache = processedOptions.cache
|
609
|
+
? new LintResultCache(cacheFilePath, processedOptions.cacheStrategy)
|
610
|
+
: null;
|
611
|
+
|
609
612
|
privateMembers.set(this, {
|
610
613
|
options: processedOptions,
|
611
614
|
linter,
|
615
|
+
cacheFilePath,
|
616
|
+
lintResultCache,
|
612
617
|
defaultConfigs,
|
613
618
|
defaultIgnores: () => false,
|
614
619
|
configs: null
|
@@ -676,11 +681,13 @@ class FlatESLint {
|
|
676
681
|
|
677
682
|
results.forEach(result => {
|
678
683
|
const filteredMessages = result.messages.filter(isErrorMessage);
|
684
|
+
const filteredSuppressedMessages = result.suppressedMessages.filter(isErrorMessage);
|
679
685
|
|
680
686
|
if (filteredMessages.length > 0) {
|
681
687
|
filtered.push({
|
682
688
|
...result,
|
683
689
|
messages: filteredMessages,
|
690
|
+
suppressedMessages: filteredSuppressedMessages,
|
684
691
|
errorCount: filteredMessages.length,
|
685
692
|
warningCount: 0,
|
686
693
|
fixableErrorCount: result.fixableErrorCount,
|
@@ -733,11 +740,12 @@ class FlatESLint {
|
|
733
740
|
* calculated config for the given file.
|
734
741
|
*/
|
735
742
|
const config = configs.getConfig(filePath);
|
743
|
+
const allMessages = result.messages.concat(result.suppressedMessages);
|
736
744
|
|
737
|
-
for (const { ruleId } of
|
745
|
+
for (const { ruleId } of allMessages) {
|
738
746
|
const rule = getRuleFromConfig(ruleId, config);
|
739
747
|
|
740
|
-
// ensure the rule exists
|
748
|
+
// ensure the rule exists
|
741
749
|
if (!rule) {
|
742
750
|
throw new TypeError(`Could not find the rule "${ruleId}".`);
|
743
751
|
}
|
@@ -773,8 +781,8 @@ class FlatESLint {
|
|
773
781
|
fix,
|
774
782
|
fixTypes,
|
775
783
|
reportUnusedDisableDirectives,
|
776
|
-
|
777
|
-
|
784
|
+
globInputPaths,
|
785
|
+
errorOnUnmatchedPattern
|
778
786
|
} = eslintOptions;
|
779
787
|
const startTime = Date.now();
|
780
788
|
const usedConfigs = [];
|
@@ -782,6 +790,8 @@ class FlatESLint {
|
|
782
790
|
|
783
791
|
// Delete cache file; should this be done here?
|
784
792
|
if (!cache && cacheFilePath) {
|
793
|
+
debug(`Deleting cache file at ${cacheFilePath}`);
|
794
|
+
|
785
795
|
try {
|
786
796
|
await fs.unlink(cacheFilePath);
|
787
797
|
} catch (error) {
|
@@ -797,9 +807,9 @@ class FlatESLint {
|
|
797
807
|
const filePaths = await findFiles({
|
798
808
|
patterns: typeof patterns === "string" ? [patterns] : patterns,
|
799
809
|
cwd,
|
800
|
-
extensions,
|
801
810
|
globInputPaths,
|
802
|
-
configs
|
811
|
+
configs,
|
812
|
+
errorOnUnmatchedPattern
|
803
813
|
});
|
804
814
|
|
805
815
|
debug(`${filePaths.length} files found in: ${Date.now() - startTime}ms`);
|
@@ -1112,6 +1122,7 @@ class FlatESLint {
|
|
1112
1122
|
results.sort(compareResultsByFilePath);
|
1113
1123
|
|
1114
1124
|
return formatter(results, {
|
1125
|
+
cwd,
|
1115
1126
|
get rulesMeta() {
|
1116
1127
|
if (!rulesMeta) {
|
1117
1128
|
rulesMeta = eslint.getRulesMetaForResults(results);
|
@@ -1160,5 +1171,6 @@ class FlatESLint {
|
|
1160
1171
|
//------------------------------------------------------------------------------
|
1161
1172
|
|
1162
1173
|
module.exports = {
|
1163
|
-
FlatESLint
|
1174
|
+
FlatESLint,
|
1175
|
+
findFlatConfigFile
|
1164
1176
|
};
|
@@ -59,7 +59,7 @@ function getContinueContext(state, label) {
|
|
59
59
|
context = context.upper;
|
60
60
|
}
|
61
61
|
|
62
|
-
/*
|
62
|
+
/* c8 ignore next */
|
63
63
|
return null;
|
64
64
|
}
|
65
65
|
|
@@ -79,7 +79,7 @@ function getBreakContext(state, label) {
|
|
79
79
|
context = context.upper;
|
80
80
|
}
|
81
81
|
|
82
|
-
/*
|
82
|
+
/* c8 ignore next */
|
83
83
|
return null;
|
84
84
|
}
|
85
85
|
|
@@ -433,7 +433,7 @@ class CodePathState {
|
|
433
433
|
*/
|
434
434
|
return context;
|
435
435
|
|
436
|
-
/*
|
436
|
+
/* c8 ignore next */
|
437
437
|
default:
|
438
438
|
throw new Error("unreachable");
|
439
439
|
}
|
@@ -1030,7 +1030,7 @@ class CodePathState {
|
|
1030
1030
|
};
|
1031
1031
|
break;
|
1032
1032
|
|
1033
|
-
/*
|
1033
|
+
/* c8 ignore next */
|
1034
1034
|
default:
|
1035
1035
|
throw new Error(`unknown type: "${type}"`);
|
1036
1036
|
}
|
@@ -1095,7 +1095,7 @@ class CodePathState {
|
|
1095
1095
|
);
|
1096
1096
|
break;
|
1097
1097
|
|
1098
|
-
/*
|
1098
|
+
/* c8 ignore next */
|
1099
1099
|
default:
|
1100
1100
|
throw new Error("unreachable");
|
1101
1101
|
}
|
@@ -1392,11 +1392,12 @@ class CodePathState {
|
|
1392
1392
|
|
1393
1393
|
const context = getBreakContext(this, label);
|
1394
1394
|
|
1395
|
-
|
1395
|
+
|
1396
1396
|
if (context) {
|
1397
1397
|
context.brokenForkContext.add(forkContext.head);
|
1398
1398
|
}
|
1399
1399
|
|
1400
|
+
/* c8 ignore next */
|
1400
1401
|
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
1401
1402
|
}
|
1402
1403
|
|
@@ -1417,7 +1418,6 @@ class CodePathState {
|
|
1417
1418
|
|
1418
1419
|
const context = getContinueContext(this, label);
|
1419
1420
|
|
1420
|
-
/* istanbul ignore else: foolproof (syntax error) */
|
1421
1421
|
if (context) {
|
1422
1422
|
if (context.continueDestSegments) {
|
1423
1423
|
makeLooped(this, forkContext.head, context.continueDestSegments);
|
@@ -20,7 +20,7 @@ const debug = require("debug")("eslint:code-path");
|
|
20
20
|
* @param {CodePathSegment} segment A segment to get.
|
21
21
|
* @returns {string} Id of the segment.
|
22
22
|
*/
|
23
|
-
/*
|
23
|
+
/* c8 ignore next */
|
24
24
|
function getId(segment) { // eslint-disable-line jsdoc/require-jsdoc -- Ignoring
|
25
25
|
return segment.id + (segment.reachable ? "" : "!");
|
26
26
|
}
|
@@ -67,7 +67,7 @@ module.exports = {
|
|
67
67
|
* @param {boolean} leaving A flag whether or not it's leaving
|
68
68
|
* @returns {void}
|
69
69
|
*/
|
70
|
-
dumpState: !debug.enabled ? debug : /*
|
70
|
+
dumpState: !debug.enabled ? debug : /* c8 ignore next */ function(node, state, leaving) {
|
71
71
|
for (let i = 0; i < state.currentSegments.length; ++i) {
|
72
72
|
const segInternal = state.currentSegments[i].internal;
|
73
73
|
|
@@ -98,7 +98,7 @@ module.exports = {
|
|
98
98
|
* @see http://www.graphviz.org
|
99
99
|
* @see http://www.webgraphviz.com
|
100
100
|
*/
|
101
|
-
dumpDot: !debug.enabled ? debug : /*
|
101
|
+
dumpDot: !debug.enabled ? debug : /* c8 ignore next */ function(codePath) {
|
102
102
|
let text =
|
103
103
|
"\n" +
|
104
104
|
"digraph {\n" +
|
@@ -131,8 +131,7 @@ module.exports = class ConfigCommentParser {
|
|
131
131
|
|
132
132
|
const items = {};
|
133
133
|
|
134
|
-
|
135
|
-
string.replace(/\s*,\s*/gu, ",").split(/,+/u).forEach(name => {
|
134
|
+
string.split(",").forEach(name => {
|
136
135
|
const trimmedName = name.trim();
|
137
136
|
|
138
137
|
if (trimmedName) {
|
package/lib/linter/timing.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Helpers
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
/*
|
12
|
+
/* c8 ignore next */
|
13
13
|
/**
|
14
14
|
* Align the string to left
|
15
15
|
* @param {string} str string to evaluate
|
@@ -22,7 +22,7 @@ function alignLeft(str, len, ch) {
|
|
22
22
|
return str + new Array(len - str.length + 1).join(ch || " ");
|
23
23
|
}
|
24
24
|
|
25
|
-
/*
|
25
|
+
/* c8 ignore next */
|
26
26
|
/**
|
27
27
|
* Align the string to right
|
28
28
|
* @param {string} str string to evaluate
|
@@ -64,7 +64,7 @@ function getListSize() {
|
|
64
64
|
return TIMING_ENV_VAR_AS_INTEGER > 10 ? TIMING_ENV_VAR_AS_INTEGER : MINIMUM_SIZE;
|
65
65
|
}
|
66
66
|
|
67
|
-
/*
|
67
|
+
/* c8 ignore next */
|
68
68
|
/**
|
69
69
|
* display the data
|
70
70
|
* @param {Object} data Data object to be displayed
|
@@ -119,7 +119,7 @@ function display(data) {
|
|
119
119
|
console.log(table.join("\n")); // eslint-disable-line no-console -- Debugging function
|
120
120
|
}
|
121
121
|
|
122
|
-
/*
|
122
|
+
/* c8 ignore next */
|
123
123
|
module.exports = (function() {
|
124
124
|
|
125
125
|
const data = Object.create(null);
|