eslint 8.34.0 → 8.37.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 +11 -12
- package/conf/rule-type-list.json +2 -2
- package/lib/cli-engine/cli-engine.js +2 -2
- package/lib/cli-engine/file-enumerator.js +8 -6
- package/lib/config/default-config.js +1 -4
- package/lib/config/flat-config-array.js +77 -17
- package/lib/config/flat-config-schema.js +4 -18
- package/lib/eslint/eslint-helpers.js +3 -3
- package/lib/linter/linter.js +5 -30
- package/lib/rule-tester/flat-rule-tester.js +1 -1
- package/lib/rule-tester/rule-tester.js +1 -1
- package/lib/rules/camelcase.js +3 -2
- package/lib/rules/consistent-this.js +4 -2
- package/lib/rules/global-require.js +3 -1
- package/lib/rules/handle-callback-err.js +2 -1
- package/lib/rules/id-blacklist.js +3 -2
- package/lib/rules/id-denylist.js +3 -2
- package/lib/rules/id-match.js +3 -2
- package/lib/rules/lines-around-comment.js +11 -0
- package/lib/rules/logical-assignment-operators.js +4 -4
- package/lib/rules/multiline-comment-style.js +42 -3
- package/lib/rules/no-alert.js +3 -1
- package/lib/rules/no-catch-shadow.js +3 -1
- package/lib/rules/no-console.js +3 -2
- package/lib/rules/no-constant-binary-expression.js +36 -27
- package/lib/rules/no-constant-condition.js +3 -2
- package/lib/rules/no-control-regex.js +1 -1
- package/lib/rules/no-else-return.js +13 -12
- package/lib/rules/no-eval.js +5 -5
- package/lib/rules/no-extend-native.js +3 -2
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-parens.js +1 -1
- package/lib/rules/no-global-assign.js +3 -2
- package/lib/rules/no-implicit-globals.js +3 -2
- package/lib/rules/no-implied-eval.js +5 -4
- package/lib/rules/no-import-assign.js +4 -2
- package/lib/rules/no-invalid-regexp.js +1 -1
- package/lib/rules/no-invalid-this.js +2 -2
- package/lib/rules/no-label-var.js +2 -1
- package/lib/rules/no-lone-blocks.js +3 -2
- package/lib/rules/no-loop-func.js +3 -1
- package/lib/rules/no-misleading-character-class.js +12 -41
- package/lib/rules/no-native-reassign.js +3 -2
- package/lib/rules/no-new-func.js +7 -6
- package/lib/rules/no-new-native-nonconstructor.js +8 -6
- package/lib/rules/no-new-object.js +4 -1
- package/lib/rules/no-new-symbol.js +8 -6
- package/lib/rules/no-obj-calls.js +8 -6
- package/lib/rules/no-promise-executor-return.js +3 -2
- package/lib/rules/no-redeclare.js +3 -3
- package/lib/rules/no-regex-spaces.js +4 -2
- package/lib/rules/no-restricted-globals.js +4 -2
- package/lib/rules/no-setter-return.js +3 -2
- package/lib/rules/no-shadow.js +3 -2
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-undef.js +3 -2
- package/lib/rules/no-undefined.js +4 -2
- package/lib/rules/no-unmodified-loop-condition.js +2 -2
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-use-before-define.js +3 -2
- package/lib/rules/no-useless-backreference.js +9 -7
- package/lib/rules/no-useless-return.js +1 -1
- package/lib/rules/object-shorthand.js +3 -2
- package/lib/rules/prefer-arrow-callback.js +1 -1
- package/lib/rules/prefer-exponentiation-operator.js +5 -5
- package/lib/rules/prefer-named-capture-group.js +8 -8
- package/lib/rules/prefer-object-has-own.js +4 -2
- package/lib/rules/prefer-object-spread.js +12 -12
- package/lib/rules/prefer-regex-literals.js +26 -27
- package/lib/rules/prefer-rest-params.js +5 -2
- package/lib/rules/radix.js +11 -11
- package/lib/rules/require-atomic-updates.js +2 -2
- package/lib/rules/require-unicode-regexp.js +63 -7
- package/lib/rules/symbol-description.js +7 -5
- package/lib/rules/utils/regular-expressions.js +42 -0
- package/lib/rules/valid-typeof.js +3 -3
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/source-code/source-code.js +52 -1
- package/lib/source-code/token-store/index.js +1 -1
- package/lib/source-code/token-store/utils.js +14 -4
- package/messages/no-config-found.js +1 -1
- package/package.json +12 -7
- package/conf/eslint-all.js +0 -31
- package/conf/eslint-recommended.js +0 -76
@@ -3,17 +3,16 @@
|
|
3
3
|
*/
|
4
4
|
"use strict";
|
5
5
|
|
6
|
-
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
|
7
|
-
const {
|
6
|
+
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("@eslint-community/eslint-utils");
|
7
|
+
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
|
8
8
|
const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurrogatePair } = require("./utils/unicode");
|
9
9
|
const astUtils = require("./utils/ast-utils.js");
|
10
|
+
const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");
|
10
11
|
|
11
12
|
//------------------------------------------------------------------------------
|
12
13
|
// Helpers
|
13
14
|
//------------------------------------------------------------------------------
|
14
15
|
|
15
|
-
const REGEXPP_LATEST_ECMA_VERSION = 2022;
|
16
|
-
|
17
16
|
/**
|
18
17
|
* Iterate character sequences of a given nodes.
|
19
18
|
*
|
@@ -185,46 +184,18 @@ module.exports = {
|
|
185
184
|
}
|
186
185
|
}
|
187
186
|
|
188
|
-
/**
|
189
|
-
* Checks if the given regular expression pattern would be valid with the `u` flag.
|
190
|
-
* @param {string} pattern The regular expression pattern to verify.
|
191
|
-
* @returns {boolean} `true` if the pattern would be valid with the `u` flag.
|
192
|
-
* `false` if the pattern would be invalid with the `u` flag or the configured
|
193
|
-
* ecmaVersion doesn't support the `u` flag.
|
194
|
-
*/
|
195
|
-
function isValidWithUnicodeFlag(pattern) {
|
196
|
-
const { ecmaVersion } = context.languageOptions;
|
197
|
-
|
198
|
-
// ecmaVersion <= 5 doesn't support the 'u' flag
|
199
|
-
if (ecmaVersion <= 5) {
|
200
|
-
return false;
|
201
|
-
}
|
202
|
-
|
203
|
-
const validator = new RegExpValidator({
|
204
|
-
ecmaVersion: Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION)
|
205
|
-
});
|
206
|
-
|
207
|
-
try {
|
208
|
-
validator.validatePattern(pattern, void 0, void 0, /* uFlag = */ true);
|
209
|
-
} catch {
|
210
|
-
return false;
|
211
|
-
}
|
212
|
-
|
213
|
-
return true;
|
214
|
-
}
|
215
|
-
|
216
187
|
return {
|
217
188
|
"Literal[regex]"(node) {
|
218
189
|
verify(node, node.regex.pattern, node.regex.flags, fixer => {
|
219
|
-
if (!isValidWithUnicodeFlag(node.regex.pattern)) {
|
190
|
+
if (!isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, node.regex.pattern)) {
|
220
191
|
return null;
|
221
192
|
}
|
222
193
|
|
223
194
|
return fixer.insertTextAfter(node, "u");
|
224
195
|
});
|
225
196
|
},
|
226
|
-
"Program"() {
|
227
|
-
const scope =
|
197
|
+
"Program"(node) {
|
198
|
+
const scope = sourceCode.getScope(node);
|
228
199
|
const tracker = new ReferenceTracker(scope);
|
229
200
|
|
230
201
|
/*
|
@@ -232,22 +203,22 @@ module.exports = {
|
|
232
203
|
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
|
233
204
|
* `const {RegExp: a} = window; new a()`, etc...
|
234
205
|
*/
|
235
|
-
for (const { node } of tracker.iterateGlobalReferences({
|
206
|
+
for (const { node: refNode } of tracker.iterateGlobalReferences({
|
236
207
|
RegExp: { [CALL]: true, [CONSTRUCT]: true }
|
237
208
|
})) {
|
238
|
-
const [patternNode, flagsNode] =
|
209
|
+
const [patternNode, flagsNode] = refNode.arguments;
|
239
210
|
const pattern = getStringIfConstant(patternNode, scope);
|
240
211
|
const flags = getStringIfConstant(flagsNode, scope);
|
241
212
|
|
242
213
|
if (typeof pattern === "string") {
|
243
|
-
verify(
|
214
|
+
verify(refNode, pattern, flags || "", fixer => {
|
244
215
|
|
245
|
-
if (!isValidWithUnicodeFlag(pattern)) {
|
216
|
+
if (!isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, pattern)) {
|
246
217
|
return null;
|
247
218
|
}
|
248
219
|
|
249
|
-
if (
|
250
|
-
const penultimateToken = sourceCode.getLastToken(
|
220
|
+
if (refNode.arguments.length === 1) {
|
221
|
+
const penultimateToken = sourceCode.getLastToken(refNode, { skip: 1 }); // skip closing parenthesis
|
251
222
|
|
252
223
|
return fixer.insertTextAfter(
|
253
224
|
penultimateToken,
|
@@ -47,6 +47,7 @@ module.exports = {
|
|
47
47
|
create(context) {
|
48
48
|
const config = context.options[0];
|
49
49
|
const exceptions = (config && config.exceptions) || [];
|
50
|
+
const sourceCode = context.getSourceCode();
|
50
51
|
|
51
52
|
/**
|
52
53
|
* Reports write references.
|
@@ -87,8 +88,8 @@ module.exports = {
|
|
87
88
|
}
|
88
89
|
|
89
90
|
return {
|
90
|
-
Program() {
|
91
|
-
const globalScope =
|
91
|
+
Program(node) {
|
92
|
+
const globalScope = sourceCode.getScope(node);
|
92
93
|
|
93
94
|
globalScope.variables.forEach(checkVariable);
|
94
95
|
}
|
package/lib/rules/no-new-func.js
CHANGED
@@ -40,27 +40,28 @@ module.exports = {
|
|
40
40
|
},
|
41
41
|
|
42
42
|
create(context) {
|
43
|
+
const sourceCode = context.getSourceCode();
|
43
44
|
|
44
45
|
return {
|
45
|
-
"Program:exit"() {
|
46
|
-
const globalScope =
|
46
|
+
"Program:exit"(node) {
|
47
|
+
const globalScope = sourceCode.getScope(node);
|
47
48
|
const variable = globalScope.set.get("Function");
|
48
49
|
|
49
50
|
if (variable && variable.defs.length === 0) {
|
50
51
|
variable.references.forEach(ref => {
|
51
|
-
const
|
52
|
-
const { parent } =
|
52
|
+
const idNode = ref.identifier;
|
53
|
+
const { parent } = idNode;
|
53
54
|
let evalNode;
|
54
55
|
|
55
56
|
if (parent) {
|
56
|
-
if (
|
57
|
+
if (idNode === parent.callee && (
|
57
58
|
parent.type === "NewExpression" ||
|
58
59
|
parent.type === "CallExpression"
|
59
60
|
)) {
|
60
61
|
evalNode = parent;
|
61
62
|
} else if (
|
62
63
|
parent.type === "MemberExpression" &&
|
63
|
-
|
64
|
+
idNode === parent.object &&
|
64
65
|
callMethods.has(astUtils.getStaticPropertyName(parent))
|
65
66
|
) {
|
66
67
|
const maybeCallee = parent.parent.type === "ChainExpression" ? parent.parent : parent;
|
@@ -35,21 +35,23 @@ module.exports = {
|
|
35
35
|
|
36
36
|
create(context) {
|
37
37
|
|
38
|
+
const sourceCode = context.getSourceCode();
|
39
|
+
|
38
40
|
return {
|
39
|
-
"Program:exit"() {
|
40
|
-
const globalScope =
|
41
|
+
"Program:exit"(node) {
|
42
|
+
const globalScope = sourceCode.getScope(node);
|
41
43
|
|
42
44
|
for (const nonConstructorName of nonConstructorGlobalFunctionNames) {
|
43
45
|
const variable = globalScope.set.get(nonConstructorName);
|
44
46
|
|
45
47
|
if (variable && variable.defs.length === 0) {
|
46
48
|
variable.references.forEach(ref => {
|
47
|
-
const
|
48
|
-
const parent =
|
49
|
+
const idNode = ref.identifier;
|
50
|
+
const parent = idNode.parent;
|
49
51
|
|
50
|
-
if (parent && parent.type === "NewExpression" && parent.callee ===
|
52
|
+
if (parent && parent.type === "NewExpression" && parent.callee === idNode) {
|
51
53
|
context.report({
|
52
|
-
node,
|
54
|
+
node: idNode,
|
53
55
|
messageId: "noNewNonconstructor",
|
54
56
|
data: { name: nonConstructorName }
|
55
57
|
});
|
@@ -34,10 +34,13 @@ module.exports = {
|
|
34
34
|
},
|
35
35
|
|
36
36
|
create(context) {
|
37
|
+
|
38
|
+
const sourceCode = context.getSourceCode();
|
39
|
+
|
37
40
|
return {
|
38
41
|
NewExpression(node) {
|
39
42
|
const variable = astUtils.getVariableByName(
|
40
|
-
|
43
|
+
sourceCode.getScope(node),
|
41
44
|
node.callee.name
|
42
45
|
);
|
43
46
|
|
@@ -29,19 +29,21 @@ module.exports = {
|
|
29
29
|
|
30
30
|
create(context) {
|
31
31
|
|
32
|
+
const sourceCode = context.getSourceCode();
|
33
|
+
|
32
34
|
return {
|
33
|
-
"Program:exit"() {
|
34
|
-
const globalScope =
|
35
|
+
"Program:exit"(node) {
|
36
|
+
const globalScope = sourceCode.getScope(node);
|
35
37
|
const variable = globalScope.set.get("Symbol");
|
36
38
|
|
37
39
|
if (variable && variable.defs.length === 0) {
|
38
40
|
variable.references.forEach(ref => {
|
39
|
-
const
|
40
|
-
const parent =
|
41
|
+
const idNode = ref.identifier;
|
42
|
+
const parent = idNode.parent;
|
41
43
|
|
42
|
-
if (parent && parent.type === "NewExpression" && parent.callee ===
|
44
|
+
if (parent && parent.type === "NewExpression" && parent.callee === idNode) {
|
43
45
|
context.report({
|
44
|
-
node,
|
46
|
+
node: idNode,
|
45
47
|
messageId: "noNewSymbol"
|
46
48
|
});
|
47
49
|
}
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const { CALL, CONSTRUCT, ReferenceTracker } = require("eslint-utils");
|
12
|
+
const { CALL, CONSTRUCT, ReferenceTracker } = require("@eslint-community/eslint-utils");
|
13
13
|
const getPropertyName = require("./utils/ast-utils").getStaticPropertyName;
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
@@ -58,9 +58,11 @@ module.exports = {
|
|
58
58
|
|
59
59
|
create(context) {
|
60
60
|
|
61
|
+
const sourceCode = context.getSourceCode();
|
62
|
+
|
61
63
|
return {
|
62
|
-
Program() {
|
63
|
-
const scope =
|
64
|
+
Program(node) {
|
65
|
+
const scope = sourceCode.getScope(node);
|
64
66
|
const tracker = new ReferenceTracker(scope);
|
65
67
|
const traceMap = {};
|
66
68
|
|
@@ -71,12 +73,12 @@ module.exports = {
|
|
71
73
|
};
|
72
74
|
}
|
73
75
|
|
74
|
-
for (const { node, path } of tracker.iterateGlobalReferences(traceMap)) {
|
75
|
-
const name = getReportNodeName(
|
76
|
+
for (const { node: refNode, path } of tracker.iterateGlobalReferences(traceMap)) {
|
77
|
+
const name = getReportNodeName(refNode.callee);
|
76
78
|
const ref = path[0];
|
77
79
|
const messageId = name === ref ? "unexpectedCall" : "unexpectedRefCall";
|
78
80
|
|
79
|
-
context.report({ node, messageId, data: { name, ref } });
|
81
|
+
context.report({ node: refNode, messageId, data: { name, ref } });
|
80
82
|
}
|
81
83
|
}
|
82
84
|
};
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const { findVariable } = require("eslint-utils");
|
12
|
+
const { findVariable } = require("@eslint-community/eslint-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -84,6 +84,7 @@ module.exports = {
|
|
84
84
|
create(context) {
|
85
85
|
|
86
86
|
let funcInfo = null;
|
87
|
+
const sourceCode = context.getSourceCode();
|
87
88
|
|
88
89
|
/**
|
89
90
|
* Reports the given node.
|
@@ -99,7 +100,7 @@ module.exports = {
|
|
99
100
|
onCodePathStart(_, node) {
|
100
101
|
funcInfo = {
|
101
102
|
upper: funcInfo,
|
102
|
-
shouldCheck: functionTypesToCheck.has(node.type) && isPromiseExecutor(node,
|
103
|
+
shouldCheck: functionTypesToCheck.has(node.type) && isPromiseExecutor(node, sourceCode.getScope(node))
|
103
104
|
};
|
104
105
|
|
105
106
|
if (funcInfo.shouldCheck && node.type === "ArrowFunctionExpression" && node.expression) {
|
@@ -129,7 +129,7 @@ module.exports = {
|
|
129
129
|
* @private
|
130
130
|
*/
|
131
131
|
function checkForBlock(node) {
|
132
|
-
const scope =
|
132
|
+
const scope = sourceCode.getScope(node);
|
133
133
|
|
134
134
|
/*
|
135
135
|
* In ES5, some node type such as `BlockStatement` doesn't have that scope.
|
@@ -141,8 +141,8 @@ module.exports = {
|
|
141
141
|
}
|
142
142
|
|
143
143
|
return {
|
144
|
-
Program() {
|
145
|
-
const scope =
|
144
|
+
Program(node) {
|
145
|
+
const scope = sourceCode.getScope(node);
|
146
146
|
|
147
147
|
findVariablesInScope(scope);
|
148
148
|
|
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const astUtils = require("./utils/ast-utils");
|
13
|
-
const regexpp = require("regexpp");
|
13
|
+
const regexpp = require("@eslint-community/regexpp");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
@@ -54,6 +54,8 @@ module.exports = {
|
|
54
54
|
|
55
55
|
create(context) {
|
56
56
|
|
57
|
+
const sourceCode = context.getSourceCode();
|
58
|
+
|
57
59
|
/**
|
58
60
|
* Validate regular expression
|
59
61
|
* @param {ASTNode} nodeToReport Node to report.
|
@@ -149,7 +151,7 @@ module.exports = {
|
|
149
151
|
* @private
|
150
152
|
*/
|
151
153
|
function checkFunction(node) {
|
152
|
-
const scope =
|
154
|
+
const scope = sourceCode.getScope(node);
|
153
155
|
const regExpVar = astUtils.getVariableByName(scope, "RegExp");
|
154
156
|
const shadowed = regExpVar && regExpVar.defs.length > 0;
|
155
157
|
const patternNode = node.arguments[0];
|
@@ -50,6 +50,8 @@ module.exports = {
|
|
50
50
|
|
51
51
|
create(context) {
|
52
52
|
|
53
|
+
const sourceCode = context.getSourceCode();
|
54
|
+
|
53
55
|
// If no globals are restricted, we don't need to do anything
|
54
56
|
if (context.options.length === 0) {
|
55
57
|
return {};
|
@@ -99,8 +101,8 @@ module.exports = {
|
|
99
101
|
}
|
100
102
|
|
101
103
|
return {
|
102
|
-
Program() {
|
103
|
-
const scope =
|
104
|
+
Program(node) {
|
105
|
+
const scope = sourceCode.getScope(node);
|
104
106
|
|
105
107
|
// Report variables declared elsewhere (ex: variables defined as "global" by eslint)
|
106
108
|
scope.variables.forEach(variable => {
|
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const astUtils = require("./utils/ast-utils");
|
13
|
-
const { findVariable } = require("eslint-utils");
|
13
|
+
const { findVariable } = require("@eslint-community/eslint-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
@@ -156,6 +156,7 @@ module.exports = {
|
|
156
156
|
|
157
157
|
create(context) {
|
158
158
|
let funcInfo = null;
|
159
|
+
const sourceCode = context.getSourceCode();
|
159
160
|
|
160
161
|
/**
|
161
162
|
* Creates and pushes to the stack a function info object for the given function node.
|
@@ -163,7 +164,7 @@ module.exports = {
|
|
163
164
|
* @returns {void}
|
164
165
|
*/
|
165
166
|
function enterFunction(node) {
|
166
|
-
const outerScope = getOuterScope(
|
167
|
+
const outerScope = getOuterScope(sourceCode.getScope(node));
|
167
168
|
|
168
169
|
funcInfo = {
|
169
170
|
upper: funcInfo,
|
package/lib/rules/no-shadow.js
CHANGED
@@ -67,6 +67,7 @@ module.exports = {
|
|
67
67
|
allow: (context.options[0] && context.options[0].allow) || [],
|
68
68
|
ignoreOnInitialization: context.options[0] && context.options[0].ignoreOnInitialization
|
69
69
|
};
|
70
|
+
const sourceCode = context.getSourceCode();
|
70
71
|
|
71
72
|
/**
|
72
73
|
* Checks whether or not a given location is inside of the range of a given node.
|
@@ -318,8 +319,8 @@ module.exports = {
|
|
318
319
|
}
|
319
320
|
|
320
321
|
return {
|
321
|
-
"Program:exit"() {
|
322
|
-
const globalScope =
|
322
|
+
"Program:exit"(node) {
|
323
|
+
const globalScope = sourceCode.getScope(node);
|
323
324
|
const stack = globalScope.childScopes.slice();
|
324
325
|
|
325
326
|
while (stack.length) {
|
@@ -39,7 +39,7 @@ module.exports = {
|
|
39
39
|
VariableDeclarator(node) {
|
40
40
|
const name = sourceCode.getText(node.id),
|
41
41
|
init = node.init && node.init.name,
|
42
|
-
scope =
|
42
|
+
scope = sourceCode.getScope(node),
|
43
43
|
undefinedVar = astUtils.getVariableByName(scope, "undefined"),
|
44
44
|
shadowed = undefinedVar && undefinedVar.defs.length > 0,
|
45
45
|
lastToken = sourceCode.getLastToken(node);
|
package/lib/rules/no-undef.js
CHANGED
@@ -54,10 +54,11 @@ module.exports = {
|
|
54
54
|
create(context) {
|
55
55
|
const options = context.options[0];
|
56
56
|
const considerTypeOf = options && options.typeof === true || false;
|
57
|
+
const sourceCode = context.getSourceCode();
|
57
58
|
|
58
59
|
return {
|
59
|
-
"Program:exit"(
|
60
|
-
const globalScope =
|
60
|
+
"Program:exit"(node) {
|
61
|
+
const globalScope = sourceCode.getScope(node);
|
61
62
|
|
62
63
|
globalScope.through.forEach(ref => {
|
63
64
|
const identifier = ref.identifier;
|
@@ -28,6 +28,8 @@ module.exports = {
|
|
28
28
|
|
29
29
|
create(context) {
|
30
30
|
|
31
|
+
const sourceCode = context.getSourceCode();
|
32
|
+
|
31
33
|
/**
|
32
34
|
* Report an invalid "undefined" identifier node.
|
33
35
|
* @param {ASTNode} node The node to report.
|
@@ -66,8 +68,8 @@ module.exports = {
|
|
66
68
|
}
|
67
69
|
|
68
70
|
return {
|
69
|
-
"Program:exit"() {
|
70
|
-
const globalScope =
|
71
|
+
"Program:exit"(node) {
|
72
|
+
const globalScope = sourceCode.getScope(node);
|
71
73
|
|
72
74
|
const stack = [globalScope];
|
73
75
|
|
@@ -673,7 +673,7 @@ module.exports = {
|
|
673
673
|
|
674
674
|
return {
|
675
675
|
"Program:exit"(programNode) {
|
676
|
-
const unusedVars = collectUnusedVariables(
|
676
|
+
const unusedVars = collectUnusedVariables(sourceCode.getScope(programNode), []);
|
677
677
|
|
678
678
|
for (let i = 0, l = unusedVars.length; i < l; ++i) {
|
679
679
|
const unusedVar = unusedVars[i];
|
@@ -258,6 +258,7 @@ module.exports = {
|
|
258
258
|
|
259
259
|
create(context) {
|
260
260
|
const options = parseOptions(context.options[0]);
|
261
|
+
const sourceCode = context.getSourceCode();
|
261
262
|
|
262
263
|
/**
|
263
264
|
* Determines whether a given reference should be checked.
|
@@ -339,8 +340,8 @@ module.exports = {
|
|
339
340
|
}
|
340
341
|
|
341
342
|
return {
|
342
|
-
Program() {
|
343
|
-
checkReferencesInScope(
|
343
|
+
Program(node) {
|
344
|
+
checkReferencesInScope(sourceCode.getScope(node));
|
344
345
|
}
|
345
346
|
};
|
346
347
|
}
|
@@ -9,8 +9,8 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
|
13
|
-
const { RegExpParser, visitRegExpAST } = require("regexpp");
|
12
|
+
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("@eslint-community/eslint-utils");
|
13
|
+
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
@@ -82,6 +82,8 @@ module.exports = {
|
|
82
82
|
|
83
83
|
create(context) {
|
84
84
|
|
85
|
+
const sourceCode = context.getSourceCode();
|
86
|
+
|
85
87
|
/**
|
86
88
|
* Checks and reports useless backreferences in the given regular expression.
|
87
89
|
* @param {ASTNode} node Node that represents regular expression. A regex literal or RegExp constructor call.
|
@@ -167,8 +169,8 @@ module.exports = {
|
|
167
169
|
|
168
170
|
checkRegex(node, pattern, flags);
|
169
171
|
},
|
170
|
-
Program() {
|
171
|
-
const scope =
|
172
|
+
Program(node) {
|
173
|
+
const scope = sourceCode.getScope(node),
|
172
174
|
tracker = new ReferenceTracker(scope),
|
173
175
|
traceMap = {
|
174
176
|
RegExp: {
|
@@ -177,13 +179,13 @@ module.exports = {
|
|
177
179
|
}
|
178
180
|
};
|
179
181
|
|
180
|
-
for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
|
181
|
-
const [patternNode, flagsNode] =
|
182
|
+
for (const { node: refNode } of tracker.iterateGlobalReferences(traceMap)) {
|
183
|
+
const [patternNode, flagsNode] = refNode.arguments,
|
182
184
|
pattern = getStringIfConstant(patternNode, scope),
|
183
185
|
flags = getStringIfConstant(flagsNode, scope);
|
184
186
|
|
185
187
|
if (typeof pattern === "string") {
|
186
|
-
checkRegex(
|
188
|
+
checkRegex(refNode, pattern, flags || "");
|
187
189
|
}
|
188
190
|
}
|
189
191
|
}
|
@@ -354,11 +354,12 @@ module.exports = {
|
|
354
354
|
/**
|
355
355
|
* Enters a function. This creates a new lexical identifier scope, so a new Set of arrow functions is pushed onto the stack.
|
356
356
|
* Also, this marks all `arguments` identifiers so that they can be detected later.
|
357
|
+
* @param {ASTNode} node The node representing the function.
|
357
358
|
* @returns {void}
|
358
359
|
*/
|
359
|
-
function enterFunction() {
|
360
|
+
function enterFunction(node) {
|
360
361
|
lexicalScopeStack.unshift(new Set());
|
361
|
-
|
362
|
+
sourceCode.getScope(node).variables.filter(variable => variable.name === "arguments").forEach(variable => {
|
362
363
|
variable.references.map(ref => ref.identifier).forEach(identifier => argumentsIdentifiers.add(identifier));
|
363
364
|
});
|
364
365
|
}
|
@@ -270,7 +270,7 @@ module.exports = {
|
|
270
270
|
}
|
271
271
|
|
272
272
|
// Skip if it's using arguments.
|
273
|
-
const variable = getVariableOfArguments(
|
273
|
+
const variable = getVariableOfArguments(sourceCode.getScope(node));
|
274
274
|
|
275
275
|
if (variable && variable.references.length > 0) {
|
276
276
|
return;
|
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const astUtils = require("./utils/ast-utils");
|
13
|
-
const { CALL, ReferenceTracker } = require("eslint-utils");
|
13
|
+
const { CALL, ReferenceTracker } = require("@eslint-community/eslint-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
@@ -172,8 +172,8 @@ module.exports = {
|
|
172
172
|
}
|
173
173
|
|
174
174
|
return {
|
175
|
-
Program() {
|
176
|
-
const scope =
|
175
|
+
Program(node) {
|
176
|
+
const scope = sourceCode.getScope(node);
|
177
177
|
const tracker = new ReferenceTracker(scope);
|
178
178
|
const trackMap = {
|
179
179
|
Math: {
|
@@ -181,8 +181,8 @@ module.exports = {
|
|
181
181
|
}
|
182
182
|
};
|
183
183
|
|
184
|
-
for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
|
185
|
-
report(
|
184
|
+
for (const { node: refNode } of tracker.iterateGlobalReferences(trackMap)) {
|
185
|
+
report(refNode);
|
186
186
|
}
|
187
187
|
}
|
188
188
|
};
|
@@ -14,8 +14,8 @@ const {
|
|
14
14
|
CONSTRUCT,
|
15
15
|
ReferenceTracker,
|
16
16
|
getStringIfConstant
|
17
|
-
} = require("eslint-utils");
|
18
|
-
const regexpp = require("regexpp");
|
17
|
+
} = require("@eslint-community/eslint-utils");
|
18
|
+
const regexpp = require("@eslint-community/regexpp");
|
19
19
|
|
20
20
|
//------------------------------------------------------------------------------
|
21
21
|
// Helpers
|
@@ -151,8 +151,8 @@ module.exports = {
|
|
151
151
|
checkRegex(node.regex.pattern, node, node, node.regex.flags.includes("u"));
|
152
152
|
}
|
153
153
|
},
|
154
|
-
Program() {
|
155
|
-
const scope =
|
154
|
+
Program(node) {
|
155
|
+
const scope = sourceCode.getScope(node);
|
156
156
|
const tracker = new ReferenceTracker(scope);
|
157
157
|
const traceMap = {
|
158
158
|
RegExp: {
|
@@ -161,12 +161,12 @@ module.exports = {
|
|
161
161
|
}
|
162
162
|
};
|
163
163
|
|
164
|
-
for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
|
165
|
-
const regex = getStringIfConstant(
|
166
|
-
const flags = getStringIfConstant(
|
164
|
+
for (const { node: refNode } of tracker.iterateGlobalReferences(traceMap)) {
|
165
|
+
const regex = getStringIfConstant(refNode.arguments[0]);
|
166
|
+
const flags = getStringIfConstant(refNode.arguments[1]);
|
167
167
|
|
168
168
|
if (regex) {
|
169
|
-
checkRegex(regex,
|
169
|
+
checkRegex(regex, refNode, refNode.arguments[0], flags && flags.includes("u"));
|
170
170
|
}
|
171
171
|
}
|
172
172
|
}
|