eslint 9.13.0 → 9.15.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/cli-engine/formatters/stylish.js +3 -3
- package/lib/cli-engine/lint-result-cache.js +1 -1
- package/lib/config/config-loader.js +193 -177
- package/lib/config/config.js +40 -24
- package/lib/eslint/eslint-helpers.js +18 -22
- package/lib/eslint/eslint.js +2 -2
- package/lib/languages/js/index.js +76 -0
- package/lib/languages/js/source-code/token-store/index.js +1 -1
- package/lib/linter/code-path-analysis/code-path-analyzer.js +1 -1
- package/lib/linter/code-path-analysis/fork-context.js +1 -1
- package/lib/linter/linter.js +36 -35
- package/lib/linter/report-translator.js +1 -1
- package/lib/rule-tester/rule-tester.js +1 -1
- package/lib/rules/accessor-pairs.js +10 -7
- package/lib/rules/array-callback-return.js +10 -8
- package/lib/rules/arrow-body-style.js +3 -1
- package/lib/rules/camelcase.js +27 -14
- package/lib/rules/class-methods-use-this.js +9 -5
- package/lib/rules/complexity.js +9 -5
- package/lib/rules/consistent-return.js +4 -4
- package/lib/rules/consistent-this.js +3 -7
- package/lib/rules/curly.js +3 -140
- package/lib/rules/default-case.js +3 -1
- package/lib/rules/dot-notation.js +9 -6
- package/lib/rules/func-names.js +3 -3
- package/lib/rules/func-style.js +10 -8
- package/lib/rules/getter-return.js +5 -5
- package/lib/rules/grouped-accessor-pairs.js +3 -1
- package/lib/rules/id-denylist.js +14 -1
- package/lib/rules/id-length.js +12 -8
- package/lib/rules/id-match.js +20 -17
- package/lib/rules/new-cap.js +15 -34
- package/lib/rules/no-bitwise.js +4 -5
- package/lib/rules/no-cond-assign.js +3 -3
- package/lib/rules/no-console.js +3 -2
- package/lib/rules/no-constant-condition.js +5 -4
- package/lib/rules/no-duplicate-imports.js +5 -4
- package/lib/rules/no-else-return.js +4 -5
- package/lib/rules/no-empty-function.js +4 -4
- package/lib/rules/no-empty-pattern.js +4 -4
- package/lib/rules/no-empty.js +6 -5
- package/lib/rules/no-eval.js +4 -5
- package/lib/rules/no-extend-native.js +3 -3
- package/lib/rules/no-extra-boolean-cast.js +3 -3
- package/lib/rules/no-fallthrough.js +12 -15
- package/lib/rules/no-global-assign.js +3 -2
- package/lib/rules/no-implicit-coercion.js +13 -24
- package/lib/rules/no-implicit-globals.js +4 -4
- package/lib/rules/no-inline-comments.js +4 -6
- package/lib/rules/no-inner-declarations.js +4 -2
- package/lib/rules/no-invalid-regexp.js +5 -4
- package/lib/rules/no-invalid-this.js +4 -4
- package/lib/rules/no-irregular-whitespace.js +24 -22
- package/lib/rules/no-labels.js +8 -7
- package/lib/rules/no-lonely-if.js +8 -2
- package/lib/rules/no-multi-assign.js +5 -10
- package/lib/rules/no-plusplus.js +4 -9
- package/lib/rules/no-promise-executor-return.js +4 -6
- package/lib/rules/no-redeclare.js +5 -8
- package/lib/rules/no-return-assign.js +3 -1
- package/lib/rules/no-self-assign.js +4 -3
- package/lib/rules/no-sequences.js +7 -7
- package/lib/rules/no-shadow.js +18 -14
- package/lib/rules/no-undef.js +4 -4
- package/lib/rules/no-underscore-dangle.js +31 -28
- package/lib/rules/no-unneeded-ternary.js +4 -4
- package/lib/rules/no-unreachable-loop.js +4 -2
- package/lib/rules/no-unsafe-negation.js +4 -4
- package/lib/rules/no-unsafe-optional-chaining.js +4 -4
- package/lib/rules/no-unused-expressions.js +17 -13
- package/lib/rules/no-use-before-define.js +14 -13
- package/lib/rules/no-useless-computed-key.js +9 -3
- package/lib/rules/no-useless-rename.js +7 -8
- package/lib/rules/no-void.js +4 -4
- package/lib/rules/no-warning-comments.js +9 -7
- package/lib/rules/operator-assignment.js +4 -2
- package/lib/rules/prefer-arrow-callback.js +5 -8
- package/lib/rules/prefer-const.js +5 -3
- package/lib/rules/prefer-promise-reject-errors.js +5 -3
- package/lib/rules/prefer-regex-literals.js +4 -3
- package/lib/rules/radix.js +3 -1
- package/lib/rules/require-atomic-updates.js +4 -3
- package/lib/rules/sort-imports.js +20 -16
- package/lib/rules/sort-keys.js +13 -16
- package/lib/rules/sort-vars.js +4 -4
- package/lib/rules/strict.js +3 -2
- package/lib/rules/unicode-bom.js +4 -2
- package/lib/rules/use-isnan.js +7 -4
- package/lib/rules/utils/ast-utils.js +186 -2
- package/lib/rules/valid-typeof.js +3 -2
- package/lib/rules/yoda.js +9 -12
- package/lib/shared/assert.js +22 -0
- package/lib/shared/deep-merge-arrays.js +60 -0
- package/lib/shared/text-table.js +67 -0
- package/lib/shared/types.js +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/rules/ecmascript-6.d.ts +36 -16
- package/lib/types/rules/stylistic-issues.d.ts +3 -0
- package/package.json +19 -20
package/lib/rules/complexity.js
CHANGED
@@ -17,11 +17,15 @@ const { upperCaseFirst } = require("../shared/string-utils");
|
|
17
17
|
// Rule Definition
|
18
18
|
//------------------------------------------------------------------------------
|
19
19
|
|
20
|
+
const THRESHOLD_DEFAULT = 20;
|
21
|
+
|
20
22
|
/** @type {import('../shared/types').Rule} */
|
21
23
|
module.exports = {
|
22
24
|
meta: {
|
23
25
|
type: "suggestion",
|
24
26
|
|
27
|
+
defaultOptions: [THRESHOLD_DEFAULT],
|
28
|
+
|
25
29
|
docs: {
|
26
30
|
description: "Enforce a maximum cyclomatic complexity allowed in a program",
|
27
31
|
recommended: false,
|
@@ -63,19 +67,19 @@ module.exports = {
|
|
63
67
|
|
64
68
|
create(context) {
|
65
69
|
const option = context.options[0];
|
66
|
-
let
|
70
|
+
let threshold = THRESHOLD_DEFAULT;
|
67
71
|
let VARIANT = "classic";
|
68
72
|
|
69
73
|
if (typeof option === "object") {
|
70
74
|
if (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) {
|
71
|
-
|
75
|
+
threshold = option.maximum || option.max;
|
72
76
|
}
|
73
77
|
|
74
78
|
if (Object.hasOwn(option, "variant")) {
|
75
79
|
VARIANT = option.variant;
|
76
80
|
}
|
77
81
|
} else if (typeof option === "number") {
|
78
|
-
|
82
|
+
threshold = option;
|
79
83
|
}
|
80
84
|
|
81
85
|
const IS_MODIFIED_COMPLEXITY = VARIANT === "modified";
|
@@ -160,7 +164,7 @@ module.exports = {
|
|
160
164
|
return;
|
161
165
|
}
|
162
166
|
|
163
|
-
if (complexity >
|
167
|
+
if (complexity > threshold) {
|
164
168
|
let name;
|
165
169
|
|
166
170
|
if (codePath.origin === "class-field-initializer") {
|
@@ -177,7 +181,7 @@ module.exports = {
|
|
177
181
|
data: {
|
178
182
|
name: upperCaseFirst(name),
|
179
183
|
complexity,
|
180
|
-
max:
|
184
|
+
max: threshold
|
181
185
|
}
|
182
186
|
});
|
183
187
|
}
|
@@ -62,13 +62,14 @@ module.exports = {
|
|
62
62
|
type: "object",
|
63
63
|
properties: {
|
64
64
|
treatUndefinedAsUnspecified: {
|
65
|
-
type: "boolean"
|
66
|
-
default: false
|
65
|
+
type: "boolean"
|
67
66
|
}
|
68
67
|
},
|
69
68
|
additionalProperties: false
|
70
69
|
}],
|
71
70
|
|
71
|
+
defaultOptions: [{ treatUndefinedAsUnspecified: false }],
|
72
|
+
|
72
73
|
messages: {
|
73
74
|
missingReturn: "Expected to return a value at the end of {{name}}.",
|
74
75
|
missingReturnValue: "{{name}} expected a return value.",
|
@@ -77,8 +78,7 @@ module.exports = {
|
|
77
78
|
},
|
78
79
|
|
79
80
|
create(context) {
|
80
|
-
const
|
81
|
-
const treatUndefinedAsUnspecified = options.treatUndefinedAsUnspecified === true;
|
81
|
+
const [{ treatUndefinedAsUnspecified }] = context.options;
|
82
82
|
let funcInfo = null;
|
83
83
|
|
84
84
|
/**
|
@@ -28,6 +28,8 @@ module.exports = {
|
|
28
28
|
uniqueItems: true
|
29
29
|
},
|
30
30
|
|
31
|
+
defaultOptions: ["that"],
|
32
|
+
|
31
33
|
messages: {
|
32
34
|
aliasNotAssignedToThis: "Designated alias '{{name}}' is not assigned to 'this'.",
|
33
35
|
unexpectedAlias: "Unexpected alias '{{name}}' for 'this'."
|
@@ -35,15 +37,9 @@ module.exports = {
|
|
35
37
|
},
|
36
38
|
|
37
39
|
create(context) {
|
38
|
-
|
40
|
+
const aliases = context.options;
|
39
41
|
const sourceCode = context.sourceCode;
|
40
42
|
|
41
|
-
if (context.options.length === 0) {
|
42
|
-
aliases.push("that");
|
43
|
-
} else {
|
44
|
-
aliases = context.options;
|
45
|
-
}
|
46
|
-
|
47
43
|
/**
|
48
44
|
* Reports that a variable declarator or assignment expression is assigning
|
49
45
|
* a non-'this' value to the specified alias.
|
package/lib/rules/curly.js
CHANGED
@@ -53,6 +53,8 @@ module.exports = {
|
|
53
53
|
]
|
54
54
|
},
|
55
55
|
|
56
|
+
defaultOptions: ["all"],
|
57
|
+
|
56
58
|
fixable: "code",
|
57
59
|
|
58
60
|
messages: {
|
@@ -64,7 +66,6 @@ module.exports = {
|
|
64
66
|
},
|
65
67
|
|
66
68
|
create(context) {
|
67
|
-
|
68
69
|
const multiOnly = (context.options[0] === "multi");
|
69
70
|
const multiLine = (context.options[0] === "multi-line");
|
70
71
|
const multiOrNest = (context.options[0] === "multi-or-nest");
|
@@ -108,40 +109,6 @@ module.exports = {
|
|
108
109
|
return first.loc.start.line === lastExcludingSemicolon.loc.end.line;
|
109
110
|
}
|
110
111
|
|
111
|
-
/**
|
112
|
-
* Determines if the given node is a lexical declaration (let, const, function, or class)
|
113
|
-
* @param {ASTNode} node The node to check
|
114
|
-
* @returns {boolean} True if the node is a lexical declaration
|
115
|
-
* @private
|
116
|
-
*/
|
117
|
-
function isLexicalDeclaration(node) {
|
118
|
-
if (node.type === "VariableDeclaration") {
|
119
|
-
return node.kind === "const" || node.kind === "let";
|
120
|
-
}
|
121
|
-
|
122
|
-
return node.type === "FunctionDeclaration" || node.type === "ClassDeclaration";
|
123
|
-
}
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Checks if the given token is an `else` token or not.
|
127
|
-
* @param {Token} token The token to check.
|
128
|
-
* @returns {boolean} `true` if the token is an `else` token.
|
129
|
-
*/
|
130
|
-
function isElseKeywordToken(token) {
|
131
|
-
return token.value === "else" && token.type === "Keyword";
|
132
|
-
}
|
133
|
-
|
134
|
-
/**
|
135
|
-
* Determines whether the given node has an `else` keyword token as the first token after.
|
136
|
-
* @param {ASTNode} node The node to check.
|
137
|
-
* @returns {boolean} `true` if the node is followed by an `else` keyword token.
|
138
|
-
*/
|
139
|
-
function isFollowedByElseKeyword(node) {
|
140
|
-
const nextToken = sourceCode.getTokenAfter(node);
|
141
|
-
|
142
|
-
return Boolean(nextToken) && isElseKeywordToken(nextToken);
|
143
|
-
}
|
144
|
-
|
145
112
|
/**
|
146
113
|
* Determines if a semicolon needs to be inserted after removing a set of curly brackets, in order to avoid a SyntaxError.
|
147
114
|
* @param {Token} closingBracket The } token
|
@@ -196,110 +163,6 @@ module.exports = {
|
|
196
163
|
return false;
|
197
164
|
}
|
198
165
|
|
199
|
-
/**
|
200
|
-
* Determines whether the code represented by the given node contains an `if` statement
|
201
|
-
* that would become associated with an `else` keyword directly appended to that code.
|
202
|
-
*
|
203
|
-
* Examples where it returns `true`:
|
204
|
-
*
|
205
|
-
* if (a)
|
206
|
-
* foo();
|
207
|
-
*
|
208
|
-
* if (a) {
|
209
|
-
* foo();
|
210
|
-
* }
|
211
|
-
*
|
212
|
-
* if (a)
|
213
|
-
* foo();
|
214
|
-
* else if (b)
|
215
|
-
* bar();
|
216
|
-
*
|
217
|
-
* while (a)
|
218
|
-
* if (b)
|
219
|
-
* if(c)
|
220
|
-
* foo();
|
221
|
-
* else
|
222
|
-
* bar();
|
223
|
-
*
|
224
|
-
* Examples where it returns `false`:
|
225
|
-
*
|
226
|
-
* if (a)
|
227
|
-
* foo();
|
228
|
-
* else
|
229
|
-
* bar();
|
230
|
-
*
|
231
|
-
* while (a) {
|
232
|
-
* if (b)
|
233
|
-
* if(c)
|
234
|
-
* foo();
|
235
|
-
* else
|
236
|
-
* bar();
|
237
|
-
* }
|
238
|
-
*
|
239
|
-
* while (a)
|
240
|
-
* if (b) {
|
241
|
-
* if(c)
|
242
|
-
* foo();
|
243
|
-
* }
|
244
|
-
* else
|
245
|
-
* bar();
|
246
|
-
* @param {ASTNode} node Node representing the code to check.
|
247
|
-
* @returns {boolean} `true` if an `if` statement within the code would become associated with an `else` appended to that code.
|
248
|
-
*/
|
249
|
-
function hasUnsafeIf(node) {
|
250
|
-
switch (node.type) {
|
251
|
-
case "IfStatement":
|
252
|
-
if (!node.alternate) {
|
253
|
-
return true;
|
254
|
-
}
|
255
|
-
return hasUnsafeIf(node.alternate);
|
256
|
-
case "ForStatement":
|
257
|
-
case "ForInStatement":
|
258
|
-
case "ForOfStatement":
|
259
|
-
case "LabeledStatement":
|
260
|
-
case "WithStatement":
|
261
|
-
case "WhileStatement":
|
262
|
-
return hasUnsafeIf(node.body);
|
263
|
-
default:
|
264
|
-
return false;
|
265
|
-
}
|
266
|
-
}
|
267
|
-
|
268
|
-
/**
|
269
|
-
* Determines whether the existing curly braces around the single statement are necessary to preserve the semantics of the code.
|
270
|
-
* The braces, which make the given block body, are necessary in either of the following situations:
|
271
|
-
*
|
272
|
-
* 1. The statement is a lexical declaration.
|
273
|
-
* 2. Without the braces, an `if` within the statement would become associated with an `else` after the closing brace:
|
274
|
-
*
|
275
|
-
* if (a) {
|
276
|
-
* if (b)
|
277
|
-
* foo();
|
278
|
-
* }
|
279
|
-
* else
|
280
|
-
* bar();
|
281
|
-
*
|
282
|
-
* if (a)
|
283
|
-
* while (b)
|
284
|
-
* while (c) {
|
285
|
-
* while (d)
|
286
|
-
* if (e)
|
287
|
-
* while(f)
|
288
|
-
* foo();
|
289
|
-
* }
|
290
|
-
* else
|
291
|
-
* bar();
|
292
|
-
* @param {ASTNode} node `BlockStatement` body with exactly one statement directly inside. The statement can have its own nested statements.
|
293
|
-
* @returns {boolean} `true` if the braces are necessary - removing them (replacing the given `BlockStatement` body with its single statement content)
|
294
|
-
* would change the semantics of the code or produce a syntax error.
|
295
|
-
*/
|
296
|
-
function areBracesNecessary(node) {
|
297
|
-
const statement = node.body[0];
|
298
|
-
|
299
|
-
return isLexicalDeclaration(statement) ||
|
300
|
-
hasUnsafeIf(statement) && isFollowedByElseKeyword(node);
|
301
|
-
}
|
302
|
-
|
303
166
|
/**
|
304
167
|
* Prepares to check the body of a node to see if it's a block statement.
|
305
168
|
* @param {ASTNode} node The node to report if there's a problem.
|
@@ -318,7 +181,7 @@ module.exports = {
|
|
318
181
|
const hasBlock = (body.type === "BlockStatement");
|
319
182
|
let expected = null;
|
320
183
|
|
321
|
-
if (hasBlock && (body.body.length !== 1 || areBracesNecessary(body))) {
|
184
|
+
if (hasBlock && (body.body.length !== 1 || astUtils.areBracesNecessary(body, sourceCode))) {
|
322
185
|
expected = true;
|
323
186
|
} else if (multiOnly) {
|
324
187
|
expected = false;
|
@@ -15,6 +15,8 @@ module.exports = {
|
|
15
15
|
meta: {
|
16
16
|
type: "suggestion",
|
17
17
|
|
18
|
+
defaultOptions: [{}],
|
19
|
+
|
18
20
|
docs: {
|
19
21
|
description: "Require `default` cases in `switch` statements",
|
20
22
|
recommended: false,
|
@@ -37,7 +39,7 @@ module.exports = {
|
|
37
39
|
},
|
38
40
|
|
39
41
|
create(context) {
|
40
|
-
const options = context.options
|
42
|
+
const [options] = context.options;
|
41
43
|
const commentPattern = options.commentPattern
|
42
44
|
? new RegExp(options.commentPattern, "u")
|
43
45
|
: DEFAULT_COMMENT_PATTERN;
|
@@ -25,6 +25,11 @@ module.exports = {
|
|
25
25
|
meta: {
|
26
26
|
type: "suggestion",
|
27
27
|
|
28
|
+
defaultOptions: [{
|
29
|
+
allowKeywords: true,
|
30
|
+
allowPattern: ""
|
31
|
+
}],
|
32
|
+
|
28
33
|
docs: {
|
29
34
|
description: "Enforce dot notation whenever possible",
|
30
35
|
recommended: false,
|
@@ -36,12 +41,10 @@ module.exports = {
|
|
36
41
|
type: "object",
|
37
42
|
properties: {
|
38
43
|
allowKeywords: {
|
39
|
-
type: "boolean"
|
40
|
-
default: true
|
44
|
+
type: "boolean"
|
41
45
|
},
|
42
46
|
allowPattern: {
|
43
|
-
type: "string"
|
44
|
-
default: ""
|
47
|
+
type: "string"
|
45
48
|
}
|
46
49
|
},
|
47
50
|
additionalProperties: false
|
@@ -57,8 +60,8 @@ module.exports = {
|
|
57
60
|
},
|
58
61
|
|
59
62
|
create(context) {
|
60
|
-
const options = context.options
|
61
|
-
const allowKeywords = options.allowKeywords
|
63
|
+
const [options] = context.options;
|
64
|
+
const allowKeywords = options.allowKeywords;
|
62
65
|
const sourceCode = context.sourceCode;
|
63
66
|
|
64
67
|
let allowPattern;
|
package/lib/rules/func-names.js
CHANGED
@@ -29,6 +29,8 @@ module.exports = {
|
|
29
29
|
meta: {
|
30
30
|
type: "suggestion",
|
31
31
|
|
32
|
+
defaultOptions: ["always", {}],
|
33
|
+
|
32
34
|
docs: {
|
33
35
|
description: "Require or disallow named `function` expressions",
|
34
36
|
recommended: false,
|
@@ -68,7 +70,6 @@ module.exports = {
|
|
68
70
|
},
|
69
71
|
|
70
72
|
create(context) {
|
71
|
-
|
72
73
|
const sourceCode = context.sourceCode;
|
73
74
|
|
74
75
|
/**
|
@@ -79,13 +80,12 @@ module.exports = {
|
|
79
80
|
function getConfigForNode(node) {
|
80
81
|
if (
|
81
82
|
node.generator &&
|
82
|
-
context.options.length > 1 &&
|
83
83
|
context.options[1].generators
|
84
84
|
) {
|
85
85
|
return context.options[1].generators;
|
86
86
|
}
|
87
87
|
|
88
|
-
return context.options[0]
|
88
|
+
return context.options[0];
|
89
89
|
}
|
90
90
|
|
91
91
|
/**
|
package/lib/rules/func-style.js
CHANGED
@@ -13,6 +13,11 @@ module.exports = {
|
|
13
13
|
meta: {
|
14
14
|
type: "suggestion",
|
15
15
|
|
16
|
+
defaultOptions: ["expression", {
|
17
|
+
allowArrowFunctions: false,
|
18
|
+
overrides: {}
|
19
|
+
}],
|
20
|
+
|
16
21
|
docs: {
|
17
22
|
description: "Enforce the consistent use of either `function` declarations or expressions assigned to variables",
|
18
23
|
recommended: false,
|
@@ -27,8 +32,7 @@ module.exports = {
|
|
27
32
|
type: "object",
|
28
33
|
properties: {
|
29
34
|
allowArrowFunctions: {
|
30
|
-
type: "boolean"
|
31
|
-
default: false
|
35
|
+
type: "boolean"
|
32
36
|
},
|
33
37
|
overrides: {
|
34
38
|
type: "object",
|
@@ -51,12 +55,10 @@ module.exports = {
|
|
51
55
|
},
|
52
56
|
|
53
57
|
create(context) {
|
54
|
-
|
55
|
-
const
|
56
|
-
|
57
|
-
|
58
|
-
exportFunctionStyle = context.options[1] && context.options[1].overrides && context.options[1].overrides.namedExports,
|
59
|
-
stack = [];
|
58
|
+
const [style, { allowArrowFunctions, overrides }] = context.options;
|
59
|
+
const enforceDeclarations = (style === "declaration");
|
60
|
+
const { namedExports: exportFunctionStyle } = overrides;
|
61
|
+
const stack = [];
|
60
62
|
|
61
63
|
const nodesToCheck = {
|
62
64
|
FunctionDeclaration(node) {
|
@@ -42,6 +42,8 @@ module.exports = {
|
|
42
42
|
meta: {
|
43
43
|
type: "problem",
|
44
44
|
|
45
|
+
defaultOptions: [{}],
|
46
|
+
|
45
47
|
docs: {
|
46
48
|
description: "Enforce `return` statements in getters",
|
47
49
|
recommended: true,
|
@@ -55,8 +57,7 @@ module.exports = {
|
|
55
57
|
type: "object",
|
56
58
|
properties: {
|
57
59
|
allowImplicit: {
|
58
|
-
type: "boolean"
|
59
|
-
default: false
|
60
|
+
type: "boolean"
|
60
61
|
}
|
61
62
|
},
|
62
63
|
additionalProperties: false
|
@@ -70,8 +71,7 @@ module.exports = {
|
|
70
71
|
},
|
71
72
|
|
72
73
|
create(context) {
|
73
|
-
|
74
|
-
const options = context.options[0] || { allowImplicit: false };
|
74
|
+
const [{ allowImplicit }] = context.options;
|
75
75
|
const sourceCode = context.sourceCode;
|
76
76
|
|
77
77
|
let funcInfo = {
|
@@ -184,7 +184,7 @@ module.exports = {
|
|
184
184
|
funcInfo.hasReturn = true;
|
185
185
|
|
186
186
|
// if allowImplicit: false, should also check node.argument
|
187
|
-
if (!
|
187
|
+
if (!allowImplicit && !node.argument) {
|
188
188
|
context.report({
|
189
189
|
node,
|
190
190
|
messageId: "expected",
|
@@ -95,6 +95,8 @@ module.exports = {
|
|
95
95
|
meta: {
|
96
96
|
type: "suggestion",
|
97
97
|
|
98
|
+
defaultOptions: ["anyOrder"],
|
99
|
+
|
98
100
|
docs: {
|
99
101
|
description: "Require grouped accessor pairs in object literals and classes",
|
100
102
|
recommended: false,
|
@@ -114,7 +116,7 @@ module.exports = {
|
|
114
116
|
},
|
115
117
|
|
116
118
|
create(context) {
|
117
|
-
const order = context.options
|
119
|
+
const [order] = context.options;
|
118
120
|
const sourceCode = context.sourceCode;
|
119
121
|
|
120
122
|
/**
|
package/lib/rules/id-denylist.js
CHANGED
@@ -6,6 +6,12 @@
|
|
6
6
|
|
7
7
|
"use strict";
|
8
8
|
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
// Requirements
|
11
|
+
//------------------------------------------------------------------------------
|
12
|
+
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
|
+
|
9
15
|
//------------------------------------------------------------------------------
|
10
16
|
// Helpers
|
11
17
|
//------------------------------------------------------------------------------
|
@@ -98,6 +104,8 @@ module.exports = {
|
|
98
104
|
meta: {
|
99
105
|
type: "suggestion",
|
100
106
|
|
107
|
+
defaultOptions: [],
|
108
|
+
|
101
109
|
docs: {
|
102
110
|
description: "Disallow specified identifiers",
|
103
111
|
recommended: false,
|
@@ -118,7 +126,6 @@ module.exports = {
|
|
118
126
|
},
|
119
127
|
|
120
128
|
create(context) {
|
121
|
-
|
122
129
|
const denyList = new Set(context.options);
|
123
130
|
const reportedNodes = new Set();
|
124
131
|
const sourceCode = context.sourceCode;
|
@@ -154,6 +161,12 @@ module.exports = {
|
|
154
161
|
* @returns {boolean} `true` if the node should be checked.
|
155
162
|
*/
|
156
163
|
function shouldCheck(node) {
|
164
|
+
|
165
|
+
// Import attributes are defined by environments, so naming conventions shouldn't apply to them
|
166
|
+
if (astUtils.isImportAttributeKey(node)) {
|
167
|
+
return false;
|
168
|
+
}
|
169
|
+
|
157
170
|
const parent = node.parent;
|
158
171
|
|
159
172
|
/*
|
package/lib/rules/id-length.js
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
//------------------------------------------------------------------------------
|
12
12
|
|
13
13
|
const { getGraphemeCount } = require("../shared/string-utils");
|
14
|
-
const { getModuleExportName } = require("./utils/ast-utils");
|
14
|
+
const { getModuleExportName, isImportAttributeKey } = require("./utils/ast-utils");
|
15
15
|
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
// Rule Definition
|
@@ -22,6 +22,12 @@ module.exports = {
|
|
22
22
|
meta: {
|
23
23
|
type: "suggestion",
|
24
24
|
|
25
|
+
defaultOptions: [{
|
26
|
+
exceptionPatterns: [],
|
27
|
+
exceptions: [],
|
28
|
+
min: 2
|
29
|
+
}],
|
30
|
+
|
25
31
|
docs: {
|
26
32
|
description: "Enforce minimum and maximum identifier lengths",
|
27
33
|
recommended: false,
|
@@ -33,8 +39,7 @@ module.exports = {
|
|
33
39
|
type: "object",
|
34
40
|
properties: {
|
35
41
|
min: {
|
36
|
-
type: "integer"
|
37
|
-
default: 2
|
42
|
+
type: "integer"
|
38
43
|
},
|
39
44
|
max: {
|
40
45
|
type: "integer"
|
@@ -69,12 +74,11 @@ module.exports = {
|
|
69
74
|
},
|
70
75
|
|
71
76
|
create(context) {
|
72
|
-
const options = context.options
|
73
|
-
const
|
74
|
-
const maxLength = typeof options.max !== "undefined" ? options.max : Infinity;
|
77
|
+
const [options] = context.options;
|
78
|
+
const { max: maxLength = Infinity, min: minLength } = options;
|
75
79
|
const properties = options.properties !== "never";
|
76
80
|
const exceptions = new Set(options.exceptions);
|
77
|
-
const exceptionPatterns =
|
81
|
+
const exceptionPatterns = options.exceptionPatterns.map(pattern => new RegExp(pattern, "u"));
|
78
82
|
const reportedNodes = new Set();
|
79
83
|
|
80
84
|
/**
|
@@ -115,7 +119,7 @@ module.exports = {
|
|
115
119
|
isKeyAndValueSame && parent.key === node && properties
|
116
120
|
);
|
117
121
|
}
|
118
|
-
return properties && !parent.computed && parent.key.name === node.name;
|
122
|
+
return properties && !isImportAttributeKey(node) && !parent.computed && parent.key.name === node.name;
|
119
123
|
},
|
120
124
|
ImportSpecifier(parent, node) {
|
121
125
|
return (
|
package/lib/rules/id-match.js
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -14,6 +20,8 @@ module.exports = {
|
|
14
20
|
meta: {
|
15
21
|
type: "suggestion",
|
16
22
|
|
23
|
+
defaultOptions: ["^.+$", {}],
|
24
|
+
|
17
25
|
docs: {
|
18
26
|
description: "Require identifiers to match a specified regular expression",
|
19
27
|
recommended: false,
|
@@ -28,20 +36,16 @@ module.exports = {
|
|
28
36
|
type: "object",
|
29
37
|
properties: {
|
30
38
|
properties: {
|
31
|
-
type: "boolean"
|
32
|
-
default: false
|
39
|
+
type: "boolean"
|
33
40
|
},
|
34
41
|
classFields: {
|
35
|
-
type: "boolean"
|
36
|
-
default: false
|
42
|
+
type: "boolean"
|
37
43
|
},
|
38
44
|
onlyDeclarations: {
|
39
|
-
type: "boolean"
|
40
|
-
default: false
|
45
|
+
type: "boolean"
|
41
46
|
},
|
42
47
|
ignoreDestructuring: {
|
43
|
-
type: "boolean"
|
44
|
-
default: false
|
48
|
+
type: "boolean"
|
45
49
|
}
|
46
50
|
},
|
47
51
|
additionalProperties: false
|
@@ -58,14 +62,13 @@ module.exports = {
|
|
58
62
|
//--------------------------------------------------------------------------
|
59
63
|
// Options
|
60
64
|
//--------------------------------------------------------------------------
|
61
|
-
const pattern
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
checkProperties
|
66
|
-
|
67
|
-
|
68
|
-
ignoreDestructuring = !!options.ignoreDestructuring;
|
65
|
+
const [pattern, {
|
66
|
+
classFields: checkClassFields,
|
67
|
+
ignoreDestructuring,
|
68
|
+
onlyDeclarations,
|
69
|
+
properties: checkProperties
|
70
|
+
}] = context.options;
|
71
|
+
const regexp = new RegExp(pattern, "u");
|
69
72
|
|
70
73
|
const sourceCode = context.sourceCode;
|
71
74
|
let globalScope;
|
@@ -180,7 +183,7 @@ module.exports = {
|
|
180
183
|
parent = node.parent,
|
181
184
|
effectiveParent = (parent.type === "MemberExpression") ? parent.parent : parent;
|
182
185
|
|
183
|
-
if (isReferenceToGlobalVariable(node)) {
|
186
|
+
if (isReferenceToGlobalVariable(node) || astUtils.isImportAttributeKey(node)) {
|
184
187
|
return;
|
185
188
|
}
|
186
189
|
|