eslint 9.14.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 +1 -1
- package/lib/cli-engine/formatters/stylish.js +3 -3
- package/lib/cli-engine/lint-result-cache.js +1 -1
- package/lib/config/config.js +40 -24
- package/lib/eslint/eslint-helpers.js +9 -13
- 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 +18 -12
- 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 +2 -1
- package/lib/rules/id-length.js +10 -6
- package/lib/rules/id-match.js +13 -16
- 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 +141 -0
- 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 +10 -11
@@ -22,6 +22,8 @@ module.exports = {
|
|
22
22
|
meta: {
|
23
23
|
type: "problem",
|
24
24
|
|
25
|
+
defaultOptions: [{}],
|
26
|
+
|
25
27
|
docs: {
|
26
28
|
description: "Disallow invalid regular expression strings in `RegExp` constructors",
|
27
29
|
recommended: true,
|
@@ -47,12 +49,11 @@ module.exports = {
|
|
47
49
|
},
|
48
50
|
|
49
51
|
create(context) {
|
50
|
-
|
51
|
-
const options = context.options[0];
|
52
|
+
const [{ allowConstructorFlags }] = context.options;
|
52
53
|
let allowedFlags = [];
|
53
54
|
|
54
|
-
if (
|
55
|
-
const temp =
|
55
|
+
if (allowConstructorFlags) {
|
56
|
+
const temp = allowConstructorFlags.join("").replace(new RegExp(`[${validFlags}]`, "gu"), "");
|
56
57
|
|
57
58
|
if (temp) {
|
58
59
|
allowedFlags = [...new Set(temp)];
|
@@ -35,6 +35,8 @@ module.exports = {
|
|
35
35
|
meta: {
|
36
36
|
type: "suggestion",
|
37
37
|
|
38
|
+
defaultOptions: [{ capIsConstructor: true }],
|
39
|
+
|
38
40
|
docs: {
|
39
41
|
description: "Disallow use of `this` in contexts where the value of `this` is `undefined`",
|
40
42
|
recommended: false,
|
@@ -46,8 +48,7 @@ module.exports = {
|
|
46
48
|
type: "object",
|
47
49
|
properties: {
|
48
50
|
capIsConstructor: {
|
49
|
-
type: "boolean"
|
50
|
-
default: true
|
51
|
+
type: "boolean"
|
51
52
|
}
|
52
53
|
},
|
53
54
|
additionalProperties: false
|
@@ -60,8 +61,7 @@ module.exports = {
|
|
60
61
|
},
|
61
62
|
|
62
63
|
create(context) {
|
63
|
-
const
|
64
|
-
const capIsConstructor = options.capIsConstructor !== false;
|
64
|
+
const [{ capIsConstructor }] = context.options;
|
65
65
|
const stack = [],
|
66
66
|
sourceCode = context.sourceCode;
|
67
67
|
|
@@ -30,6 +30,14 @@ module.exports = {
|
|
30
30
|
meta: {
|
31
31
|
type: "problem",
|
32
32
|
|
33
|
+
defaultOptions: [{
|
34
|
+
skipComments: false,
|
35
|
+
skipJSXText: false,
|
36
|
+
skipRegExps: false,
|
37
|
+
skipStrings: true,
|
38
|
+
skipTemplates: false
|
39
|
+
}],
|
40
|
+
|
33
41
|
docs: {
|
34
42
|
description: "Disallow irregular whitespace",
|
35
43
|
recommended: true,
|
@@ -41,24 +49,19 @@ module.exports = {
|
|
41
49
|
type: "object",
|
42
50
|
properties: {
|
43
51
|
skipComments: {
|
44
|
-
type: "boolean"
|
45
|
-
default: false
|
52
|
+
type: "boolean"
|
46
53
|
},
|
47
54
|
skipStrings: {
|
48
|
-
type: "boolean"
|
49
|
-
default: true
|
55
|
+
type: "boolean"
|
50
56
|
},
|
51
57
|
skipTemplates: {
|
52
|
-
type: "boolean"
|
53
|
-
default: false
|
58
|
+
type: "boolean"
|
54
59
|
},
|
55
60
|
skipRegExps: {
|
56
|
-
type: "boolean"
|
57
|
-
default: false
|
61
|
+
type: "boolean"
|
58
62
|
},
|
59
63
|
skipJSXText: {
|
60
|
-
type: "boolean"
|
61
|
-
default: false
|
64
|
+
type: "boolean"
|
62
65
|
}
|
63
66
|
},
|
64
67
|
additionalProperties: false
|
@@ -71,21 +74,20 @@ module.exports = {
|
|
71
74
|
},
|
72
75
|
|
73
76
|
create(context) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
const skipStrings = options.skipStrings !== false;
|
82
|
-
const skipRegExps = !!options.skipRegExps;
|
83
|
-
const skipTemplates = !!options.skipTemplates;
|
84
|
-
const skipJSXText = !!options.skipJSXText;
|
77
|
+
const [{
|
78
|
+
skipComments,
|
79
|
+
skipStrings,
|
80
|
+
skipRegExps,
|
81
|
+
skipTemplates,
|
82
|
+
skipJSXText
|
83
|
+
}] = context.options;
|
85
84
|
|
86
85
|
const sourceCode = context.sourceCode;
|
87
86
|
const commentNodes = sourceCode.getAllComments();
|
88
87
|
|
88
|
+
// Module store of errors that we have found
|
89
|
+
let errors = [];
|
90
|
+
|
89
91
|
/**
|
90
92
|
* Removes errors that occur inside the given node
|
91
93
|
* @param {ASTNode} node to check for matching errors.
|
@@ -233,7 +235,7 @@ module.exports = {
|
|
233
235
|
* @returns {void}
|
234
236
|
* @private
|
235
237
|
*/
|
236
|
-
function noop() {}
|
238
|
+
function noop() { }
|
237
239
|
|
238
240
|
const nodes = {};
|
239
241
|
|
package/lib/rules/no-labels.js
CHANGED
@@ -19,6 +19,11 @@ module.exports = {
|
|
19
19
|
meta: {
|
20
20
|
type: "suggestion",
|
21
21
|
|
22
|
+
defaultOptions: [{
|
23
|
+
allowLoop: false,
|
24
|
+
allowSwitch: false
|
25
|
+
}],
|
26
|
+
|
22
27
|
docs: {
|
23
28
|
description: "Disallow labeled statements",
|
24
29
|
recommended: false,
|
@@ -30,12 +35,10 @@ module.exports = {
|
|
30
35
|
type: "object",
|
31
36
|
properties: {
|
32
37
|
allowLoop: {
|
33
|
-
type: "boolean"
|
34
|
-
default: false
|
38
|
+
type: "boolean"
|
35
39
|
},
|
36
40
|
allowSwitch: {
|
37
|
-
type: "boolean"
|
38
|
-
default: false
|
41
|
+
type: "boolean"
|
39
42
|
}
|
40
43
|
},
|
41
44
|
additionalProperties: false
|
@@ -50,9 +53,7 @@ module.exports = {
|
|
50
53
|
},
|
51
54
|
|
52
55
|
create(context) {
|
53
|
-
const
|
54
|
-
const allowLoop = options && options.allowLoop;
|
55
|
-
const allowSwitch = options && options.allowSwitch;
|
56
|
+
const [{ allowLoop, allowSwitch }] = context.options;
|
56
57
|
let scopeInfo = null;
|
57
58
|
|
58
59
|
/**
|
@@ -4,6 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
|
+
|
7
13
|
//------------------------------------------------------------------------------
|
8
14
|
// Rule Definition
|
9
15
|
//------------------------------------------------------------------------------
|
@@ -36,8 +42,8 @@ module.exports = {
|
|
36
42
|
grandparent = parent.parent;
|
37
43
|
|
38
44
|
if (parent && parent.type === "BlockStatement" &&
|
39
|
-
parent.body.length === 1 &&
|
40
|
-
grandparent.type === "IfStatement" &&
|
45
|
+
parent.body.length === 1 && !astUtils.areBracesNecessary(parent, sourceCode) &&
|
46
|
+
grandparent && grandparent.type === "IfStatement" &&
|
41
47
|
parent === grandparent.alternate) {
|
42
48
|
context.report({
|
43
49
|
node,
|
@@ -15,6 +15,8 @@ module.exports = {
|
|
15
15
|
meta: {
|
16
16
|
type: "suggestion",
|
17
17
|
|
18
|
+
defaultOptions: [{}],
|
19
|
+
|
18
20
|
docs: {
|
19
21
|
description: "Disallow use of chained assignment expressions",
|
20
22
|
recommended: false,
|
@@ -25,8 +27,7 @@ module.exports = {
|
|
25
27
|
type: "object",
|
26
28
|
properties: {
|
27
29
|
ignoreNonDeclaration: {
|
28
|
-
type: "boolean"
|
29
|
-
default: false
|
30
|
+
type: "boolean"
|
30
31
|
}
|
31
32
|
},
|
32
33
|
additionalProperties: false
|
@@ -38,19 +39,13 @@ module.exports = {
|
|
38
39
|
},
|
39
40
|
|
40
41
|
create(context) {
|
41
|
-
|
42
|
-
//--------------------------------------------------------------------------
|
43
|
-
// Public
|
44
|
-
//--------------------------------------------------------------------------
|
45
|
-
const options = context.options[0] || {
|
46
|
-
ignoreNonDeclaration: false
|
47
|
-
};
|
42
|
+
const [{ ignoreNonDeclaration }] = context.options;
|
48
43
|
const selectors = [
|
49
44
|
"VariableDeclarator > AssignmentExpression.init",
|
50
45
|
"PropertyDefinition > AssignmentExpression.value"
|
51
46
|
];
|
52
47
|
|
53
|
-
if (!
|
48
|
+
if (!ignoreNonDeclaration) {
|
54
49
|
selectors.push("AssignmentExpression > AssignmentExpression.right");
|
55
50
|
}
|
56
51
|
|
package/lib/rules/no-plusplus.js
CHANGED
@@ -50,6 +50,8 @@ module.exports = {
|
|
50
50
|
meta: {
|
51
51
|
type: "suggestion",
|
52
52
|
|
53
|
+
defaultOptions: [{}],
|
54
|
+
|
53
55
|
docs: {
|
54
56
|
description: "Disallow the unary operators `++` and `--`",
|
55
57
|
recommended: false,
|
@@ -61,8 +63,7 @@ module.exports = {
|
|
61
63
|
type: "object",
|
62
64
|
properties: {
|
63
65
|
allowForLoopAfterthoughts: {
|
64
|
-
type: "boolean"
|
65
|
-
default: false
|
66
|
+
type: "boolean"
|
66
67
|
}
|
67
68
|
},
|
68
69
|
additionalProperties: false
|
@@ -75,13 +76,7 @@ module.exports = {
|
|
75
76
|
},
|
76
77
|
|
77
78
|
create(context) {
|
78
|
-
|
79
|
-
const config = context.options[0];
|
80
|
-
let allowForLoopAfterthoughts = false;
|
81
|
-
|
82
|
-
if (typeof config === "object") {
|
83
|
-
allowForLoopAfterthoughts = config.allowForLoopAfterthoughts === true;
|
84
|
-
}
|
79
|
+
const [{ allowForLoopAfterthoughts }] = context.options;
|
85
80
|
|
86
81
|
return {
|
87
82
|
|
@@ -141,6 +141,8 @@ module.exports = {
|
|
141
141
|
meta: {
|
142
142
|
type: "problem",
|
143
143
|
|
144
|
+
defaultOptions: [{}],
|
145
|
+
|
144
146
|
docs: {
|
145
147
|
description: "Disallow returning values from Promise executor functions",
|
146
148
|
recommended: false,
|
@@ -153,8 +155,7 @@ module.exports = {
|
|
153
155
|
type: "object",
|
154
156
|
properties: {
|
155
157
|
allowVoid: {
|
156
|
-
type: "boolean"
|
157
|
-
default: false
|
158
|
+
type: "boolean"
|
158
159
|
}
|
159
160
|
},
|
160
161
|
additionalProperties: false
|
@@ -172,12 +173,9 @@ module.exports = {
|
|
172
173
|
},
|
173
174
|
|
174
175
|
create(context) {
|
175
|
-
|
176
176
|
let funcInfo = null;
|
177
177
|
const sourceCode = context.sourceCode;
|
178
|
-
const {
|
179
|
-
allowVoid = false
|
180
|
-
} = context.options[0] || {};
|
178
|
+
const [{ allowVoid }] = context.options;
|
181
179
|
|
182
180
|
return {
|
183
181
|
|
@@ -20,6 +20,8 @@ module.exports = {
|
|
20
20
|
meta: {
|
21
21
|
type: "suggestion",
|
22
22
|
|
23
|
+
defaultOptions: [{ builtinGlobals: true }],
|
24
|
+
|
23
25
|
docs: {
|
24
26
|
description: "Disallow variable redeclaration",
|
25
27
|
recommended: true,
|
@@ -36,7 +38,7 @@ module.exports = {
|
|
36
38
|
{
|
37
39
|
type: "object",
|
38
40
|
properties: {
|
39
|
-
builtinGlobals: { type: "boolean"
|
41
|
+
builtinGlobals: { type: "boolean" }
|
40
42
|
},
|
41
43
|
additionalProperties: false
|
42
44
|
}
|
@@ -44,12 +46,7 @@ module.exports = {
|
|
44
46
|
},
|
45
47
|
|
46
48
|
create(context) {
|
47
|
-
const
|
48
|
-
builtinGlobals: Boolean(
|
49
|
-
context.options.length === 0 ||
|
50
|
-
context.options[0].builtinGlobals
|
51
|
-
)
|
52
|
-
};
|
49
|
+
const [{ builtinGlobals }] = context.options;
|
53
50
|
const sourceCode = context.sourceCode;
|
54
51
|
|
55
52
|
/**
|
@@ -58,7 +55,7 @@ module.exports = {
|
|
58
55
|
* @returns {IterableIterator<{type:string,node:ASTNode,loc:SourceLocation}>} The declarations.
|
59
56
|
*/
|
60
57
|
function *iterateDeclarations(variable) {
|
61
|
-
if (
|
58
|
+
if (builtinGlobals && (
|
62
59
|
variable.eslintImplicitGlobalSetting === "readonly" ||
|
63
60
|
variable.eslintImplicitGlobalSetting === "writable"
|
64
61
|
)) {
|
@@ -25,6 +25,8 @@ module.exports = {
|
|
25
25
|
meta: {
|
26
26
|
type: "suggestion",
|
27
27
|
|
28
|
+
defaultOptions: ["except-parens"],
|
29
|
+
|
28
30
|
docs: {
|
29
31
|
description: "Disallow assignment operators in `return` statements",
|
30
32
|
recommended: false,
|
@@ -44,7 +46,7 @@ module.exports = {
|
|
44
46
|
},
|
45
47
|
|
46
48
|
create(context) {
|
47
|
-
const always =
|
49
|
+
const always = context.options[0] !== "except-parens";
|
48
50
|
const sourceCode = context.sourceCode;
|
49
51
|
|
50
52
|
return {
|
@@ -129,6 +129,8 @@ module.exports = {
|
|
129
129
|
meta: {
|
130
130
|
type: "problem",
|
131
131
|
|
132
|
+
defaultOptions: [{ props: true }],
|
133
|
+
|
132
134
|
docs: {
|
133
135
|
description: "Disallow assignments where both sides are exactly the same",
|
134
136
|
recommended: true,
|
@@ -140,8 +142,7 @@ module.exports = {
|
|
140
142
|
type: "object",
|
141
143
|
properties: {
|
142
144
|
props: {
|
143
|
-
type: "boolean"
|
144
|
-
default: true
|
145
|
+
type: "boolean"
|
145
146
|
}
|
146
147
|
},
|
147
148
|
additionalProperties: false
|
@@ -155,7 +156,7 @@ module.exports = {
|
|
155
156
|
|
156
157
|
create(context) {
|
157
158
|
const sourceCode = context.sourceCode;
|
158
|
-
const [{ props
|
159
|
+
const [{ props }] = context.options;
|
159
160
|
|
160
161
|
/**
|
161
162
|
* Reports a given node as self assignments.
|
@@ -15,9 +15,6 @@ const astUtils = require("./utils/ast-utils");
|
|
15
15
|
// Helpers
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
-
const DEFAULT_OPTIONS = {
|
19
|
-
allowInParentheses: true
|
20
|
-
};
|
21
18
|
|
22
19
|
//------------------------------------------------------------------------------
|
23
20
|
// Rule Definition
|
@@ -38,20 +35,23 @@ module.exports = {
|
|
38
35
|
type: "object",
|
39
36
|
properties: {
|
40
37
|
allowInParentheses: {
|
41
|
-
type: "boolean"
|
42
|
-
default: true
|
38
|
+
type: "boolean"
|
43
39
|
}
|
44
40
|
},
|
45
41
|
additionalProperties: false
|
46
42
|
}],
|
47
43
|
|
44
|
+
defaultOptions: [{
|
45
|
+
allowInParentheses: true
|
46
|
+
}],
|
47
|
+
|
48
48
|
messages: {
|
49
49
|
unexpectedCommaExpression: "Unexpected use of comma operator."
|
50
50
|
}
|
51
51
|
},
|
52
52
|
|
53
53
|
create(context) {
|
54
|
-
const
|
54
|
+
const [{ allowInParentheses }] = context.options;
|
55
55
|
const sourceCode = context.sourceCode;
|
56
56
|
|
57
57
|
/**
|
@@ -117,7 +117,7 @@ module.exports = {
|
|
117
117
|
}
|
118
118
|
|
119
119
|
// Wrapping a sequence in extra parens indicates intent
|
120
|
-
if (
|
120
|
+
if (allowInParentheses) {
|
121
121
|
if (requiresExtraParens(node)) {
|
122
122
|
if (isParenthesisedTwice(node)) {
|
123
123
|
return;
|
package/lib/rules/no-shadow.js
CHANGED
@@ -29,6 +29,11 @@ module.exports = {
|
|
29
29
|
meta: {
|
30
30
|
type: "suggestion",
|
31
31
|
|
32
|
+
defaultOptions: [{
|
33
|
+
allow: [],
|
34
|
+
hoist: "functions"
|
35
|
+
}],
|
36
|
+
|
32
37
|
docs: {
|
33
38
|
description: "Disallow variable declarations from shadowing variables declared in the outer scope",
|
34
39
|
recommended: false,
|
@@ -39,7 +44,7 @@ module.exports = {
|
|
39
44
|
{
|
40
45
|
type: "object",
|
41
46
|
properties: {
|
42
|
-
builtinGlobals: { type: "boolean"
|
47
|
+
builtinGlobals: { type: "boolean" },
|
43
48
|
hoist: { enum: ["all", "functions", "never"], default: "functions" },
|
44
49
|
allow: {
|
45
50
|
type: "array",
|
@@ -47,7 +52,7 @@ module.exports = {
|
|
47
52
|
type: "string"
|
48
53
|
}
|
49
54
|
},
|
50
|
-
ignoreOnInitialization: { type: "boolean"
|
55
|
+
ignoreOnInitialization: { type: "boolean" }
|
51
56
|
},
|
52
57
|
additionalProperties: false
|
53
58
|
}
|
@@ -60,13 +65,12 @@ module.exports = {
|
|
60
65
|
},
|
61
66
|
|
62
67
|
create(context) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
};
|
68
|
+
const [{
|
69
|
+
builtinGlobals,
|
70
|
+
hoist,
|
71
|
+
allow,
|
72
|
+
ignoreOnInitialization
|
73
|
+
}] = context.options;
|
70
74
|
const sourceCode = context.sourceCode;
|
71
75
|
|
72
76
|
/**
|
@@ -174,7 +178,7 @@ module.exports = {
|
|
174
178
|
* @returns {boolean} Whether or not the variable name is allowed.
|
175
179
|
*/
|
176
180
|
function isAllowed(variable) {
|
177
|
-
return
|
181
|
+
return allow.includes(variable.name);
|
178
182
|
}
|
179
183
|
|
180
184
|
/**
|
@@ -269,7 +273,7 @@ module.exports = {
|
|
269
273
|
inner[1] < outer[0] &&
|
270
274
|
|
271
275
|
// Excepts FunctionDeclaration if is {"hoist":"function"}.
|
272
|
-
(
|
276
|
+
(hoist !== "functions" || !outerDef || outerDef.node.type !== "FunctionDeclaration")
|
273
277
|
);
|
274
278
|
}
|
275
279
|
|
@@ -296,10 +300,10 @@ module.exports = {
|
|
296
300
|
const shadowed = astUtils.getVariableByName(scope.upper, variable.name);
|
297
301
|
|
298
302
|
if (shadowed &&
|
299
|
-
(shadowed.identifiers.length > 0 || (
|
303
|
+
(shadowed.identifiers.length > 0 || (builtinGlobals && "writeable" in shadowed)) &&
|
300
304
|
!isOnInitializer(variable, shadowed) &&
|
301
|
-
!(
|
302
|
-
!(
|
305
|
+
!(ignoreOnInitialization && isInitPatternNode(variable, shadowed)) &&
|
306
|
+
!(hoist !== "all" && isInTdz(variable, shadowed))
|
303
307
|
) {
|
304
308
|
const location = getDeclaredLocation(shadowed);
|
305
309
|
const messageId = location.global ? "noShadowGlobal" : "noShadow";
|
package/lib/rules/no-undef.js
CHANGED
@@ -28,6 +28,8 @@ module.exports = {
|
|
28
28
|
meta: {
|
29
29
|
type: "problem",
|
30
30
|
|
31
|
+
defaultOptions: [{}],
|
32
|
+
|
31
33
|
docs: {
|
32
34
|
description: "Disallow the use of undeclared variables unless mentioned in `/*global */` comments",
|
33
35
|
recommended: true,
|
@@ -39,8 +41,7 @@ module.exports = {
|
|
39
41
|
type: "object",
|
40
42
|
properties: {
|
41
43
|
typeof: {
|
42
|
-
type: "boolean"
|
43
|
-
default: false
|
44
|
+
type: "boolean"
|
44
45
|
}
|
45
46
|
},
|
46
47
|
additionalProperties: false
|
@@ -52,8 +53,7 @@ module.exports = {
|
|
52
53
|
},
|
53
54
|
|
54
55
|
create(context) {
|
55
|
-
const
|
56
|
-
const considerTypeOf = options && options.typeof === true || false;
|
56
|
+
const [{ typeof: considerTypeOf }] = context.options;
|
57
57
|
const sourceCode = context.sourceCode;
|
58
58
|
|
59
59
|
return {
|
@@ -14,6 +14,17 @@ module.exports = {
|
|
14
14
|
meta: {
|
15
15
|
type: "suggestion",
|
16
16
|
|
17
|
+
defaultOptions: [{
|
18
|
+
allow: [],
|
19
|
+
allowAfterSuper: false,
|
20
|
+
allowAfterThis: false,
|
21
|
+
allowAfterThisConstructor: false,
|
22
|
+
allowFunctionParams: true,
|
23
|
+
allowInArrayDestructuring: true,
|
24
|
+
allowInObjectDestructuring: true,
|
25
|
+
enforceInMethodNames: false
|
26
|
+
}],
|
27
|
+
|
17
28
|
docs: {
|
18
29
|
description: "Disallow dangling underscores in identifiers",
|
19
30
|
recommended: false,
|
@@ -31,36 +42,28 @@ module.exports = {
|
|
31
42
|
}
|
32
43
|
},
|
33
44
|
allowAfterThis: {
|
34
|
-
type: "boolean"
|
35
|
-
default: false
|
45
|
+
type: "boolean"
|
36
46
|
},
|
37
47
|
allowAfterSuper: {
|
38
|
-
type: "boolean"
|
39
|
-
default: false
|
48
|
+
type: "boolean"
|
40
49
|
},
|
41
50
|
allowAfterThisConstructor: {
|
42
|
-
type: "boolean"
|
43
|
-
default: false
|
51
|
+
type: "boolean"
|
44
52
|
},
|
45
53
|
enforceInMethodNames: {
|
46
|
-
type: "boolean"
|
47
|
-
default: false
|
54
|
+
type: "boolean"
|
48
55
|
},
|
49
56
|
allowFunctionParams: {
|
50
|
-
type: "boolean"
|
51
|
-
default: true
|
57
|
+
type: "boolean"
|
52
58
|
},
|
53
59
|
enforceInClassFields: {
|
54
|
-
type: "boolean"
|
55
|
-
default: false
|
60
|
+
type: "boolean"
|
56
61
|
},
|
57
62
|
allowInArrayDestructuring: {
|
58
|
-
type: "boolean"
|
59
|
-
default: true
|
63
|
+
type: "boolean"
|
60
64
|
},
|
61
65
|
allowInObjectDestructuring: {
|
62
|
-
type: "boolean"
|
63
|
-
default: true
|
66
|
+
type: "boolean"
|
64
67
|
}
|
65
68
|
},
|
66
69
|
additionalProperties: false
|
@@ -73,17 +76,17 @@ module.exports = {
|
|
73
76
|
},
|
74
77
|
|
75
78
|
create(context) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
const [{
|
80
|
+
allow,
|
81
|
+
allowAfterSuper,
|
82
|
+
allowAfterThis,
|
83
|
+
allowAfterThisConstructor,
|
84
|
+
allowFunctionParams,
|
85
|
+
allowInArrayDestructuring,
|
86
|
+
allowInObjectDestructuring,
|
87
|
+
enforceInClassFields,
|
88
|
+
enforceInMethodNames
|
89
|
+
}] = context.options;
|
87
90
|
const sourceCode = context.sourceCode;
|
88
91
|
|
89
92
|
//-------------------------------------------------------------------------
|
@@ -97,7 +100,7 @@ module.exports = {
|
|
97
100
|
* @private
|
98
101
|
*/
|
99
102
|
function isAllowed(identifier) {
|
100
|
-
return
|
103
|
+
return allow.includes(identifier);
|
101
104
|
}
|
102
105
|
|
103
106
|
/**
|