eslint 8.47.0 → 8.49.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/config/rule-validator.js +2 -1
- package/lib/linter/code-path-analysis/code-path-analyzer.js +32 -24
- package/lib/linter/code-path-analysis/code-path-segment.js +52 -24
- package/lib/linter/code-path-analysis/code-path.js +1 -0
- package/lib/linter/linter.js +1 -0
- package/lib/rule-tester/flat-rule-tester.js +54 -20
- package/lib/rule-tester/rule-tester.js +117 -22
- package/lib/rules/array-callback-return.js +36 -11
- package/lib/rules/consistent-return.js +32 -7
- package/lib/rules/constructor-super.js +37 -14
- package/lib/rules/for-direction.js +15 -8
- package/lib/rules/getter-return.js +33 -8
- package/lib/rules/lines-between-class-members.js +92 -7
- package/lib/rules/no-fallthrough.js +42 -14
- package/lib/rules/no-promise-executor-return.js +154 -16
- package/lib/rules/no-this-before-super.js +38 -11
- package/lib/rules/no-unreachable-loop.js +47 -12
- package/lib/rules/no-unreachable.js +39 -10
- package/lib/rules/no-useless-return.js +35 -4
- package/lib/rules/require-atomic-updates.js +21 -7
- package/messages/eslintrc-incompat.js +1 -1
- package/package.json +11 -9
@@ -24,12 +24,19 @@ function isInitialized(node) {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
/**
|
27
|
-
* Checks
|
28
|
-
* @param {CodePathSegment}
|
29
|
-
* @returns {boolean}
|
27
|
+
* Checks all segments in a set and returns true if all are unreachable.
|
28
|
+
* @param {Set<CodePathSegment>} segments The segments to check.
|
29
|
+
* @returns {boolean} True if all segments are unreachable; false otherwise.
|
30
30
|
*/
|
31
|
-
function
|
32
|
-
|
31
|
+
function areAllSegmentsUnreachable(segments) {
|
32
|
+
|
33
|
+
for (const segment of segments) {
|
34
|
+
if (segment.reachable) {
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
return true;
|
33
40
|
}
|
34
41
|
|
35
42
|
/**
|
@@ -124,7 +131,6 @@ module.exports = {
|
|
124
131
|
},
|
125
132
|
|
126
133
|
create(context) {
|
127
|
-
let currentCodePath = null;
|
128
134
|
|
129
135
|
/** @type {ConstructorInfo | null} */
|
130
136
|
let constructorInfo = null;
|
@@ -132,6 +138,12 @@ module.exports = {
|
|
132
138
|
/** @type {ConsecutiveRange} */
|
133
139
|
const range = new ConsecutiveRange(context.sourceCode);
|
134
140
|
|
141
|
+
/** @type {Array<Set<CodePathSegment>>} */
|
142
|
+
const codePathSegments = [];
|
143
|
+
|
144
|
+
/** @type {Set<CodePathSegment>} */
|
145
|
+
let currentCodePathSegments = new Set();
|
146
|
+
|
135
147
|
/**
|
136
148
|
* Reports a given node if it's unreachable.
|
137
149
|
* @param {ASTNode} node A statement node to report.
|
@@ -140,7 +152,7 @@ module.exports = {
|
|
140
152
|
function reportIfUnreachable(node) {
|
141
153
|
let nextNode = null;
|
142
154
|
|
143
|
-
if (node && (node.type === "PropertyDefinition" ||
|
155
|
+
if (node && (node.type === "PropertyDefinition" || areAllSegmentsUnreachable(currentCodePathSegments))) {
|
144
156
|
|
145
157
|
// Store this statement to distinguish consecutive statements.
|
146
158
|
if (range.isEmpty) {
|
@@ -181,12 +193,29 @@ module.exports = {
|
|
181
193
|
return {
|
182
194
|
|
183
195
|
// Manages the current code path.
|
184
|
-
onCodePathStart(
|
185
|
-
|
196
|
+
onCodePathStart() {
|
197
|
+
codePathSegments.push(currentCodePathSegments);
|
198
|
+
currentCodePathSegments = new Set();
|
186
199
|
},
|
187
200
|
|
188
201
|
onCodePathEnd() {
|
189
|
-
|
202
|
+
currentCodePathSegments = codePathSegments.pop();
|
203
|
+
},
|
204
|
+
|
205
|
+
onUnreachableCodePathSegmentStart(segment) {
|
206
|
+
currentCodePathSegments.add(segment);
|
207
|
+
},
|
208
|
+
|
209
|
+
onUnreachableCodePathSegmentEnd(segment) {
|
210
|
+
currentCodePathSegments.delete(segment);
|
211
|
+
},
|
212
|
+
|
213
|
+
onCodePathSegmentEnd(segment) {
|
214
|
+
currentCodePathSegments.delete(segment);
|
215
|
+
},
|
216
|
+
|
217
|
+
onCodePathSegmentStart(segment) {
|
218
|
+
currentCodePathSegments.add(segment);
|
190
219
|
},
|
191
220
|
|
192
221
|
// Registers for all statement nodes (excludes FunctionDeclaration).
|
@@ -57,6 +57,22 @@ function isInFinally(node) {
|
|
57
57
|
return false;
|
58
58
|
}
|
59
59
|
|
60
|
+
/**
|
61
|
+
* Checks all segments in a set and returns true if any are reachable.
|
62
|
+
* @param {Set<CodePathSegment>} segments The segments to check.
|
63
|
+
* @returns {boolean} True if any segment is reachable; false otherwise.
|
64
|
+
*/
|
65
|
+
function isAnySegmentReachable(segments) {
|
66
|
+
|
67
|
+
for (const segment of segments) {
|
68
|
+
if (segment.reachable) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
60
76
|
//------------------------------------------------------------------------------
|
61
77
|
// Rule Definition
|
62
78
|
//------------------------------------------------------------------------------
|
@@ -205,7 +221,6 @@ module.exports = {
|
|
205
221
|
*/
|
206
222
|
function markReturnStatementsOnCurrentSegmentsAsUsed() {
|
207
223
|
scopeInfo
|
208
|
-
.codePath
|
209
224
|
.currentSegments
|
210
225
|
.forEach(segment => markReturnStatementsOnSegmentAsUsed(segment, new Set()));
|
211
226
|
}
|
@@ -222,7 +237,8 @@ module.exports = {
|
|
222
237
|
upper: scopeInfo,
|
223
238
|
uselessReturns: [],
|
224
239
|
traversedTryBlockStatements: [],
|
225
|
-
codePath
|
240
|
+
codePath,
|
241
|
+
currentSegments: new Set()
|
226
242
|
};
|
227
243
|
},
|
228
244
|
|
@@ -259,6 +275,9 @@ module.exports = {
|
|
259
275
|
* NOTE: This event is notified for only reachable segments.
|
260
276
|
*/
|
261
277
|
onCodePathSegmentStart(segment) {
|
278
|
+
|
279
|
+
scopeInfo.currentSegments.add(segment);
|
280
|
+
|
262
281
|
const info = {
|
263
282
|
uselessReturns: getUselessReturns([], segment.allPrevSegments),
|
264
283
|
returned: false
|
@@ -268,6 +287,18 @@ module.exports = {
|
|
268
287
|
segmentInfoMap.set(segment, info);
|
269
288
|
},
|
270
289
|
|
290
|
+
onUnreachableCodePathSegmentStart(segment) {
|
291
|
+
scopeInfo.currentSegments.add(segment);
|
292
|
+
},
|
293
|
+
|
294
|
+
onUnreachableCodePathSegmentEnd(segment) {
|
295
|
+
scopeInfo.currentSegments.delete(segment);
|
296
|
+
},
|
297
|
+
|
298
|
+
onCodePathSegmentEnd(segment) {
|
299
|
+
scopeInfo.currentSegments.delete(segment);
|
300
|
+
},
|
301
|
+
|
271
302
|
// Adds ReturnStatement node to check whether it's useless or not.
|
272
303
|
ReturnStatement(node) {
|
273
304
|
if (node.argument) {
|
@@ -279,12 +310,12 @@ module.exports = {
|
|
279
310
|
isInFinally(node) ||
|
280
311
|
|
281
312
|
// Ignore `return` statements in unreachable places (https://github.com/eslint/eslint/issues/11647).
|
282
|
-
!scopeInfo.
|
313
|
+
!isAnySegmentReachable(scopeInfo.currentSegments)
|
283
314
|
) {
|
284
315
|
return;
|
285
316
|
}
|
286
317
|
|
287
|
-
for (const segment of scopeInfo.
|
318
|
+
for (const segment of scopeInfo.currentSegments) {
|
288
319
|
const info = segmentInfoMap.get(segment);
|
289
320
|
|
290
321
|
if (info) {
|
@@ -213,7 +213,8 @@ module.exports = {
|
|
213
213
|
stack = {
|
214
214
|
upper: stack,
|
215
215
|
codePath,
|
216
|
-
referenceMap: shouldVerify ? createReferenceMap(scope) : null
|
216
|
+
referenceMap: shouldVerify ? createReferenceMap(scope) : null,
|
217
|
+
currentSegments: new Set()
|
217
218
|
};
|
218
219
|
},
|
219
220
|
onCodePathEnd() {
|
@@ -223,11 +224,25 @@ module.exports = {
|
|
223
224
|
// Initialize the segment information.
|
224
225
|
onCodePathSegmentStart(segment) {
|
225
226
|
segmentInfo.initialize(segment);
|
227
|
+
stack.currentSegments.add(segment);
|
226
228
|
},
|
227
229
|
|
230
|
+
onUnreachableCodePathSegmentStart(segment) {
|
231
|
+
stack.currentSegments.add(segment);
|
232
|
+
},
|
233
|
+
|
234
|
+
onUnreachableCodePathSegmentEnd(segment) {
|
235
|
+
stack.currentSegments.delete(segment);
|
236
|
+
},
|
237
|
+
|
238
|
+
onCodePathSegmentEnd(segment) {
|
239
|
+
stack.currentSegments.delete(segment);
|
240
|
+
},
|
241
|
+
|
242
|
+
|
228
243
|
// Handle references to prepare verification.
|
229
244
|
Identifier(node) {
|
230
|
-
const {
|
245
|
+
const { referenceMap } = stack;
|
231
246
|
const reference = referenceMap && referenceMap.get(node);
|
232
247
|
|
233
248
|
// Ignore if this is not a valid variable reference.
|
@@ -240,7 +255,7 @@ module.exports = {
|
|
240
255
|
|
241
256
|
// Add a fresh read variable.
|
242
257
|
if (reference.isRead() && !(writeExpr && writeExpr.parent.operator === "=")) {
|
243
|
-
segmentInfo.markAsRead(
|
258
|
+
segmentInfo.markAsRead(stack.currentSegments, variable);
|
244
259
|
}
|
245
260
|
|
246
261
|
/*
|
@@ -267,16 +282,15 @@ module.exports = {
|
|
267
282
|
* If the reference exists in `outdatedReadVariables` list, report it.
|
268
283
|
*/
|
269
284
|
":expression:exit"(node) {
|
270
|
-
const { codePath, referenceMap } = stack;
|
271
285
|
|
272
286
|
// referenceMap exists if this is in a resumable function scope.
|
273
|
-
if (!referenceMap) {
|
287
|
+
if (!stack.referenceMap) {
|
274
288
|
return;
|
275
289
|
}
|
276
290
|
|
277
291
|
// Mark the read variables on this code path as outdated.
|
278
292
|
if (node.type === "AwaitExpression" || node.type === "YieldExpression") {
|
279
|
-
segmentInfo.makeOutdated(
|
293
|
+
segmentInfo.makeOutdated(stack.currentSegments);
|
280
294
|
}
|
281
295
|
|
282
296
|
// Verify.
|
@@ -288,7 +302,7 @@ module.exports = {
|
|
288
302
|
for (const reference of references) {
|
289
303
|
const variable = reference.resolved;
|
290
304
|
|
291
|
-
if (segmentInfo.isOutdated(
|
305
|
+
if (segmentInfo.isOutdated(stack.currentSegments, variable)) {
|
292
306
|
if (node.parent.left === reference.identifier) {
|
293
307
|
context.report({
|
294
308
|
node: node.parent,
|
@@ -19,7 +19,7 @@ A config object is using the "extends" key, which is not supported in flat confi
|
|
19
19
|
Instead of "extends", you can include config objects that you'd like to extend from directly in the flat config array.
|
20
20
|
|
21
21
|
Please see the following page for more information:
|
22
|
-
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-configs
|
22
|
+
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-and-shareable-configs
|
23
23
|
`,
|
24
24
|
|
25
25
|
globals: `
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.49.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -63,8 +63,8 @@
|
|
63
63
|
"@eslint-community/eslint-utils": "^4.2.0",
|
64
64
|
"@eslint-community/regexpp": "^4.6.1",
|
65
65
|
"@eslint/eslintrc": "^2.1.2",
|
66
|
-
"@eslint/js": "
|
67
|
-
"@humanwhocodes/config-array": "^0.11.
|
66
|
+
"@eslint/js": "8.49.0",
|
67
|
+
"@humanwhocodes/config-array": "^0.11.11",
|
68
68
|
"@humanwhocodes/module-importer": "^1.0.1",
|
69
69
|
"@nodelib/fs.walk": "^1.2.8",
|
70
70
|
"ajv": "^6.12.4",
|
@@ -101,6 +101,11 @@
|
|
101
101
|
"devDependencies": {
|
102
102
|
"@babel/core": "^7.4.3",
|
103
103
|
"@babel/preset-env": "^7.4.3",
|
104
|
+
"@wdio/browser-runner": "^8.14.6",
|
105
|
+
"@wdio/cli": "^8.14.6",
|
106
|
+
"@wdio/concise-reporter": "^8.14.0",
|
107
|
+
"@wdio/globals": "^8.14.6",
|
108
|
+
"@wdio/mocha-framework": "^8.14.0",
|
104
109
|
"babel-loader": "^8.0.5",
|
105
110
|
"c8": "^7.12.0",
|
106
111
|
"chai": "^4.0.1",
|
@@ -124,11 +129,6 @@
|
|
124
129
|
"glob": "^7.1.6",
|
125
130
|
"got": "^11.8.3",
|
126
131
|
"gray-matter": "^4.0.3",
|
127
|
-
"karma": "^6.1.1",
|
128
|
-
"karma-chrome-launcher": "^3.1.0",
|
129
|
-
"karma-mocha": "^2.0.1",
|
130
|
-
"karma-mocha-reporter": "^2.2.5",
|
131
|
-
"karma-webpack": "^5.0.0",
|
132
132
|
"lint-staged": "^11.0.0",
|
133
133
|
"load-perf": "^0.2.0",
|
134
134
|
"markdownlint": "^0.25.1",
|
@@ -148,12 +148,14 @@
|
|
148
148
|
"pirates": "^4.0.5",
|
149
149
|
"progress": "^2.0.3",
|
150
150
|
"proxyquire": "^2.0.1",
|
151
|
-
"puppeteer": "^13.7.0",
|
152
151
|
"recast": "^0.20.4",
|
153
152
|
"regenerator-runtime": "^0.13.2",
|
153
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
154
154
|
"semver": "^7.5.3",
|
155
155
|
"shelljs": "^0.8.2",
|
156
156
|
"sinon": "^11.0.0",
|
157
|
+
"vite-plugin-commonjs": "^0.8.2",
|
158
|
+
"webdriverio": "^8.14.6",
|
157
159
|
"webpack": "^5.23.0",
|
158
160
|
"webpack-cli": "^4.5.0",
|
159
161
|
"yorkie": "^2.0.0"
|