eslint 8.57.0 → 9.2.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 +31 -28
- package/bin/eslint.js +4 -3
- package/conf/ecma-version.js +16 -0
- package/conf/globals.js +1 -0
- package/conf/rule-type-list.json +3 -1
- package/lib/api.js +7 -11
- package/lib/cli-engine/cli-engine.js +14 -3
- package/lib/cli-engine/formatters/formatters-meta.json +1 -29
- package/lib/cli-engine/lint-result-cache.js +2 -2
- package/lib/cli.js +115 -36
- package/lib/config/default-config.js +3 -0
- package/lib/config/flat-config-array.js +110 -24
- package/lib/config/flat-config-helpers.js +41 -20
- package/lib/config/flat-config-schema.js +1 -7
- package/lib/config/rule-validator.js +42 -6
- package/lib/eslint/eslint-helpers.js +116 -58
- package/lib/eslint/eslint.js +892 -377
- package/lib/eslint/index.js +2 -2
- package/lib/eslint/legacy-eslint.js +728 -0
- package/lib/linter/apply-disable-directives.js +59 -31
- package/lib/linter/code-path-analysis/code-path-analyzer.js +0 -1
- package/lib/linter/code-path-analysis/code-path.js +32 -30
- package/lib/linter/code-path-analysis/fork-context.js +1 -1
- package/lib/linter/config-comment-parser.js +8 -11
- package/lib/linter/index.js +1 -3
- package/lib/linter/interpolate.js +24 -2
- package/lib/linter/linter.js +428 -207
- package/lib/linter/report-translator.js +3 -3
- package/lib/linter/rules.js +6 -15
- package/lib/linter/source-code-fixer.js +1 -1
- package/lib/linter/timing.js +16 -8
- package/lib/options.js +35 -3
- package/lib/rule-tester/index.js +3 -1
- package/lib/rule-tester/rule-tester.js +424 -347
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/block-scoped-var.js +1 -1
- package/lib/rules/callback-return.js +2 -2
- package/lib/rules/camelcase.js +3 -5
- package/lib/rules/capitalized-comments.js +10 -7
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-style.js +2 -2
- package/lib/rules/complexity.js +14 -1
- package/lib/rules/constructor-super.js +99 -100
- package/lib/rules/default-case.js +1 -1
- package/lib/rules/eol-last.js +2 -2
- package/lib/rules/function-paren-newline.js +2 -2
- package/lib/rules/indent-legacy.js +5 -5
- package/lib/rules/indent.js +5 -5
- package/lib/rules/index.js +1 -2
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/lines-around-directive.js +2 -2
- package/lib/rules/max-depth.js +1 -1
- package/lib/rules/max-len.js +3 -3
- package/lib/rules/max-lines.js +3 -3
- package/lib/rules/max-nested-callbacks.js +1 -1
- package/lib/rules/max-params.js +1 -1
- package/lib/rules/max-statements.js +1 -1
- package/lib/rules/multiline-comment-style.js +7 -7
- package/lib/rules/new-cap.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-before-return.js +1 -1
- package/lib/rules/no-case-declarations.js +13 -1
- package/lib/rules/no-constant-binary-expression.js +7 -8
- package/lib/rules/no-constant-condition.js +18 -7
- package/lib/rules/no-constructor-return.js +2 -2
- package/lib/rules/no-dupe-class-members.js +2 -2
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-function.js +2 -2
- package/lib/rules/no-empty-static-block.js +1 -1
- package/lib/rules/no-extend-native.js +1 -2
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-fallthrough.js +41 -16
- package/lib/rules/no-implicit-coercion.js +66 -24
- package/lib/rules/no-inner-declarations.js +23 -2
- package/lib/rules/no-invalid-regexp.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-lone-blocks.js +3 -3
- package/lib/rules/no-loss-of-precision.js +1 -1
- package/lib/rules/no-misleading-character-class.js +225 -69
- package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
- package/lib/rules/no-multiple-empty-lines.js +1 -1
- package/lib/rules/no-new-native-nonconstructor.js +1 -1
- package/lib/rules/no-new-symbol.js +8 -1
- package/lib/rules/no-restricted-globals.js +1 -1
- package/lib/rules/no-restricted-imports.js +186 -40
- package/lib/rules/no-restricted-modules.js +2 -2
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-sequences.js +1 -0
- package/lib/rules/no-this-before-super.js +45 -13
- package/lib/rules/no-trailing-spaces.js +2 -3
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-optional-chaining.js +1 -1
- package/lib/rules/no-unused-private-class-members.js +1 -1
- package/lib/rules/no-unused-vars.js +197 -36
- package/lib/rules/no-useless-assignment.js +566 -0
- package/lib/rules/no-useless-backreference.js +1 -1
- package/lib/rules/no-useless-computed-key.js +2 -2
- package/lib/rules/no-useless-return.js +7 -2
- package/lib/rules/object-curly-spacing.js +3 -3
- package/lib/rules/object-property-newline.js +1 -1
- package/lib/rules/one-var.js +5 -5
- package/lib/rules/padded-blocks.js +7 -7
- package/lib/rules/prefer-arrow-callback.js +3 -3
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-regex-literals.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/radix.js +2 -2
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/sort-imports.js +1 -1
- package/lib/rules/sort-keys.js +1 -1
- package/lib/rules/sort-vars.js +1 -1
- package/lib/rules/space-unary-ops.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/use-isnan.js +101 -7
- package/lib/rules/utils/ast-utils.js +16 -7
- package/lib/rules/utils/char-source.js +240 -0
- package/lib/rules/utils/lazy-loading-rule-map.js +1 -1
- package/lib/rules/utils/unicode/index.js +9 -4
- package/lib/rules/yield-star-spacing.js +1 -1
- package/lib/shared/runtime-info.js +1 -0
- package/lib/shared/serialization.js +55 -0
- package/lib/shared/stats.js +30 -0
- package/lib/shared/string-utils.js +9 -11
- package/lib/shared/types.js +35 -1
- package/lib/source-code/index.js +3 -1
- package/lib/source-code/source-code.js +299 -85
- package/lib/source-code/token-store/backward-token-cursor.js +3 -3
- package/lib/source-code/token-store/cursors.js +4 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +3 -3
- package/lib/source-code/token-store/forward-token-cursor.js +3 -3
- package/lib/source-code/token-store/index.js +2 -2
- package/lib/unsupported-api.js +3 -5
- package/messages/no-config-found.js +1 -1
- package/messages/plugin-conflict.js +1 -1
- package/messages/plugin-invalid.js +1 -1
- package/messages/plugin-missing.js +1 -1
- package/package.json +32 -29
- package/conf/config-schema.js +0 -93
- package/lib/cli-engine/formatters/checkstyle.js +0 -60
- package/lib/cli-engine/formatters/compact.js +0 -60
- package/lib/cli-engine/formatters/jslint-xml.js +0 -41
- package/lib/cli-engine/formatters/junit.js +0 -82
- package/lib/cli-engine/formatters/tap.js +0 -95
- package/lib/cli-engine/formatters/unix.js +0 -58
- package/lib/cli-engine/formatters/visualstudio.js +0 -63
- package/lib/cli-engine/xml-escape.js +0 -34
- package/lib/eslint/flat-eslint.js +0 -1155
- package/lib/rule-tester/flat-rule-tester.js +0 -1131
- package/lib/rules/require-jsdoc.js +0 -122
- package/lib/rules/utils/patterns/letters.js +0 -36
- package/lib/rules/valid-jsdoc.js +0 -516
- package/lib/shared/config-validator.js +0 -347
- package/lib/shared/deprecation-warnings.js +0 -58
- package/lib/shared/relative-module-resolver.js +0 -50
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
const assert = require("assert");
|
13
13
|
const ruleFixer = require("./rule-fixer");
|
14
|
-
const interpolate = require("./interpolate");
|
14
|
+
const { interpolate } = require("./interpolate");
|
15
15
|
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
// Typedefs
|
@@ -160,7 +160,7 @@ function mergeFixes(fixes, sourceCode) {
|
|
160
160
|
|
161
161
|
const originalText = sourceCode.text;
|
162
162
|
const start = fixes[0].range[0];
|
163
|
-
const end = fixes
|
163
|
+
const end = fixes.at(-1).range[1];
|
164
164
|
let text = "";
|
165
165
|
let lastPos = Number.MIN_SAFE_INTEGER;
|
166
166
|
|
@@ -343,7 +343,7 @@ module.exports = function createReportTranslator(metadata) {
|
|
343
343
|
if (descriptor.message) {
|
344
344
|
throw new TypeError("context.report() called with a message and a messageId. Please only pass one.");
|
345
345
|
}
|
346
|
-
if (!messages || !Object.
|
346
|
+
if (!messages || !Object.hasOwn(messages, id)) {
|
347
347
|
throw new TypeError(`context.report() called with a messageId of '${id}' which is not present in the 'messages' config: ${JSON.stringify(messages, null, 2)}`);
|
348
348
|
}
|
349
349
|
computedMessage = messages[id];
|
package/lib/linter/rules.js
CHANGED
@@ -13,18 +13,10 @@
|
|
13
13
|
const builtInRules = require("../rules");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
|
-
//
|
16
|
+
// Typedefs
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
-
/**
|
20
|
-
* Normalizes a rule module to the new-style API
|
21
|
-
* @param {(Function|{create: Function})} rule A rule object, which can either be a function
|
22
|
-
* ("old-style") or an object with a `create` method ("new-style")
|
23
|
-
* @returns {{create: Function}} A new-style rule.
|
24
|
-
*/
|
25
|
-
function normalizeRule(rule) {
|
26
|
-
return typeof rule === "function" ? Object.assign({ create: rule }, rule) : rule;
|
27
|
-
}
|
19
|
+
/** @typedef {import("../shared/types").Rule} Rule */
|
28
20
|
|
29
21
|
//------------------------------------------------------------------------------
|
30
22
|
// Public Interface
|
@@ -41,18 +33,17 @@ class Rules {
|
|
41
33
|
/**
|
42
34
|
* Registers a rule module for rule id in storage.
|
43
35
|
* @param {string} ruleId Rule id (file name).
|
44
|
-
* @param {
|
36
|
+
* @param {Rule} rule Rule object.
|
45
37
|
* @returns {void}
|
46
38
|
*/
|
47
|
-
define(ruleId,
|
48
|
-
this._rules[ruleId] =
|
39
|
+
define(ruleId, rule) {
|
40
|
+
this._rules[ruleId] = rule;
|
49
41
|
}
|
50
42
|
|
51
43
|
/**
|
52
44
|
* Access rule handler by id (file name).
|
53
45
|
* @param {string} ruleId Rule id (file name).
|
54
|
-
* @returns {
|
55
|
-
* A rule. This is normalized to always have the new-style shape with a `create` method.
|
46
|
+
* @returns {Rule} Rule object.
|
56
47
|
*/
|
57
48
|
get(ruleId) {
|
58
49
|
if (typeof this._rules[ruleId] === "string") {
|
@@ -107,7 +107,7 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
|
|
107
107
|
}
|
108
108
|
|
109
109
|
messages.forEach(problem => {
|
110
|
-
if (Object.
|
110
|
+
if (Object.hasOwn(problem, "fix")) {
|
111
111
|
fixes.push(problem);
|
112
112
|
} else {
|
113
113
|
remainingMessages.push(problem);
|
package/lib/linter/timing.js
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { startTime, endTime } = require("../shared/stats");
|
9
|
+
|
8
10
|
//------------------------------------------------------------------------------
|
9
11
|
// Helpers
|
10
12
|
//------------------------------------------------------------------------------
|
@@ -128,21 +130,27 @@ module.exports = (function() {
|
|
128
130
|
* Time the run
|
129
131
|
* @param {any} key key from the data object
|
130
132
|
* @param {Function} fn function to be called
|
133
|
+
* @param {boolean} stats if 'stats' is true, return the result and the time difference
|
131
134
|
* @returns {Function} function to be executed
|
132
135
|
* @private
|
133
136
|
*/
|
134
|
-
function time(key, fn) {
|
135
|
-
if (typeof data[key] === "undefined") {
|
136
|
-
data[key] = 0;
|
137
|
-
}
|
137
|
+
function time(key, fn, stats) {
|
138
138
|
|
139
139
|
return function(...args) {
|
140
|
-
|
140
|
+
|
141
|
+
const t = startTime();
|
141
142
|
const result = fn(...args);
|
143
|
+
const tdiff = endTime(t);
|
144
|
+
|
145
|
+
if (enabled) {
|
146
|
+
if (typeof data[key] === "undefined") {
|
147
|
+
data[key] = 0;
|
148
|
+
}
|
149
|
+
|
150
|
+
data[key] += tdiff;
|
151
|
+
}
|
142
152
|
|
143
|
-
|
144
|
-
data[key] += t[0] * 1e3 + t[1] / 1e6;
|
145
|
-
return result;
|
153
|
+
return stats ? { result, tdiff } : result;
|
146
154
|
};
|
147
155
|
}
|
148
156
|
|
package/lib/options.js
CHANGED
@@ -38,7 +38,7 @@ const optionator = require("optionator");
|
|
38
38
|
* @property {boolean} [help] Show help
|
39
39
|
* @property {boolean} ignore Disable use of ignore files and patterns
|
40
40
|
* @property {string} [ignorePath] Specify path of ignore file
|
41
|
-
* @property {string[]} [ignorePattern]
|
41
|
+
* @property {string[]} [ignorePattern] Patterns of files to ignore. In eslintrc mode, these are in addition to `.eslintignore`
|
42
42
|
* @property {boolean} init Run config initialization wizard
|
43
43
|
* @property {boolean} inlineConfig Prevent comments from changing config or rules
|
44
44
|
* @property {number} maxWarnings Number of warnings to trigger nonzero exit code
|
@@ -57,7 +57,10 @@ const optionator = require("optionator");
|
|
57
57
|
* @property {boolean} quiet Report errors only
|
58
58
|
* @property {boolean} [version] Output the version number
|
59
59
|
* @property {boolean} warnIgnored Show warnings when the file list includes ignored files
|
60
|
+
* @property {boolean} [passOnNoPatterns=false] When set to true, missing patterns cause
|
61
|
+
* the linting operation to short circuit and not report any failures.
|
60
62
|
* @property {string[]} _ Positional filenames or patterns
|
63
|
+
* @property {boolean} [stats] Report additional statistics
|
61
64
|
*/
|
62
65
|
|
63
66
|
//------------------------------------------------------------------------------
|
@@ -101,6 +104,16 @@ module.exports = function(usingFlatConfig) {
|
|
101
104
|
};
|
102
105
|
}
|
103
106
|
|
107
|
+
let inspectConfigFlag;
|
108
|
+
|
109
|
+
if (usingFlatConfig) {
|
110
|
+
inspectConfigFlag = {
|
111
|
+
option: "inspect-config",
|
112
|
+
type: "Boolean",
|
113
|
+
description: "Open the config inspector with the current configuration"
|
114
|
+
};
|
115
|
+
}
|
116
|
+
|
104
117
|
let extFlag;
|
105
118
|
|
106
119
|
if (!usingFlatConfig) {
|
@@ -141,6 +154,17 @@ module.exports = function(usingFlatConfig) {
|
|
141
154
|
};
|
142
155
|
}
|
143
156
|
|
157
|
+
let statsFlag;
|
158
|
+
|
159
|
+
if (usingFlatConfig) {
|
160
|
+
statsFlag = {
|
161
|
+
option: "stats",
|
162
|
+
type: "Boolean",
|
163
|
+
default: "false",
|
164
|
+
description: "Add statistics to the lint report"
|
165
|
+
};
|
166
|
+
}
|
167
|
+
|
144
168
|
let warnIgnoredFlag;
|
145
169
|
|
146
170
|
if (usingFlatConfig) {
|
@@ -171,6 +195,7 @@ module.exports = function(usingFlatConfig) {
|
|
171
195
|
? "Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs"
|
172
196
|
: "Use this configuration, overriding .eslintrc.* config options if present"
|
173
197
|
},
|
198
|
+
inspectConfigFlag,
|
174
199
|
envFlag,
|
175
200
|
extFlag,
|
176
201
|
{
|
@@ -236,7 +261,7 @@ module.exports = function(usingFlatConfig) {
|
|
236
261
|
{
|
237
262
|
option: "ignore-pattern",
|
238
263
|
type: "[String]",
|
239
|
-
description:
|
264
|
+
description: `Patterns of files to ignore${usingFlatConfig ? "" : " (in addition to those in .eslintignore)"}`,
|
240
265
|
concatRepeatedArrays: [true, {
|
241
266
|
oneValuePerFlag: true
|
242
267
|
}]
|
@@ -370,6 +395,12 @@ module.exports = function(usingFlatConfig) {
|
|
370
395
|
description: "Exit with exit code 2 in case of fatal error"
|
371
396
|
},
|
372
397
|
warnIgnoredFlag,
|
398
|
+
{
|
399
|
+
option: "pass-on-no-patterns",
|
400
|
+
type: "Boolean",
|
401
|
+
default: false,
|
402
|
+
description: "Exit with exit code 0 in case no file patterns are passed"
|
403
|
+
},
|
373
404
|
{
|
374
405
|
option: "debug",
|
375
406
|
type: "Boolean",
|
@@ -392,7 +423,8 @@ module.exports = function(usingFlatConfig) {
|
|
392
423
|
option: "print-config",
|
393
424
|
type: "path::String",
|
394
425
|
description: "Print the configuration for the given file"
|
395
|
-
}
|
426
|
+
},
|
427
|
+
statsFlag
|
396
428
|
].filter(value => !!value)
|
397
429
|
});
|
398
430
|
};
|