eslint 10.3.0 → 10.4.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/README.md +3 -3
- package/bin/eslint.js +28 -12
- package/lib/config-api.js +7 -1
- package/lib/eslint/eslint.js +29 -6
- package/lib/linter/code-path-analysis/code-path-analyzer.js +2 -2
- package/lib/linter/code-path-analysis/code-path-state.js +10 -6
- package/lib/linter/code-path-analysis/debug-helpers.js +12 -1
- 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-vars.js +50 -53
- package/lib/rules/no-use-before-define.js +1 -2
- package/lib/rules/no-useless-constructor.js +1 -2
- 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 +19 -10
- package/lib/types/config-api.d.ts +2 -1
- package/lib/types/index.d.ts +23 -0
- package/package.json +9 -5
|
@@ -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
|
},
|
|
@@ -91,11 +91,10 @@ function isAncestorTSIndexedAccessType(node) {
|
|
|
91
91
|
module.exports = {
|
|
92
92
|
meta: {
|
|
93
93
|
type: "suggestion",
|
|
94
|
-
dialects: ["typescript", "javascript"],
|
|
95
|
-
language: "javascript",
|
|
96
94
|
|
|
97
95
|
docs: {
|
|
98
96
|
description: "Disallow magic numbers",
|
|
97
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
99
98
|
recommended: false,
|
|
100
99
|
frozen: true,
|
|
101
100
|
url: "https://eslint.org/docs/latest/rules/no-magic-numbers",
|
|
@@ -107,11 +106,9 @@ module.exports = {
|
|
|
107
106
|
properties: {
|
|
108
107
|
detectObjects: {
|
|
109
108
|
type: "boolean",
|
|
110
|
-
default: false,
|
|
111
109
|
},
|
|
112
110
|
enforceConst: {
|
|
113
111
|
type: "boolean",
|
|
114
|
-
default: false,
|
|
115
112
|
},
|
|
116
113
|
ignore: {
|
|
117
114
|
type: "array",
|
|
@@ -128,37 +125,45 @@ module.exports = {
|
|
|
128
125
|
},
|
|
129
126
|
ignoreArrayIndexes: {
|
|
130
127
|
type: "boolean",
|
|
131
|
-
default: false,
|
|
132
128
|
},
|
|
133
129
|
ignoreDefaultValues: {
|
|
134
130
|
type: "boolean",
|
|
135
|
-
default: false,
|
|
136
131
|
},
|
|
137
132
|
ignoreClassFieldInitialValues: {
|
|
138
133
|
type: "boolean",
|
|
139
|
-
default: false,
|
|
140
134
|
},
|
|
141
135
|
ignoreEnums: {
|
|
142
136
|
type: "boolean",
|
|
143
|
-
default: false,
|
|
144
137
|
},
|
|
145
138
|
ignoreNumericLiteralTypes: {
|
|
146
139
|
type: "boolean",
|
|
147
|
-
default: false,
|
|
148
140
|
},
|
|
149
141
|
ignoreReadonlyClassProperties: {
|
|
150
142
|
type: "boolean",
|
|
151
|
-
default: false,
|
|
152
143
|
},
|
|
153
144
|
ignoreTypeIndexes: {
|
|
154
145
|
type: "boolean",
|
|
155
|
-
default: false,
|
|
156
146
|
},
|
|
157
147
|
},
|
|
158
148
|
additionalProperties: false,
|
|
159
149
|
},
|
|
160
150
|
],
|
|
161
151
|
|
|
152
|
+
defaultOptions: [
|
|
153
|
+
{
|
|
154
|
+
detectObjects: false,
|
|
155
|
+
enforceConst: false,
|
|
156
|
+
ignore: [],
|
|
157
|
+
ignoreArrayIndexes: false,
|
|
158
|
+
ignoreDefaultValues: false,
|
|
159
|
+
ignoreClassFieldInitialValues: false,
|
|
160
|
+
ignoreEnums: false,
|
|
161
|
+
ignoreNumericLiteralTypes: false,
|
|
162
|
+
ignoreReadonlyClassProperties: false,
|
|
163
|
+
ignoreTypeIndexes: false,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
|
|
162
167
|
messages: {
|
|
163
168
|
useConst: "Number constants declarations must use 'const'.",
|
|
164
169
|
noMagic: "No magic number: {{raw}}.",
|
|
@@ -166,19 +171,19 @@ module.exports = {
|
|
|
166
171
|
},
|
|
167
172
|
|
|
168
173
|
create(context) {
|
|
169
|
-
const
|
|
170
|
-
detectObjects
|
|
171
|
-
enforceConst
|
|
172
|
-
ignore
|
|
173
|
-
ignoreArrayIndexes
|
|
174
|
-
ignoreDefaultValues
|
|
175
|
-
ignoreClassFieldInitialValues
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
const {
|
|
175
|
+
detectObjects,
|
|
176
|
+
enforceConst,
|
|
177
|
+
ignore: rawIgnore,
|
|
178
|
+
ignoreArrayIndexes,
|
|
179
|
+
ignoreDefaultValues,
|
|
180
|
+
ignoreClassFieldInitialValues,
|
|
181
|
+
ignoreEnums,
|
|
182
|
+
ignoreNumericLiteralTypes,
|
|
183
|
+
ignoreReadonlyClassProperties,
|
|
184
|
+
ignoreTypeIndexes,
|
|
185
|
+
} = context.options[0];
|
|
186
|
+
const ignore = new Set(rawIgnore.map(normalizeIgnoreValue));
|
|
182
187
|
|
|
183
188
|
const okTypes = detectObjects
|
|
184
189
|
? []
|
|
@@ -92,6 +92,8 @@ module.exports = {
|
|
|
92
92
|
},
|
|
93
93
|
],
|
|
94
94
|
|
|
95
|
+
defaultOptions: [{}],
|
|
96
|
+
|
|
95
97
|
messages: {
|
|
96
98
|
restrictedNamed:
|
|
97
99
|
"'{{name}}' is restricted from being used as an exported name.",
|
|
@@ -100,14 +102,12 @@ module.exports = {
|
|
|
100
102
|
},
|
|
101
103
|
|
|
102
104
|
create(context) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const restrictDefaultExports =
|
|
110
|
-
context.options[0] && context.options[0].restrictDefaultExports;
|
|
105
|
+
const {
|
|
106
|
+
restrictedNamedExports,
|
|
107
|
+
restrictedNamedExportsPattern: restrictedNamePattern,
|
|
108
|
+
restrictDefaultExports,
|
|
109
|
+
} = context.options[0];
|
|
110
|
+
const restrictedNames = new Set(restrictedNamedExports);
|
|
111
111
|
const sourceCode = context.sourceCode;
|
|
112
112
|
|
|
113
113
|
/**
|
|
@@ -53,12 +53,11 @@ const arrayOfGlobals = {
|
|
|
53
53
|
/** @type {import('../types').Rule.RuleModule} */
|
|
54
54
|
module.exports = {
|
|
55
55
|
meta: {
|
|
56
|
-
dialects: ["javascript", "typescript"],
|
|
57
|
-
language: "javascript",
|
|
58
56
|
type: "suggestion",
|
|
59
57
|
|
|
60
58
|
docs: {
|
|
61
59
|
description: "Disallow specified global variables",
|
|
60
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
62
61
|
recommended: false,
|
|
63
62
|
url: "https://eslint.org/docs/latest/rules/no-restricted-globals",
|
|
64
63
|
},
|
|
@@ -171,11 +171,10 @@ const arrayOfStringsOrObjectPatterns = {
|
|
|
171
171
|
module.exports = {
|
|
172
172
|
meta: {
|
|
173
173
|
type: "suggestion",
|
|
174
|
-
dialects: ["typescript", "javascript"],
|
|
175
|
-
language: "javascript",
|
|
176
174
|
|
|
177
175
|
docs: {
|
|
178
176
|
description: "Disallow specified modules when loaded by `import`",
|
|
177
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
179
178
|
recommended: false,
|
|
180
179
|
url: "https://eslint.org/docs/latest/rules/no-restricted-imports",
|
|
181
180
|
},
|
package/lib/rules/no-shadow.js
CHANGED
|
@@ -55,8 +55,6 @@ const ALLOWED_FUNCTION_VARIABLE_DEF_TYPES = new Set([
|
|
|
55
55
|
module.exports = {
|
|
56
56
|
meta: {
|
|
57
57
|
type: "suggestion",
|
|
58
|
-
dialects: ["typescript", "javascript"],
|
|
59
|
-
language: "javascript",
|
|
60
58
|
|
|
61
59
|
defaultOptions: [
|
|
62
60
|
{
|
|
@@ -72,6 +70,7 @@ module.exports = {
|
|
|
72
70
|
docs: {
|
|
73
71
|
description:
|
|
74
72
|
"Disallow variable declarations from shadowing variables declared in the outer scope",
|
|
73
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
75
74
|
recommended: false,
|
|
76
75
|
url: "https://eslint.org/docs/latest/rules/no-shadow",
|
|
77
76
|
},
|
|
@@ -12,12 +12,11 @@
|
|
|
12
12
|
module.exports = {
|
|
13
13
|
meta: {
|
|
14
14
|
type: "problem",
|
|
15
|
-
dialects: ["typescript", "javascript"],
|
|
16
|
-
language: "javascript",
|
|
17
15
|
|
|
18
16
|
docs: {
|
|
19
17
|
description:
|
|
20
18
|
"Disallow `let` or `var` variables that are read but never assigned",
|
|
19
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
21
20
|
recommended: true,
|
|
22
21
|
url: "https://eslint.org/docs/latest/rules/no-unassigned-vars",
|
|
23
22
|
},
|
|
@@ -29,12 +29,11 @@ function alwaysFalse() {
|
|
|
29
29
|
/** @type {import('../types').Rule.RuleModule} */
|
|
30
30
|
module.exports = {
|
|
31
31
|
meta: {
|
|
32
|
-
dialects: ["javascript", "typescript"],
|
|
33
|
-
language: "javascript",
|
|
34
32
|
type: "suggestion",
|
|
35
33
|
|
|
36
34
|
docs: {
|
|
37
35
|
description: "Disallow unused expressions",
|
|
36
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
38
37
|
recommended: false,
|
|
39
38
|
url: "https://eslint.org/docs/latest/rules/no-unused-expressions",
|
|
40
39
|
},
|
|
@@ -42,6 +42,20 @@ const astUtils = require("./utils/ast-utils");
|
|
|
42
42
|
* @property {string} additional Any additional info to be appended at the end.
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
|
+
//------------------------------------------------------------------------------
|
|
46
|
+
// Helpers
|
|
47
|
+
//------------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
const DEFAULT_OPTIONS = {
|
|
50
|
+
vars: "all",
|
|
51
|
+
args: "after-used",
|
|
52
|
+
ignoreRestSiblings: false,
|
|
53
|
+
caughtErrors: "all",
|
|
54
|
+
ignoreClassWithStaticInitBlock: false,
|
|
55
|
+
ignoreUsingDeclarations: false,
|
|
56
|
+
reportUsedIgnorePattern: false,
|
|
57
|
+
};
|
|
58
|
+
|
|
45
59
|
//------------------------------------------------------------------------------
|
|
46
60
|
// Rule Definition
|
|
47
61
|
//------------------------------------------------------------------------------
|
|
@@ -108,6 +122,8 @@ module.exports = {
|
|
|
108
122
|
},
|
|
109
123
|
],
|
|
110
124
|
|
|
125
|
+
defaultOptions: [DEFAULT_OPTIONS],
|
|
126
|
+
|
|
111
127
|
messages: {
|
|
112
128
|
unusedVar:
|
|
113
129
|
"'{{varName}}' is {{action}} but never used{{additional}}.",
|
|
@@ -123,65 +139,46 @@ module.exports = {
|
|
|
123
139
|
const REST_PROPERTY_TYPE =
|
|
124
140
|
/^(?:RestElement|(?:Experimental)?RestProperty)$/u;
|
|
125
141
|
|
|
126
|
-
|
|
127
|
-
vars: "all",
|
|
128
|
-
args: "after-used",
|
|
129
|
-
ignoreRestSiblings: false,
|
|
130
|
-
caughtErrors: "all",
|
|
131
|
-
ignoreClassWithStaticInitBlock: false,
|
|
132
|
-
ignoreUsingDeclarations: false,
|
|
133
|
-
reportUsedIgnorePattern: false,
|
|
134
|
-
};
|
|
142
|
+
let config;
|
|
135
143
|
|
|
136
144
|
const firstOption = context.options[0];
|
|
137
145
|
|
|
138
|
-
if (firstOption) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
firstOption.caughtErrors || config.caughtErrors;
|
|
148
|
-
config.ignoreClassWithStaticInitBlock =
|
|
149
|
-
firstOption.ignoreClassWithStaticInitBlock ||
|
|
150
|
-
config.ignoreClassWithStaticInitBlock;
|
|
151
|
-
config.ignoreUsingDeclarations =
|
|
152
|
-
firstOption.ignoreUsingDeclarations ||
|
|
153
|
-
config.ignoreUsingDeclarations;
|
|
154
|
-
config.reportUsedIgnorePattern =
|
|
155
|
-
firstOption.reportUsedIgnorePattern ||
|
|
156
|
-
config.reportUsedIgnorePattern;
|
|
157
|
-
|
|
158
|
-
if (firstOption.varsIgnorePattern) {
|
|
159
|
-
config.varsIgnorePattern = new RegExp(
|
|
160
|
-
firstOption.varsIgnorePattern,
|
|
161
|
-
"u",
|
|
162
|
-
);
|
|
163
|
-
}
|
|
146
|
+
if (typeof firstOption === "string") {
|
|
147
|
+
config = {
|
|
148
|
+
...DEFAULT_OPTIONS,
|
|
149
|
+
vars: firstOption,
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
config = {
|
|
153
|
+
...firstOption,
|
|
154
|
+
};
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
156
|
+
if (firstOption.varsIgnorePattern) {
|
|
157
|
+
config.varsIgnorePattern = new RegExp(
|
|
158
|
+
firstOption.varsIgnorePattern,
|
|
159
|
+
"u",
|
|
160
|
+
);
|
|
161
|
+
}
|
|
171
162
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
163
|
+
if (firstOption.argsIgnorePattern) {
|
|
164
|
+
config.argsIgnorePattern = new RegExp(
|
|
165
|
+
firstOption.argsIgnorePattern,
|
|
166
|
+
"u",
|
|
167
|
+
);
|
|
168
|
+
}
|
|
178
169
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
170
|
+
if (firstOption.caughtErrorsIgnorePattern) {
|
|
171
|
+
config.caughtErrorsIgnorePattern = new RegExp(
|
|
172
|
+
firstOption.caughtErrorsIgnorePattern,
|
|
173
|
+
"u",
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (firstOption.destructuredArrayIgnorePattern) {
|
|
178
|
+
config.destructuredArrayIgnorePattern = new RegExp(
|
|
179
|
+
firstOption.destructuredArrayIgnorePattern,
|
|
180
|
+
"u",
|
|
181
|
+
);
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
184
|
|
|
@@ -276,13 +276,12 @@ function isClassRefInClassDecorator(variable, reference) {
|
|
|
276
276
|
/** @type {import('../types').Rule.RuleModule} */
|
|
277
277
|
module.exports = {
|
|
278
278
|
meta: {
|
|
279
|
-
dialects: ["javascript", "typescript"],
|
|
280
|
-
language: "javascript",
|
|
281
279
|
type: "problem",
|
|
282
280
|
|
|
283
281
|
docs: {
|
|
284
282
|
description:
|
|
285
283
|
"Disallow the use of variables before they are defined",
|
|
284
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
286
285
|
recommended: false,
|
|
287
286
|
url: "https://eslint.org/docs/latest/rules/no-use-before-define",
|
|
288
287
|
},
|
|
@@ -164,12 +164,11 @@ function isRedundantSuperCall(body, ctorParams) {
|
|
|
164
164
|
/** @type {import('../types').Rule.RuleModule} */
|
|
165
165
|
module.exports = {
|
|
166
166
|
meta: {
|
|
167
|
-
dialects: ["javascript", "typescript"],
|
|
168
|
-
language: "javascript",
|
|
169
167
|
type: "suggestion",
|
|
170
168
|
|
|
171
169
|
docs: {
|
|
172
170
|
description: "Disallow unnecessary constructors",
|
|
171
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
173
172
|
recommended: false,
|
|
174
173
|
url: "https://eslint.org/docs/latest/rules/no-useless-constructor",
|
|
175
174
|
},
|
package/lib/rules/no-var.js
CHANGED
|
@@ -229,11 +229,10 @@ function hasReferenceBeforeDeclaration(variable) {
|
|
|
229
229
|
module.exports = {
|
|
230
230
|
meta: {
|
|
231
231
|
type: "suggestion",
|
|
232
|
-
dialects: ["typescript", "javascript"],
|
|
233
|
-
language: "javascript",
|
|
234
232
|
|
|
235
233
|
docs: {
|
|
236
234
|
description: "Require `let` or `const` instead of `var`",
|
|
235
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
237
236
|
recommended: false,
|
|
238
237
|
url: "https://eslint.org/docs/latest/rules/no-var",
|
|
239
238
|
},
|
|
@@ -186,6 +186,8 @@ module.exports = {
|
|
|
186
186
|
],
|
|
187
187
|
},
|
|
188
188
|
|
|
189
|
+
defaultOptions: ["always"],
|
|
190
|
+
|
|
189
191
|
messages: {
|
|
190
192
|
expectedAllPropertiesShorthanded:
|
|
191
193
|
"Expected shorthand for all properties.",
|
|
@@ -201,7 +203,7 @@ module.exports = {
|
|
|
201
203
|
},
|
|
202
204
|
|
|
203
205
|
create(context) {
|
|
204
|
-
const APPLY = context.options[0]
|
|
206
|
+
const APPLY = context.options[0];
|
|
205
207
|
const APPLY_TO_METHODS =
|
|
206
208
|
APPLY === OPTIONS.methods || APPLY === OPTIONS.always;
|
|
207
209
|
const APPLY_TO_PROPS =
|
package/lib/rules/one-var.js
CHANGED
|
@@ -89,6 +89,8 @@ module.exports = {
|
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
|
|
92
|
+
defaultOptions: ["always"],
|
|
93
|
+
|
|
92
94
|
messages: {
|
|
93
95
|
combineUninitialized:
|
|
94
96
|
"Combine this with the previous '{{type}}' statement with uninitialized variables.",
|
|
@@ -109,7 +111,7 @@ module.exports = {
|
|
|
109
111
|
const MODE_ALWAYS = "always";
|
|
110
112
|
const MODE_NEVER = "never";
|
|
111
113
|
const MODE_CONSECUTIVE = "consecutive";
|
|
112
|
-
const mode = context.options[0]
|
|
114
|
+
const mode = context.options[0];
|
|
113
115
|
|
|
114
116
|
const options = {};
|
|
115
117
|
|
|
@@ -158,8 +158,6 @@ function hasDuplicateParams(paramsList) {
|
|
|
158
158
|
module.exports = {
|
|
159
159
|
meta: {
|
|
160
160
|
type: "suggestion",
|
|
161
|
-
dialects: ["javascript", "typescript"],
|
|
162
|
-
language: "javascript",
|
|
163
161
|
|
|
164
162
|
defaultOptions: [
|
|
165
163
|
{ allowNamedFunctions: false, allowUnboundThis: true },
|
|
@@ -167,6 +165,7 @@ module.exports = {
|
|
|
167
165
|
|
|
168
166
|
docs: {
|
|
169
167
|
description: "Require using arrow functions for callbacks",
|
|
168
|
+
dialects: ["JavaScript", "TypeScript"],
|
|
170
169
|
recommended: false,
|
|
171
170
|
frozen: true,
|
|
172
171
|
url: "https://eslint.org/docs/latest/rules/prefer-arrow-callback",
|
|
@@ -324,6 +323,24 @@ module.exports = {
|
|
|
324
323
|
return;
|
|
325
324
|
}
|
|
326
325
|
|
|
326
|
+
const functionToken = sourceCode.getFirstToken(
|
|
327
|
+
node,
|
|
328
|
+
node.async ? 1 : 0,
|
|
329
|
+
);
|
|
330
|
+
const leftParenToken = sourceCode.getTokenAfter(
|
|
331
|
+
functionToken,
|
|
332
|
+
astUtils.isOpeningParenToken,
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
if (node.async) {
|
|
336
|
+
if (
|
|
337
|
+
functionToken.loc.end.line <
|
|
338
|
+
leftParenToken.loc.start.line
|
|
339
|
+
) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
327
344
|
// Remove `.bind(this)` if exists.
|
|
328
345
|
if (callbackInfo.isLexicalThis) {
|
|
329
346
|
const memberNode = node.parent;
|
|
@@ -376,14 +393,6 @@ module.exports = {
|
|
|
376
393
|
}
|
|
377
394
|
|
|
378
395
|
// Convert the function expression to an arrow function.
|
|
379
|
-
const functionToken = sourceCode.getFirstToken(
|
|
380
|
-
node,
|
|
381
|
-
node.async ? 1 : 0,
|
|
382
|
-
);
|
|
383
|
-
const leftParenToken = sourceCode.getTokenAfter(
|
|
384
|
-
functionToken,
|
|
385
|
-
astUtils.isOpeningParenToken,
|
|
386
|
-
);
|
|
387
396
|
const tokenBeforeBody = sourceCode.getTokenBefore(
|
|
388
397
|
node.body,
|
|
389
398
|
);
|
package/lib/types/index.d.ts
CHANGED
|
@@ -723,6 +723,22 @@ export namespace Rule {
|
|
|
723
723
|
| "class-field-initializer"
|
|
724
724
|
| "class-static-block";
|
|
725
725
|
|
|
726
|
+
interface CodePathSegmentTraversalController {
|
|
727
|
+
skip(): void;
|
|
728
|
+
break(): void;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
type CodePathSegmentTraversalCallback = (
|
|
732
|
+
this: CodePath,
|
|
733
|
+
segment: CodePathSegment,
|
|
734
|
+
controller: CodePathSegmentTraversalController,
|
|
735
|
+
) => void;
|
|
736
|
+
|
|
737
|
+
interface CodePathTraversalOptions {
|
|
738
|
+
first?: CodePathSegment | undefined;
|
|
739
|
+
last?: CodePathSegment | undefined;
|
|
740
|
+
}
|
|
741
|
+
|
|
726
742
|
interface CodePath {
|
|
727
743
|
id: string;
|
|
728
744
|
origin: CodePathOrigin;
|
|
@@ -732,12 +748,19 @@ export namespace Rule {
|
|
|
732
748
|
thrownSegments: CodePathSegment[];
|
|
733
749
|
upper: CodePath | null;
|
|
734
750
|
childCodePaths: CodePath[];
|
|
751
|
+
traverseSegments(callback: CodePathSegmentTraversalCallback): void;
|
|
752
|
+
traverseSegments(
|
|
753
|
+
options: CodePathTraversalOptions,
|
|
754
|
+
callback: CodePathSegmentTraversalCallback,
|
|
755
|
+
): void;
|
|
735
756
|
}
|
|
736
757
|
|
|
737
758
|
interface CodePathSegment {
|
|
738
759
|
id: string;
|
|
739
760
|
nextSegments: CodePathSegment[];
|
|
740
761
|
prevSegments: CodePathSegment[];
|
|
762
|
+
allNextSegments: CodePathSegment[];
|
|
763
|
+
allPrevSegments: CodePathSegment[];
|
|
741
764
|
reachable: boolean;
|
|
742
765
|
}
|
|
743
766
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.1",
|
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -122,9 +122,9 @@
|
|
|
122
122
|
"@eslint-community/eslint-utils": "^4.8.0",
|
|
123
123
|
"@eslint-community/regexpp": "^4.12.2",
|
|
124
124
|
"@eslint/config-array": "^0.23.5",
|
|
125
|
-
"@eslint/config-helpers": "^0.
|
|
125
|
+
"@eslint/config-helpers": "^0.6.0",
|
|
126
126
|
"@eslint/core": "^1.2.1",
|
|
127
|
-
"@eslint/plugin-kit": "^0.7.
|
|
127
|
+
"@eslint/plugin-kit": "^0.7.2",
|
|
128
128
|
"@humanfs/node": "^0.16.6",
|
|
129
129
|
"@humanwhocodes/module-importer": "^1.0.1",
|
|
130
130
|
"@humanwhocodes/retry": "^0.4.2",
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
"got": "^11.8.3",
|
|
184
184
|
"gray-matter": "^4.0.3",
|
|
185
185
|
"jiti": "^2.6.1",
|
|
186
|
-
"knip": "^
|
|
186
|
+
"knip": "^6.13.1",
|
|
187
187
|
"lint-staged": "^11.0.0",
|
|
188
188
|
"markdown-it": "^12.2.0",
|
|
189
189
|
"markdown-it-container": "^3.0.0",
|
|
@@ -201,7 +201,6 @@
|
|
|
201
201
|
"prettier": "3.8.3",
|
|
202
202
|
"progress": "^2.0.3",
|
|
203
203
|
"proxyquire": "^2.0.1",
|
|
204
|
-
"recast": "^0.23.0",
|
|
205
204
|
"regenerator-runtime": "^0.14.0",
|
|
206
205
|
"semver": "^7.5.3",
|
|
207
206
|
"shelljs": "^0.10.0",
|
|
@@ -229,5 +228,10 @@
|
|
|
229
228
|
"license": "MIT",
|
|
230
229
|
"engines": {
|
|
231
230
|
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
231
|
+
},
|
|
232
|
+
"overrides": {
|
|
233
|
+
"@arethetypeswrong/core": {
|
|
234
|
+
"fflate": "0.8.2"
|
|
235
|
+
}
|
|
232
236
|
}
|
|
233
237
|
}
|