eslint 8.21.0 → 8.22.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.
@@ -139,31 +139,72 @@ class FlatConfigArray extends ConfigArray {
|
|
139
139
|
[ConfigArraySymbol.finalizeConfig](config) {
|
140
140
|
|
141
141
|
const { plugins, languageOptions, processor } = config;
|
142
|
+
let parserName, processorName;
|
143
|
+
let invalidParser = false,
|
144
|
+
invalidProcessor = false;
|
142
145
|
|
143
146
|
// Check parser value
|
144
|
-
if (languageOptions && languageOptions.parser
|
145
|
-
|
147
|
+
if (languageOptions && languageOptions.parser) {
|
148
|
+
if (typeof languageOptions.parser === "string") {
|
149
|
+
const { pluginName, objectName: localParserName } = splitPluginIdentifier(languageOptions.parser);
|
146
150
|
|
147
|
-
|
148
|
-
|
149
|
-
|
151
|
+
parserName = languageOptions.parser;
|
152
|
+
|
153
|
+
if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[localParserName]) {
|
154
|
+
throw new TypeError(`Key "parser": Could not find "${localParserName}" in plugin "${pluginName}".`);
|
155
|
+
}
|
150
156
|
|
151
|
-
|
157
|
+
languageOptions.parser = plugins[pluginName].parsers[localParserName];
|
158
|
+
} else {
|
159
|
+
invalidParser = true;
|
160
|
+
}
|
152
161
|
}
|
153
162
|
|
154
163
|
// Check processor value
|
155
|
-
if (processor
|
156
|
-
|
164
|
+
if (processor) {
|
165
|
+
if (typeof processor === "string") {
|
166
|
+
const { pluginName, objectName: localProcessorName } = splitPluginIdentifier(processor);
|
157
167
|
|
158
|
-
|
159
|
-
|
160
|
-
|
168
|
+
processorName = processor;
|
169
|
+
|
170
|
+
if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[localProcessorName]) {
|
171
|
+
throw new TypeError(`Key "processor": Could not find "${localProcessorName}" in plugin "${pluginName}".`);
|
172
|
+
}
|
161
173
|
|
162
|
-
|
174
|
+
config.processor = plugins[pluginName].processors[localProcessorName];
|
175
|
+
} else {
|
176
|
+
invalidProcessor = true;
|
177
|
+
}
|
163
178
|
}
|
164
179
|
|
165
180
|
ruleValidator.validate(config);
|
166
181
|
|
182
|
+
// apply special logic for serialization into JSON
|
183
|
+
/* eslint-disable object-shorthand -- shorthand would change "this" value */
|
184
|
+
Object.defineProperty(config, "toJSON", {
|
185
|
+
value: function() {
|
186
|
+
|
187
|
+
if (invalidParser) {
|
188
|
+
throw new Error("Caching is not supported when parser is an object.");
|
189
|
+
}
|
190
|
+
|
191
|
+
if (invalidProcessor) {
|
192
|
+
throw new Error("Caching is not supported when processor is an object.");
|
193
|
+
}
|
194
|
+
|
195
|
+
return {
|
196
|
+
...this,
|
197
|
+
plugins: Object.keys(plugins),
|
198
|
+
languageOptions: {
|
199
|
+
...languageOptions,
|
200
|
+
parser: parserName
|
201
|
+
},
|
202
|
+
processor: processorName
|
203
|
+
};
|
204
|
+
}
|
205
|
+
});
|
206
|
+
/* eslint-enable object-shorthand -- ok to enable now */
|
207
|
+
|
167
208
|
return config;
|
168
209
|
}
|
169
210
|
/* eslint-enable class-methods-use-this -- Desired as instance method */
|
@@ -436,9 +436,6 @@ function processOptions({
|
|
436
436
|
if (typeof cache !== "boolean") {
|
437
437
|
errors.push("'cache' must be a boolean.");
|
438
438
|
}
|
439
|
-
if (cache) {
|
440
|
-
errors.push("'cache' option is not yet supported.");
|
441
|
-
}
|
442
439
|
if (!isNonEmptyString(cacheLocation)) {
|
443
440
|
errors.push("'cacheLocation' must be a non-empty string.");
|
444
441
|
}
|
@@ -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.
|
@@ -606,9 +608,20 @@ class FlatESLint {
|
|
606
608
|
configType: "flat"
|
607
609
|
});
|
608
610
|
|
611
|
+
const cacheFilePath = getCacheFile(
|
612
|
+
processedOptions.cacheLocation,
|
613
|
+
processedOptions.cwd
|
614
|
+
);
|
615
|
+
|
616
|
+
const lintResultCache = processedOptions.cache
|
617
|
+
? new LintResultCache(cacheFilePath, processedOptions.cacheStrategy)
|
618
|
+
: null;
|
619
|
+
|
609
620
|
privateMembers.set(this, {
|
610
621
|
options: processedOptions,
|
611
622
|
linter,
|
623
|
+
cacheFilePath,
|
624
|
+
lintResultCache,
|
612
625
|
defaultConfigs,
|
613
626
|
defaultIgnores: () => false,
|
614
627
|
configs: null
|
@@ -782,6 +795,8 @@ class FlatESLint {
|
|
782
795
|
|
783
796
|
// Delete cache file; should this be done here?
|
784
797
|
if (!cache && cacheFilePath) {
|
798
|
+
debug(`Deleting cache file at ${cacheFilePath}`);
|
799
|
+
|
785
800
|
try {
|
786
801
|
await fs.unlink(cacheFilePath);
|
787
802
|
} catch (error) {
|
@@ -78,6 +78,9 @@ module.exports = {
|
|
78
78
|
ignoreConstructors: {
|
79
79
|
type: "boolean"
|
80
80
|
},
|
81
|
+
methodsIgnorePattern: {
|
82
|
+
type: "string"
|
83
|
+
},
|
81
84
|
avoidQuotes: {
|
82
85
|
type: "boolean"
|
83
86
|
},
|
@@ -115,6 +118,9 @@ module.exports = {
|
|
115
118
|
|
116
119
|
const PARAMS = context.options[1] || {};
|
117
120
|
const IGNORE_CONSTRUCTORS = PARAMS.ignoreConstructors;
|
121
|
+
const METHODS_IGNORE_PATTERN = PARAMS.methodsIgnorePattern
|
122
|
+
? new RegExp(PARAMS.methodsIgnorePattern, "u")
|
123
|
+
: null;
|
118
124
|
const AVOID_QUOTES = PARAMS.avoidQuotes;
|
119
125
|
const AVOID_EXPLICIT_RETURN_ARROWS = !!PARAMS.avoidExplicitReturnArrows;
|
120
126
|
const sourceCode = context.getSourceCode();
|
@@ -457,6 +463,15 @@ module.exports = {
|
|
457
463
|
if (IGNORE_CONSTRUCTORS && node.key.type === "Identifier" && isConstructor(node.key.name)) {
|
458
464
|
return;
|
459
465
|
}
|
466
|
+
|
467
|
+
if (METHODS_IGNORE_PATTERN) {
|
468
|
+
const propertyName = astUtils.getStaticPropertyName(node);
|
469
|
+
|
470
|
+
if (propertyName !== null && METHODS_IGNORE_PATTERN.test(propertyName)) {
|
471
|
+
return;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
460
475
|
if (AVOID_QUOTES && isStringLiteral(node.key)) {
|
461
476
|
return;
|
462
477
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.22.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -39,7 +39,8 @@
|
|
39
39
|
"docs/src/rules/*.md": [
|
40
40
|
"node tools/fetch-docs-links.js",
|
41
41
|
"git add docs/src/_data/further_reading_links.json"
|
42
|
-
]
|
42
|
+
],
|
43
|
+
"docs/**/*.svg": "npx svgo -r --multipass"
|
43
44
|
},
|
44
45
|
"files": [
|
45
46
|
"LICENSE",
|