eslint 9.16.0 → 9.18.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/README.md +2 -2
- package/lib/cli.js +3 -4
- package/lib/config/config-loader.js +9 -22
- package/lib/eslint/eslint.js +2 -5
- package/lib/linter/source-code-fixer.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -0
- package/lib/rules/camelcase.js +1 -0
- package/lib/rules/capitalized-comments.js +1 -0
- package/lib/rules/consistent-this.js +1 -0
- package/lib/rules/curly.js +1 -0
- package/lib/rules/default-case-last.js +2 -2
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-notation.js +1 -0
- package/lib/rules/for-direction.js +2 -2
- package/lib/rules/func-name-matching.js +1 -0
- package/lib/rules/func-style.js +1 -0
- package/lib/rules/id-denylist.js +1 -0
- package/lib/rules/id-length.js +1 -0
- package/lib/rules/id-match.js +1 -0
- package/lib/rules/init-declarations.js +1 -0
- package/lib/rules/logical-assignment-operators.js +1 -0
- package/lib/rules/no-console.js +3 -1
- package/lib/rules/no-continue.js +1 -0
- package/lib/rules/no-div-regex.js +1 -0
- package/lib/rules/no-else-return.js +1 -0
- package/lib/rules/no-extra-boolean-cast.js +1 -0
- package/lib/rules/no-extra-label.js +1 -0
- package/lib/rules/no-implicit-coercion.js +1 -0
- package/lib/rules/no-inline-comments.js +1 -0
- package/lib/rules/no-label-var.js +1 -0
- package/lib/rules/no-labels.js +1 -0
- package/lib/rules/no-lonely-if.js +1 -0
- package/lib/rules/no-magic-numbers.js +1 -0
- package/lib/rules/no-multi-str.js +1 -0
- package/lib/rules/no-negated-condition.js +1 -0
- package/lib/rules/no-nested-ternary.js +1 -0
- package/lib/rules/no-param-reassign.js +2 -2
- package/lib/rules/no-plusplus.js +1 -0
- package/lib/rules/no-script-url.js +3 -3
- package/lib/rules/no-shadow-restricted-names.js +17 -7
- package/lib/rules/no-ternary.js +1 -0
- package/lib/rules/no-undef-init.js +1 -0
- package/lib/rules/no-undefined.js +1 -0
- package/lib/rules/no-underscore-dangle.js +1 -0
- package/lib/rules/no-unneeded-ternary.js +1 -0
- package/lib/rules/no-unused-vars.js +613 -2
- package/lib/rules/no-useless-assignment.js +9 -0
- package/lib/rules/no-useless-computed-key.js +1 -0
- package/lib/rules/no-useless-concat.js +1 -0
- package/lib/rules/no-void.js +1 -0
- package/lib/rules/no-warning-comments.js +1 -0
- package/lib/rules/object-shorthand.js +1 -0
- package/lib/rules/one-var.js +1 -0
- package/lib/rules/operator-assignment.js +1 -0
- package/lib/rules/prefer-arrow-callback.js +1 -0
- package/lib/rules/prefer-destructuring.js +1 -0
- package/lib/rules/prefer-exponentiation-operator.js +1 -0
- package/lib/rules/prefer-numeric-literals.js +1 -0
- package/lib/rules/prefer-object-spread.js +3 -2
- package/lib/rules/prefer-spread.js +1 -0
- package/lib/rules/prefer-template.js +1 -0
- package/lib/rules/require-unicode-regexp.js +2 -2
- package/lib/rules/sort-imports.js +3 -2
- package/lib/rules/sort-keys.js +1 -0
- package/lib/rules/sort-vars.js +1 -0
- package/lib/rules/vars-on-top.js +1 -0
- package/lib/rules/yoda.js +1 -0
- package/lib/shared/flags.js +3 -3
- package/lib/types/index.d.ts +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
@@ -299,8 +299,8 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
299
299
|
<h3>Platinum Sponsors</h3>
|
300
300
|
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
|
301
301
|
<p><a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a></p><h3>Silver Sponsors</h3>
|
302
|
-
<p><a href="https://www.serptriumph.com/"><img src="https://images.opencollective.com/serp-triumph5/fea3074/logo.png" alt="SERP Triumph" height="64"></a> <a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301
|
303
|
-
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://
|
302
|
+
<p><a href="https://www.serptriumph.com/"><img src="https://images.opencollective.com/serp-triumph5/fea3074/logo.png" alt="SERP Triumph" height="64"></a> <a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a></p><h3>Bronze Sponsors</h3>
|
303
|
+
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a></p>
|
304
304
|
<h3>Technology Sponsors</h3>
|
305
305
|
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
306
306
|
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
package/lib/cli.js
CHANGED
@@ -341,16 +341,15 @@ const cli = {
|
|
341
341
|
/**
|
342
342
|
* Calculates the command string for the --inspect-config operation.
|
343
343
|
* @param {string} configFile The path to the config file to inspect.
|
344
|
-
* @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
|
345
344
|
* @returns {Promise<string>} The command string to execute.
|
346
345
|
*/
|
347
|
-
async calculateInspectConfigFlags(configFile
|
346
|
+
async calculateInspectConfigFlags(configFile) {
|
348
347
|
|
349
348
|
// find the config file
|
350
349
|
const {
|
351
350
|
configFilePath,
|
352
351
|
basePath
|
353
|
-
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile }
|
352
|
+
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile });
|
354
353
|
|
355
354
|
return ["--config", configFilePath, "--basePath", basePath];
|
356
355
|
},
|
@@ -451,7 +450,7 @@ const cli = {
|
|
451
450
|
try {
|
452
451
|
const flatOptions = await translateOptions(options, "flat");
|
453
452
|
const spawn = require("cross-spawn");
|
454
|
-
const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile
|
453
|
+
const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile);
|
455
454
|
|
456
455
|
spawn.sync("npx", ["@eslint/config-inspector@latest", ...flags], { encoding: "utf8", stdio: "inherit" });
|
457
456
|
} catch (error) {
|
@@ -31,7 +31,6 @@ const { FlatConfigArray } = require("./flat-config-array");
|
|
31
31
|
* @property {Array<FlatConfigObject>} [defaultConfigs] The default configs to use.
|
32
32
|
* @property {Array<string>} [ignorePatterns] The ignore patterns to use.
|
33
33
|
* @property {FlatConfigObject|Array<FlatConfigObject>} overrideConfig The override config to use.
|
34
|
-
* @property {boolean} allowTS Indicates if TypeScript configuration files are allowed.
|
35
34
|
*/
|
36
35
|
|
37
36
|
//------------------------------------------------------------------------------
|
@@ -41,10 +40,7 @@ const { FlatConfigArray } = require("./flat-config-array");
|
|
41
40
|
const FLAT_CONFIG_FILENAMES = [
|
42
41
|
"eslint.config.js",
|
43
42
|
"eslint.config.mjs",
|
44
|
-
"eslint.config.cjs"
|
45
|
-
];
|
46
|
-
|
47
|
-
const TS_FLAT_CONFIG_FILENAMES = [
|
43
|
+
"eslint.config.cjs",
|
48
44
|
"eslint.config.ts",
|
49
45
|
"eslint.config.mts",
|
50
46
|
"eslint.config.cts"
|
@@ -119,10 +115,9 @@ function isRunningInDeno() {
|
|
119
115
|
/**
|
120
116
|
* Load the config array from the given filename.
|
121
117
|
* @param {string} filePath The filename to load from.
|
122
|
-
* @param {boolean} allowTS Indicates if TypeScript configuration files are allowed.
|
123
118
|
* @returns {Promise<any>} The config loaded from the config file.
|
124
119
|
*/
|
125
|
-
async function loadConfigFile(filePath
|
120
|
+
async function loadConfigFile(filePath) {
|
126
121
|
|
127
122
|
debug(`Loading config from ${filePath}`);
|
128
123
|
|
@@ -171,7 +166,7 @@ async function loadConfigFile(filePath, allowTS) {
|
|
171
166
|
*
|
172
167
|
* When Node.js supports native TypeScript imports, we can remove this check.
|
173
168
|
*/
|
174
|
-
if (
|
169
|
+
if (isTS && !isDeno && !isBun) {
|
175
170
|
|
176
171
|
// eslint-disable-next-line no-use-before-define -- `ConfigLoader.loadJiti` can be overwritten for testing
|
177
172
|
const { createJiti } = await ConfigLoader.loadJiti().catch(() => {
|
@@ -261,8 +256,7 @@ class ConfigLoader {
|
|
261
256
|
const resultPromise = ConfigLoader.locateConfigFileToUse({
|
262
257
|
useConfigFile: this.#options.configFile,
|
263
258
|
cwd: this.#options.cwd,
|
264
|
-
fromDirectory
|
265
|
-
allowTS: this.#options.allowTS
|
259
|
+
fromDirectory
|
266
260
|
});
|
267
261
|
|
268
262
|
// ensure `ConfigLoader.locateConfigFileToUse` is called only once for `fromDirectory`
|
@@ -443,15 +437,10 @@ class ConfigLoader {
|
|
443
437
|
* @param {string|false|undefined} options.useConfigFile The path to the config file to use.
|
444
438
|
* @param {string} options.cwd Path to a directory that should be considered as the current working directory.
|
445
439
|
* @param {string} [options.fromDirectory] The directory from which to start searching. Defaults to `cwd`.
|
446
|
-
* @param {boolean} options.allowTS Indicates if TypeScript configuration files are allowed.
|
447
440
|
* @returns {Promise<{configFilePath:string|undefined,basePath:string}>} Location information for
|
448
441
|
* the config file.
|
449
442
|
*/
|
450
|
-
static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd
|
451
|
-
|
452
|
-
const configFilenames = allowTS
|
453
|
-
? [...FLAT_CONFIG_FILENAMES, ...TS_FLAT_CONFIG_FILENAMES]
|
454
|
-
: FLAT_CONFIG_FILENAMES;
|
443
|
+
static async locateConfigFileToUse({ useConfigFile, cwd, fromDirectory = cwd }) {
|
455
444
|
|
456
445
|
// determine where to load config file from
|
457
446
|
let configFilePath;
|
@@ -464,7 +453,7 @@ class ConfigLoader {
|
|
464
453
|
} else if (useConfigFile !== false) {
|
465
454
|
debug("Searching for eslint.config.js");
|
466
455
|
configFilePath = await findUp(
|
467
|
-
|
456
|
+
FLAT_CONFIG_FILENAMES,
|
468
457
|
{ cwd: fromDirectory }
|
469
458
|
);
|
470
459
|
|
@@ -497,8 +486,7 @@ class ConfigLoader {
|
|
497
486
|
ignoreEnabled,
|
498
487
|
ignorePatterns,
|
499
488
|
overrideConfig,
|
500
|
-
defaultConfigs = []
|
501
|
-
allowTS
|
489
|
+
defaultConfigs = []
|
502
490
|
} = options;
|
503
491
|
|
504
492
|
debug(`Calculating config array from config file ${configFilePath} and base path ${basePath}`);
|
@@ -509,7 +497,7 @@ class ConfigLoader {
|
|
509
497
|
if (configFilePath) {
|
510
498
|
|
511
499
|
debug(`Loading config file ${configFilePath}`);
|
512
|
-
const fileConfig = await loadConfigFile(configFilePath
|
500
|
+
const fileConfig = await loadConfigFile(configFilePath);
|
513
501
|
|
514
502
|
if (Array.isArray(fileConfig)) {
|
515
503
|
configs.push(...fileConfig);
|
@@ -618,8 +606,7 @@ class LegacyConfigLoader extends ConfigLoader {
|
|
618
606
|
if (!this.#configFilePath) {
|
619
607
|
this.#configFilePath = ConfigLoader.locateConfigFileToUse({
|
620
608
|
useConfigFile: this.#options.configFile,
|
621
|
-
cwd: this.#options.cwd
|
622
|
-
allowTS: this.#options.allowTS
|
609
|
+
cwd: this.#options.cwd
|
623
610
|
});
|
624
611
|
}
|
625
612
|
|
package/lib/eslint/eslint.js
CHANGED
@@ -266,15 +266,13 @@ function compareResultsByFilePath(a, b) {
|
|
266
266
|
* This function is used primarily by the `--inspect-config` option. For now,
|
267
267
|
* we will maintain the existing behavior, which is to search up from the cwd.
|
268
268
|
* @param {ESLintOptions} options The ESLint instance options.
|
269
|
-
* @param {boolean} allowTS `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
|
270
269
|
* @returns {Promise<{configFilePath:string|undefined;basePath:string}>} Location information for
|
271
270
|
* the config file.
|
272
271
|
*/
|
273
|
-
async function locateConfigFileToUse({ configFile, cwd }
|
272
|
+
async function locateConfigFileToUse({ configFile, cwd }) {
|
274
273
|
|
275
274
|
const configLoader = new ConfigLoader({
|
276
275
|
cwd,
|
277
|
-
allowTS,
|
278
276
|
configFile
|
279
277
|
});
|
280
278
|
|
@@ -469,8 +467,7 @@ class ESLint {
|
|
469
467
|
configFile: processedOptions.configFile,
|
470
468
|
ignoreEnabled: processedOptions.ignore,
|
471
469
|
ignorePatterns: processedOptions.ignorePatterns,
|
472
|
-
defaultConfigs
|
473
|
-
allowTS: processedOptions.flags.includes("unstable_ts_config")
|
470
|
+
defaultConfigs
|
474
471
|
};
|
475
472
|
|
476
473
|
this.#configLoader = processedOptions.flags.includes("unstable_config_lookup_from_file")
|
@@ -107,7 +107,7 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
|
|
107
107
|
}
|
108
108
|
|
109
109
|
messages.forEach(problem => {
|
110
|
-
if (Object.hasOwn(problem, "fix")) {
|
110
|
+
if (Object.hasOwn(problem, "fix") && problem.fix) {
|
111
111
|
fixes.push(problem);
|
112
112
|
} else {
|
113
113
|
remainingMessages.push(problem);
|
package/lib/rules/camelcase.js
CHANGED
package/lib/rules/curly.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @fileoverview Rule to enforce default clauses in switch statements to be last
|
2
|
+
* @fileoverview Rule to enforce `default` clauses in `switch` statements to be last
|
3
3
|
* @author Milos Djermanovic
|
4
4
|
*/
|
5
5
|
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
15
15
|
type: "suggestion",
|
16
16
|
|
17
17
|
docs: {
|
18
|
-
description: "Enforce default clauses in switch statements to be last",
|
18
|
+
description: "Enforce `default` clauses in `switch` statements to be last",
|
19
19
|
recommended: false,
|
20
20
|
url: "https://eslint.org/docs/latest/rules/default-case-last"
|
21
21
|
},
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @fileoverview enforce
|
2
|
+
* @fileoverview enforce `for` loop update clause moving the counter in the right direction.(for-direction)
|
3
3
|
* @author Aladdin-ADD<hh_2013@foxmail.com>
|
4
4
|
*/
|
5
5
|
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
21
21
|
type: "problem",
|
22
22
|
|
23
23
|
docs: {
|
24
|
-
description: "Enforce
|
24
|
+
description: "Enforce `for` loop update clause moving the counter in the right direction",
|
25
25
|
recommended: true,
|
26
26
|
url: "https://eslint.org/docs/latest/rules/for-direction"
|
27
27
|
},
|
package/lib/rules/func-style.js
CHANGED
package/lib/rules/id-denylist.js
CHANGED
package/lib/rules/id-length.js
CHANGED
package/lib/rules/id-match.js
CHANGED
package/lib/rules/no-console.js
CHANGED
@@ -49,6 +49,7 @@ module.exports = {
|
|
49
49
|
|
50
50
|
messages: {
|
51
51
|
unexpected: "Unexpected console statement.",
|
52
|
+
limited: "Unexpected console statement. Only these console methods are allowed: {{ allowed }}.",
|
52
53
|
removeConsole: "Remove the console.{{ propertyName }}()."
|
53
54
|
}
|
54
55
|
},
|
@@ -169,7 +170,8 @@ module.exports = {
|
|
169
170
|
context.report({
|
170
171
|
node,
|
171
172
|
loc: node.loc,
|
172
|
-
messageId: "unexpected",
|
173
|
+
messageId: allowed.length ? "limited" : "unexpected",
|
174
|
+
data: { allowed: allowed.join(", ") },
|
173
175
|
suggest: canProvideSuggestions(node)
|
174
176
|
? [{
|
175
177
|
messageId: "removeConsole",
|
package/lib/rules/no-continue.js
CHANGED
package/lib/rules/no-labels.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @fileoverview Disallow
|
2
|
+
* @fileoverview Disallow reassigning function parameters.
|
3
3
|
* @author Nat Burns
|
4
4
|
*/
|
5
5
|
"use strict";
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
type: "suggestion",
|
17
17
|
|
18
18
|
docs: {
|
19
|
-
description: "Disallow reassigning
|
19
|
+
description: "Disallow reassigning function parameters",
|
20
20
|
recommended: false,
|
21
21
|
url: "https://eslint.org/docs/latest/rules/no-param-reassign"
|
22
22
|
},
|
package/lib/rules/no-plusplus.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @fileoverview Rule to
|
2
|
+
* @fileoverview Rule to disallow `javascript:` URLs
|
3
3
|
* @author Ilya Volodin
|
4
4
|
*/
|
5
5
|
/* eslint no-script-url: 0 -- Code is checking to report such URLs */
|
@@ -18,7 +18,7 @@ module.exports = {
|
|
18
18
|
type: "suggestion",
|
19
19
|
|
20
20
|
docs: {
|
21
|
-
description: "Disallow `javascript:`
|
21
|
+
description: "Disallow `javascript:` URLs",
|
22
22
|
recommended: false,
|
23
23
|
url: "https://eslint.org/docs/latest/rules/no-script-url"
|
24
24
|
},
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
33
33
|
create(context) {
|
34
34
|
|
35
35
|
/**
|
36
|
-
* Check whether a node's static value starts with
|
36
|
+
* Check whether a node's static value starts with `javascript:` or not.
|
37
37
|
* And report an error for unexpected script URL.
|
38
38
|
* @param {ASTNode} node node to check
|
39
39
|
* @returns {void}
|
@@ -45,17 +45,27 @@ module.exports = {
|
|
45
45
|
const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]);
|
46
46
|
const sourceCode = context.sourceCode;
|
47
47
|
|
48
|
+
// Track reported nodes to avoid duplicate reports. For example, on class declarations.
|
49
|
+
const reportedNodes = new Set();
|
50
|
+
|
48
51
|
return {
|
49
|
-
"VariableDeclaration, :function, CatchClause"(node) {
|
52
|
+
"VariableDeclaration, :function, CatchClause, ImportDeclaration, ClassDeclaration, ClassExpression"(node) {
|
50
53
|
for (const variable of sourceCode.getDeclaredVariables(node)) {
|
51
54
|
if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
for (const def of variable.defs) {
|
56
|
+
const nodeToReport = def.name;
|
57
|
+
|
58
|
+
if (!reportedNodes.has(nodeToReport)) {
|
59
|
+
reportedNodes.add(nodeToReport);
|
60
|
+
context.report({
|
61
|
+
node: nodeToReport,
|
62
|
+
messageId: "shadowingRestrictedName",
|
63
|
+
data: {
|
64
|
+
name: variable.name
|
65
|
+
}
|
66
|
+
});
|
57
67
|
}
|
58
|
-
}
|
68
|
+
}
|
59
69
|
}
|
60
70
|
}
|
61
71
|
}
|
package/lib/rules/no-ternary.js
CHANGED