eslint 10.2.1 → 10.4.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 +3 -3
- package/lib/config/config-loader.js +1 -1
- package/lib/config-api.js +7 -1
- package/lib/eslint/eslint.js +29 -6
- package/lib/linter/code-path-analysis/code-path-analyzer.js +7 -7
- package/lib/linter/code-path-analysis/debug-helpers.js +12 -1
- package/lib/linter/code-path-analysis/id-generator.js +1 -2
- package/lib/rules/capitalized-comments.js +3 -1
- package/lib/rules/class-methods-use-this.js +1 -2
- package/lib/rules/default-param-last.js +1 -2
- package/lib/rules/eqeqeq.js +3 -1
- package/lib/rules/for-direction.js +55 -11
- package/lib/rules/func-name-matching.js +2 -0
- package/lib/rules/func-style.js +1 -2
- package/lib/rules/init-declarations.js +7 -8
- package/lib/rules/logical-assignment-operators.js +4 -1
- package/lib/rules/max-classes-per-file.js +4 -2
- package/lib/rules/max-depth.js +3 -0
- package/lib/rules/max-lines-per-function.js +3 -0
- package/lib/rules/max-lines.js +3 -0
- package/lib/rules/max-nested-callbacks.js +3 -0
- package/lib/rules/max-params.js +4 -2
- package/lib/rules/max-statements.js +3 -0
- package/lib/rules/no-array-constructor.js +1 -2
- package/lib/rules/no-dupe-class-members.js +1 -2
- package/lib/rules/no-duplicate-imports.js +1 -2
- package/lib/rules/no-empty-function.js +1 -2
- package/lib/rules/no-invalid-this.js +1 -2
- package/lib/rules/no-loop-func.js +1 -2
- package/lib/rules/no-loss-of-precision.js +1 -2
- package/lib/rules/no-magic-numbers.js +29 -24
- package/lib/rules/no-restricted-exports.js +8 -8
- package/lib/rules/no-restricted-globals.js +1 -2
- package/lib/rules/no-restricted-imports.js +1 -2
- package/lib/rules/no-restricted-properties.js +2 -0
- package/lib/rules/no-restricted-syntax.js +2 -0
- package/lib/rules/no-shadow.js +1 -2
- package/lib/rules/no-unassigned-vars.js +1 -2
- package/lib/rules/no-unused-expressions.js +1 -2
- package/lib/rules/no-unused-private-class-members.js +201 -1
- package/lib/rules/no-unused-vars.js +50 -53
- package/lib/rules/no-use-before-define.js +1 -2
- package/lib/rules/no-useless-concat.js +2 -2
- package/lib/rules/no-useless-constructor.js +4 -4
- package/lib/rules/no-var.js +1 -2
- package/lib/rules/object-shorthand.js +3 -1
- package/lib/rules/one-var.js +3 -1
- package/lib/rules/prefer-arrow-callback.js +1 -2
- package/lib/rules/require-await.js +6 -4
- package/lib/rules/utils/ast-utils.js +36 -4
- package/lib/types/config-api.d.ts +2 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -315,8 +315,8 @@ Tanuj Kanti
|
|
|
315
315
|
</a>
|
|
316
316
|
</td><td align="center" valign="top" width="11%">
|
|
317
317
|
<a href="https://github.com/lumirlumir">
|
|
318
|
-
<img src="https://github.com/lumirlumir.png?s=75" width="75" height="75" alt="
|
|
319
|
-
|
|
318
|
+
<img src="https://github.com/lumirlumir.png?s=75" width="75" height="75" alt="lumir's Avatar"><br />
|
|
319
|
+
lumir
|
|
320
320
|
</a>
|
|
321
321
|
</td><td align="center" valign="top" width="11%">
|
|
322
322
|
<a href="https://github.com/Pixel998">
|
|
@@ -360,7 +360,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
|
360
360
|
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
|
361
361
|
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3>
|
|
362
362
|
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
|
363
|
-
<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://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" 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://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
|
363
|
+
<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://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" 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://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://citadel.co.jp"><img src="https://avatars.githubusercontent.com/u/75781367" alt="Citadel AI" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
|
364
364
|
<h3>Technology Sponsors</h3>
|
|
365
365
|
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.
|
|
366
366
|
<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>
|
|
@@ -230,7 +230,7 @@ async function loadConfigFile(filePath, hasUnstableNativeNodeJsTSConfigFlag) {
|
|
|
230
230
|
* the require cache only if the file has been changed.
|
|
231
231
|
*/
|
|
232
232
|
if (importedConfigFileModificationTime.get(filePath) !== mtime) {
|
|
233
|
-
delete require.cache[filePath];
|
|
233
|
+
delete require.cache?.[filePath];
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
const isTS = isFileTS(filePath);
|
package/lib/config-api.js
CHANGED
|
@@ -4,9 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
defineConfig,
|
|
10
|
+
globalIgnores,
|
|
11
|
+
includeIgnoreFile,
|
|
12
|
+
} = require("@eslint/config-helpers");
|
|
8
13
|
|
|
9
14
|
module.exports = {
|
|
10
15
|
defineConfig,
|
|
11
16
|
globalIgnores,
|
|
17
|
+
includeIgnoreFile,
|
|
12
18
|
};
|
package/lib/eslint/eslint.js
CHANGED
|
@@ -107,6 +107,34 @@ function createRulesMeta(rules) {
|
|
|
107
107
|
}, {});
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Gets the replacement rule names from a deprecated rule's metadata.
|
|
112
|
+
* @param {RulesMeta} meta The rule metadata.
|
|
113
|
+
* @returns {string[]} Replacement rule names.
|
|
114
|
+
*/
|
|
115
|
+
function getDeprecatedRuleReplacements(meta) {
|
|
116
|
+
if (typeof meta.deprecated !== "object") {
|
|
117
|
+
return meta.replacedBy || [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const { replacedBy } = meta.deprecated;
|
|
121
|
+
|
|
122
|
+
if (!Array.isArray(replacedBy)) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return replacedBy.map(replacement => {
|
|
127
|
+
if (typeof replacement !== "object" || replacement === null) {
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const pluginName = replacement.plugin?.name;
|
|
132
|
+
const ruleName = replacement.rule?.name;
|
|
133
|
+
|
|
134
|
+
return `${typeof pluginName === "string" ? `${getShorthandName(pluginName, "eslint-plugin")}/` : ""}${typeof ruleName === "string" ? ruleName : ""}`;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
110
138
|
/** @type {WeakMap<CalculatedConfig, DeprecatedRuleInfo[]>} */
|
|
111
139
|
const usedDeprecatedRulesCache = new WeakMap();
|
|
112
140
|
|
|
@@ -144,12 +172,7 @@ function getOrFindUsedDeprecatedRules(eslint, maybeFilePath) {
|
|
|
144
172
|
|
|
145
173
|
retv.push({
|
|
146
174
|
ruleId,
|
|
147
|
-
replacedBy:
|
|
148
|
-
? (meta.deprecated.replacedBy?.map(
|
|
149
|
-
replacement =>
|
|
150
|
-
`${replacement.plugin?.name !== void 0 ? `${getShorthandName(replacement.plugin.name, "eslint-plugin")}/` : ""}${replacement.rule?.name ?? ""}`,
|
|
151
|
-
) ?? [])
|
|
152
|
-
: meta.replacedBy || [],
|
|
175
|
+
replacedBy: getDeprecatedRuleReplacements(meta),
|
|
153
176
|
info: usesNewFormat ? meta.deprecated : void 0,
|
|
154
177
|
});
|
|
155
178
|
}
|
|
@@ -77,8 +77,8 @@ function getLabel(node) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Checks whether
|
|
81
|
-
*
|
|
80
|
+
* Checks whether a given logical expression node takes different paths for the
|
|
81
|
+
* `true` and `false` cases.
|
|
82
82
|
* @param {ASTNode} node A node to check.
|
|
83
83
|
* @returns {boolean} `true` if the node is a test of a choice statement.
|
|
84
84
|
*/
|
|
@@ -107,8 +107,8 @@ function isForkingByTrueOrFalse(node) {
|
|
|
107
107
|
/**
|
|
108
108
|
* Gets the boolean value of a given literal node.
|
|
109
109
|
*
|
|
110
|
-
* This is used to detect
|
|
111
|
-
* Statements preceded by an
|
|
110
|
+
* This is used to detect infinite loops (e.g. `while (true) {}`).
|
|
111
|
+
* Statements preceded by an infinite loop are unreachable if the loop didn't
|
|
112
112
|
* have any `break` statement.
|
|
113
113
|
* @param {ASTNode} node A node to get.
|
|
114
114
|
* @returns {boolean|undefined} a boolean value if the node is a Literal node,
|
|
@@ -221,8 +221,8 @@ function forwardCurrentToHead(analyzer, node) {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
|
-
* Updates the current segment with empty.
|
|
225
|
-
* This is called
|
|
224
|
+
* Updates the current segment with an empty array.
|
|
225
|
+
* This is called when a code path ends.
|
|
226
226
|
* @param {CodePathAnalyzer} analyzer The instance.
|
|
227
227
|
* @param {ASTNode} node The current AST node.
|
|
228
228
|
* @returns {void}
|
|
@@ -727,7 +727,7 @@ function postprocess(analyzer, node) {
|
|
|
727
727
|
* a = () => {}
|
|
728
728
|
* }
|
|
729
729
|
*
|
|
730
|
-
* In this case,
|
|
730
|
+
* In this case, the ArrowFunctionExpression code path is closed first,
|
|
731
731
|
* and then we need to close the code path for the PropertyDefinition
|
|
732
732
|
* value.
|
|
733
733
|
*/
|
|
@@ -45,6 +45,15 @@ function nodeToString(node, label) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Escape text for use in a DOT label.
|
|
50
|
+
* @param {string} value The value to escape.
|
|
51
|
+
* @returns {string} The escaped value.
|
|
52
|
+
*/
|
|
53
|
+
function escapeDotLabelText(value) {
|
|
54
|
+
return value.replace(/\\/gu, String.raw`\\`).replace(/"/gu, String.raw`\"`);
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
//------------------------------------------------------------------------------
|
|
49
58
|
// Public Interface
|
|
50
59
|
//------------------------------------------------------------------------------
|
|
@@ -147,7 +156,9 @@ module.exports = {
|
|
|
147
156
|
}
|
|
148
157
|
|
|
149
158
|
if (segment.internal.nodes.length > 0) {
|
|
150
|
-
text += segment.internal.nodes
|
|
159
|
+
text += segment.internal.nodes
|
|
160
|
+
.map(escapeDotLabelText)
|
|
161
|
+
.join("\\n");
|
|
151
162
|
} else {
|
|
152
163
|
text += "????";
|
|
153
164
|
}
|
|
@@ -131,6 +131,8 @@ module.exports = {
|
|
|
131
131
|
},
|
|
132
132
|
],
|
|
133
133
|
|
|
134
|
+
defaultOptions: ["always"],
|
|
135
|
+
|
|
134
136
|
messages: {
|
|
135
137
|
unexpectedLowercaseComment:
|
|
136
138
|
"Comments should not begin with a lowercase character.",
|
|
@@ -140,7 +142,7 @@ module.exports = {
|
|
|
140
142
|
},
|
|
141
143
|
|
|
142
144
|
create(context) {
|
|
143
|
-
const capitalize = context.options[0]
|
|
145
|
+
const capitalize = context.options[0],
|
|
144
146
|
normalizedOptions = getAllNormalizedOptions(context.options[1]),
|
|
145
147
|
sourceCode = context.sourceCode;
|
|
146
148
|
|
|
@@ -18,8 +18,6 @@ const astUtils = require("./utils/ast-utils");
|
|
|
18
18
|
/** @type {import('../types').Rule.RuleModule} */
|
|
19
19
|
module.exports = {
|
|
20
20
|
meta: {
|
|
21
|
-
dialects: ["javascript", "typescript"],
|
|
22
|
-
language: "javascript",
|
|
23
21
|
type: "suggestion",
|
|
24
22
|
|
|
25
23
|
defaultOptions: [
|
|
@@ -32,6 +30,7 @@ module.exports = {
|
|
|
32
30
|
|
|
33
31
|
docs: {
|
|
34
32
|
description: "Enforce that class methods utilize `this`",
|
|
33
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
35
34
|
recommended: false,
|
|
36
35
|
url: "https://eslint.org/docs/latest/rules/class-methods-use-this",
|
|
37
36
|
},
|
|
@@ -21,12 +21,11 @@ function isRequiredParameter(node) {
|
|
|
21
21
|
/** @type {import('../types').Rule.RuleModule} */
|
|
22
22
|
module.exports = {
|
|
23
23
|
meta: {
|
|
24
|
-
dialects: ["javascript", "typescript"],
|
|
25
|
-
language: "javascript",
|
|
26
24
|
type: "suggestion",
|
|
27
25
|
|
|
28
26
|
docs: {
|
|
29
27
|
description: "Enforce default parameters to be last",
|
|
28
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
30
29
|
recommended: false,
|
|
31
30
|
frozen: true,
|
|
32
31
|
url: "https://eslint.org/docs/latest/rules/default-param-last",
|
package/lib/rules/eqeqeq.js
CHANGED
|
@@ -59,6 +59,8 @@ module.exports = {
|
|
|
59
59
|
],
|
|
60
60
|
},
|
|
61
61
|
|
|
62
|
+
defaultOptions: ["always"],
|
|
63
|
+
|
|
62
64
|
fixable: "code",
|
|
63
65
|
|
|
64
66
|
messages: {
|
|
@@ -70,7 +72,7 @@ module.exports = {
|
|
|
70
72
|
},
|
|
71
73
|
|
|
72
74
|
create(context) {
|
|
73
|
-
const config = context.options[0]
|
|
75
|
+
const config = context.options[0];
|
|
74
76
|
const options = context.options[1] || {};
|
|
75
77
|
const sourceCode = context.sourceCode;
|
|
76
78
|
|
|
@@ -117,6 +117,50 @@ module.exports = {
|
|
|
117
117
|
}
|
|
118
118
|
return 0;
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Collects all expressions that modify the counter.
|
|
122
|
+
* @param {ASTNode} node The expression node to check.
|
|
123
|
+
* @param {string} counter The name of the counter variable.
|
|
124
|
+
* @returns {ASTNode[]} An array of modifying expressions.
|
|
125
|
+
*/
|
|
126
|
+
function getModifyingExpressions(node, counter) {
|
|
127
|
+
if (node.type === "SequenceExpression") {
|
|
128
|
+
return node.expressions.flatMap(expr =>
|
|
129
|
+
getModifyingExpressions(expr, counter),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (
|
|
133
|
+
node.type === "UpdateExpression" &&
|
|
134
|
+
node.argument.type === "Identifier" &&
|
|
135
|
+
node.argument.name === counter
|
|
136
|
+
) {
|
|
137
|
+
return [node];
|
|
138
|
+
}
|
|
139
|
+
if (
|
|
140
|
+
node.type === "AssignmentExpression" &&
|
|
141
|
+
node.left.type === "Identifier" &&
|
|
142
|
+
node.left.name === counter
|
|
143
|
+
) {
|
|
144
|
+
return [node];
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Determines the direction of a single update expression for the counter.
|
|
151
|
+
* @param {ASTNode} expr An expression node to check (UpdateExpression or AssignmentExpression).
|
|
152
|
+
* @param {string} counter The variable name of the counter.
|
|
153
|
+
* @returns {number} 1 if incrementing, -1 if decrementing, 0 if unknown or not modifying the counter.
|
|
154
|
+
*/
|
|
155
|
+
function getDirectionFromExpression(expr, counter) {
|
|
156
|
+
if (expr.type === "UpdateExpression") {
|
|
157
|
+
return getUpdateDirection(expr, counter);
|
|
158
|
+
}
|
|
159
|
+
if (expr.type === "AssignmentExpression") {
|
|
160
|
+
return getAssignmentDirection(expr, counter);
|
|
161
|
+
}
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
120
164
|
|
|
121
165
|
return {
|
|
122
166
|
ForStatement(node) {
|
|
@@ -146,17 +190,17 @@ module.exports = {
|
|
|
146
190
|
return;
|
|
147
191
|
}
|
|
148
192
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
193
|
+
const mutatingExpressions = getModifyingExpressions(
|
|
194
|
+
update,
|
|
195
|
+
counter,
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
if (
|
|
199
|
+
mutatingExpressions.length === 1 &&
|
|
200
|
+
getDirectionFromExpression(
|
|
201
|
+
mutatingExpressions[0],
|
|
202
|
+
counter,
|
|
203
|
+
) === wrongDirection
|
|
160
204
|
) {
|
|
161
205
|
report(node);
|
|
162
206
|
}
|
package/lib/rules/func-style.js
CHANGED
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
/** @type {import('../types').Rule.RuleModule} */
|
|
12
12
|
module.exports = {
|
|
13
13
|
meta: {
|
|
14
|
-
dialects: ["javascript", "typescript"],
|
|
15
|
-
language: "javascript",
|
|
16
14
|
type: "suggestion",
|
|
17
15
|
|
|
18
16
|
defaultOptions: [
|
|
@@ -27,6 +25,7 @@ module.exports = {
|
|
|
27
25
|
docs: {
|
|
28
26
|
description:
|
|
29
27
|
"Enforce the consistent use of either `function` declarations or expressions assigned to variables",
|
|
28
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
30
29
|
recommended: false,
|
|
31
30
|
frozen: true,
|
|
32
31
|
url: "https://eslint.org/docs/latest/rules/func-style",
|
|
@@ -50,12 +50,11 @@ function isInitialized(node) {
|
|
|
50
50
|
module.exports = {
|
|
51
51
|
meta: {
|
|
52
52
|
type: "suggestion",
|
|
53
|
-
dialects: ["typescript", "javascript"],
|
|
54
|
-
language: "javascript",
|
|
55
53
|
|
|
56
54
|
docs: {
|
|
57
55
|
description:
|
|
58
56
|
"Require or disallow initialization in variable declarations",
|
|
57
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
59
58
|
recommended: false,
|
|
60
59
|
frozen: true,
|
|
61
60
|
url: "https://eslint.org/docs/latest/rules/init-declarations",
|
|
@@ -94,6 +93,9 @@ module.exports = {
|
|
|
94
93
|
},
|
|
95
94
|
],
|
|
96
95
|
},
|
|
96
|
+
|
|
97
|
+
defaultOptions: ["always"],
|
|
98
|
+
|
|
97
99
|
messages: {
|
|
98
100
|
initialized:
|
|
99
101
|
"Variable '{{idName}}' should be initialized on declaration.",
|
|
@@ -103,10 +105,7 @@ module.exports = {
|
|
|
103
105
|
},
|
|
104
106
|
|
|
105
107
|
create(context) {
|
|
106
|
-
const
|
|
107
|
-
MODE_NEVER = "never";
|
|
108
|
-
|
|
109
|
-
const mode = context.options[0] || MODE_ALWAYS;
|
|
108
|
+
const mode = context.options[0];
|
|
110
109
|
const params = context.options[1] || {};
|
|
111
110
|
|
|
112
111
|
// Track whether we're inside a declared namespace
|
|
@@ -145,10 +144,10 @@ module.exports = {
|
|
|
145
144
|
params.ignoreForLoopInit && isForLoop(node.parent);
|
|
146
145
|
let messageId = "";
|
|
147
146
|
|
|
148
|
-
if (mode ===
|
|
147
|
+
if (mode === "always" && !initialized) {
|
|
149
148
|
messageId = "initialized";
|
|
150
149
|
} else if (
|
|
151
|
-
mode ===
|
|
150
|
+
mode === "never" &&
|
|
152
151
|
!CONSTANT_BINDINGS.has(kind) &&
|
|
153
152
|
initialized &&
|
|
154
153
|
!isIgnoredForLoop
|
|
@@ -259,6 +259,9 @@ module.exports = {
|
|
|
259
259
|
},
|
|
260
260
|
],
|
|
261
261
|
},
|
|
262
|
+
|
|
263
|
+
defaultOptions: ["always"],
|
|
264
|
+
|
|
262
265
|
fixable: "code",
|
|
263
266
|
hasSuggestions: true,
|
|
264
267
|
messages: {
|
|
@@ -281,7 +284,7 @@ module.exports = {
|
|
|
281
284
|
},
|
|
282
285
|
|
|
283
286
|
create(context) {
|
|
284
|
-
const mode = context.options[0]
|
|
287
|
+
const mode = context.options[0];
|
|
285
288
|
const checkIf =
|
|
286
289
|
mode === "always" &&
|
|
287
290
|
context.options.length > 1 &&
|
|
@@ -47,16 +47,18 @@ module.exports = {
|
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
|
|
50
|
+
defaultOptions: [1],
|
|
51
|
+
|
|
50
52
|
messages: {
|
|
51
53
|
maximumExceeded:
|
|
52
54
|
"File has too many classes ({{ classCount }}). Maximum allowed is {{ max }}.",
|
|
53
55
|
},
|
|
54
56
|
},
|
|
55
57
|
create(context) {
|
|
56
|
-
const
|
|
58
|
+
const option = context.options[0];
|
|
57
59
|
const [ignoreExpressions, max] =
|
|
58
60
|
typeof option === "number"
|
|
59
|
-
? [false, option
|
|
61
|
+
? [false, option]
|
|
60
62
|
: [option.ignoreExpressions, option.max || 1];
|
|
61
63
|
|
|
62
64
|
let classCount = 0;
|
package/lib/rules/max-depth.js
CHANGED
package/lib/rules/max-lines.js
CHANGED
package/lib/rules/max-params.js
CHANGED
|
@@ -20,12 +20,11 @@ const { upperCaseFirst } = require("../shared/string-utils");
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
meta: {
|
|
22
22
|
type: "suggestion",
|
|
23
|
-
dialects: ["typescript", "javascript"],
|
|
24
|
-
language: "javascript",
|
|
25
23
|
|
|
26
24
|
docs: {
|
|
27
25
|
description:
|
|
28
26
|
"Enforce a maximum number of parameters in function definitions",
|
|
27
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
29
28
|
recommended: false,
|
|
30
29
|
url: "https://eslint.org/docs/latest/rules/max-params",
|
|
31
30
|
},
|
|
@@ -65,6 +64,9 @@ module.exports = {
|
|
|
65
64
|
],
|
|
66
65
|
},
|
|
67
66
|
],
|
|
67
|
+
|
|
68
|
+
defaultOptions: [3],
|
|
69
|
+
|
|
68
70
|
messages: {
|
|
69
71
|
exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}.",
|
|
70
72
|
},
|
|
@@ -24,12 +24,11 @@ const {
|
|
|
24
24
|
/** @type {import('../types').Rule.RuleModule} */
|
|
25
25
|
module.exports = {
|
|
26
26
|
meta: {
|
|
27
|
-
dialects: ["javascript", "typescript"],
|
|
28
|
-
language: "javascript",
|
|
29
27
|
type: "suggestion",
|
|
30
28
|
|
|
31
29
|
docs: {
|
|
32
30
|
description: "Disallow `Array` constructors",
|
|
31
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
33
32
|
recommended: false,
|
|
34
33
|
url: "https://eslint.org/docs/latest/rules/no-array-constructor",
|
|
35
34
|
},
|
|
@@ -15,11 +15,10 @@ const astUtils = require("./utils/ast-utils");
|
|
|
15
15
|
module.exports = {
|
|
16
16
|
meta: {
|
|
17
17
|
type: "problem",
|
|
18
|
-
dialects: ["javascript", "typescript"],
|
|
19
|
-
language: "javascript",
|
|
20
18
|
|
|
21
19
|
docs: {
|
|
22
20
|
description: "Disallow duplicate class members",
|
|
21
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
23
22
|
recommended: true,
|
|
24
23
|
url: "https://eslint.org/docs/latest/rules/no-dupe-class-members",
|
|
25
24
|
},
|
|
@@ -294,8 +294,6 @@ function handleImportsExports(
|
|
|
294
294
|
/** @type {import('../types').Rule.RuleModule} */
|
|
295
295
|
module.exports = {
|
|
296
296
|
meta: {
|
|
297
|
-
dialects: ["javascript", "typescript"],
|
|
298
|
-
language: "javascript",
|
|
299
297
|
type: "problem",
|
|
300
298
|
|
|
301
299
|
defaultOptions: [
|
|
@@ -307,6 +305,7 @@ module.exports = {
|
|
|
307
305
|
|
|
308
306
|
docs: {
|
|
309
307
|
description: "Disallow duplicate module imports",
|
|
308
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
310
309
|
recommended: false,
|
|
311
310
|
url: "https://eslint.org/docs/latest/rules/no-duplicate-imports",
|
|
312
311
|
},
|
|
@@ -103,8 +103,6 @@ function isParameterPropertiesConstructor(node) {
|
|
|
103
103
|
/** @type {import('../types').Rule.RuleModule} */
|
|
104
104
|
module.exports = {
|
|
105
105
|
meta: {
|
|
106
|
-
dialects: ["javascript", "typescript"],
|
|
107
|
-
language: "javascript",
|
|
108
106
|
hasSuggestions: true,
|
|
109
107
|
type: "suggestion",
|
|
110
108
|
|
|
@@ -112,6 +110,7 @@ module.exports = {
|
|
|
112
110
|
|
|
113
111
|
docs: {
|
|
114
112
|
description: "Disallow empty functions",
|
|
113
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
115
114
|
recommended: false,
|
|
116
115
|
url: "https://eslint.org/docs/latest/rules/no-empty-function",
|
|
117
116
|
},
|
|
@@ -36,8 +36,6 @@ function isCodePathWithLexicalThis(codePath, node) {
|
|
|
36
36
|
/** @type {import('../types').Rule.RuleModule} */
|
|
37
37
|
module.exports = {
|
|
38
38
|
meta: {
|
|
39
|
-
dialects: ["javascript", "typescript"],
|
|
40
|
-
language: "javascript",
|
|
41
39
|
type: "suggestion",
|
|
42
40
|
|
|
43
41
|
defaultOptions: [{ capIsConstructor: true }],
|
|
@@ -45,6 +43,7 @@ module.exports = {
|
|
|
45
43
|
docs: {
|
|
46
44
|
description:
|
|
47
45
|
"Disallow use of `this` in contexts where the value of `this` is `undefined`",
|
|
46
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
48
47
|
recommended: false,
|
|
49
48
|
url: "https://eslint.org/docs/latest/rules/no-invalid-this",
|
|
50
49
|
},
|
|
@@ -40,12 +40,11 @@ function isIIFE(node) {
|
|
|
40
40
|
module.exports = {
|
|
41
41
|
meta: {
|
|
42
42
|
type: "suggestion",
|
|
43
|
-
dialects: ["typescript", "javascript"],
|
|
44
|
-
language: "javascript",
|
|
45
43
|
|
|
46
44
|
docs: {
|
|
47
45
|
description:
|
|
48
46
|
"Disallow function declarations that contain unsafe references inside loop statements",
|
|
47
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
49
48
|
recommended: false,
|
|
50
49
|
url: "https://eslint.org/docs/latest/rules/no-loop-func",
|
|
51
50
|
},
|
|
@@ -219,11 +219,10 @@ function losesPrecision(node) {
|
|
|
219
219
|
module.exports = {
|
|
220
220
|
meta: {
|
|
221
221
|
type: "problem",
|
|
222
|
-
dialects: ["typescript", "javascript"],
|
|
223
|
-
language: "javascript",
|
|
224
222
|
|
|
225
223
|
docs: {
|
|
226
224
|
description: "Disallow literal numbers that lose precision",
|
|
225
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
227
226
|
recommended: true,
|
|
228
227
|
url: "https://eslint.org/docs/latest/rules/no-loss-of-precision",
|
|
229
228
|
},
|