eslint 9.14.0 → 9.16.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 +14 -10
- 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 +7 -5
- package/lib/rules/grouped-accessor-pairs.js +3 -1
- package/lib/rules/id-denylist.js +2 -1
- package/lib/rules/id-length.js +11 -6
- package/lib/rules/id-match.js +18 -16
- package/lib/rules/new-cap.js +16 -35
- package/lib/rules/no-bitwise.js +7 -5
- package/lib/rules/no-compare-neg-zero.js +1 -1
- 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 +7 -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 +6 -4
- package/lib/rules/no-empty.js +6 -5
- package/lib/rules/no-eval.js +6 -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 +6 -4
- package/lib/rules/no-inline-comments.js +4 -6
- package/lib/rules/no-inner-declarations.js +5 -3
- 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 +7 -10
- package/lib/rules/no-plusplus.js +6 -9
- package/lib/rules/no-promise-executor-return.js +6 -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 +21 -15
- package/lib/rules/no-undef.js +6 -4
- package/lib/rules/no-underscore-dangle.js +32 -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 +6 -4
- package/lib/rules/no-unsafe-optional-chaining.js +6 -4
- package/lib/rules/no-unused-expressions.js +17 -13
- package/lib/rules/no-use-before-define.js +15 -13
- package/lib/rules/no-useless-computed-key.js +10 -4
- package/lib/rules/no-useless-rename.js +11 -8
- package/lib/rules/no-void.js +6 -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 +9 -5
- package/lib/rules/prefer-promise-reject-errors.js +7 -3
- package/lib/rules/prefer-regex-literals.js +6 -3
- package/lib/rules/radix.js +3 -1
- package/lib/rules/require-atomic-updates.js +6 -3
- package/lib/rules/sort-imports.js +20 -16
- package/lib/rules/sort-keys.js +22 -16
- package/lib/rules/sort-vars.js +7 -6
- package/lib/rules/strict.js +3 -2
- package/lib/rules/unicode-bom.js +4 -2
- package/lib/rules/use-isnan.js +8 -6
- package/lib/rules/utils/ast-utils.js +141 -0
- package/lib/rules/valid-typeof.js +6 -4
- 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 +7 -0
- package/package.json +11 -12
@@ -47,6 +47,8 @@ module.exports = {
|
|
47
47
|
meta: {
|
48
48
|
type: "problem",
|
49
49
|
|
50
|
+
defaultOptions: ["functions", { blockScopedFunctions: "allow" }],
|
51
|
+
|
50
52
|
docs: {
|
51
53
|
description: "Disallow variable or `function` declarations in nested blocks",
|
52
54
|
recommended: false,
|
@@ -74,10 +76,11 @@ module.exports = {
|
|
74
76
|
},
|
75
77
|
|
76
78
|
create(context) {
|
79
|
+
const both = context.options[0] === "both";
|
80
|
+
const { blockScopedFunctions } = context.options[1];
|
77
81
|
|
78
82
|
const sourceCode = context.sourceCode;
|
79
83
|
const ecmaVersion = context.languageOptions.ecmaVersion;
|
80
|
-
const blockScopedFunctions = context.options[1]?.blockScopedFunctions ?? "allow";
|
81
84
|
|
82
85
|
/**
|
83
86
|
* Ensure that a given node is at a program or function body's root.
|
@@ -107,7 +110,6 @@ module.exports = {
|
|
107
110
|
});
|
108
111
|
}
|
109
112
|
|
110
|
-
|
111
113
|
return {
|
112
114
|
|
113
115
|
FunctionDeclaration(node) {
|
@@ -120,7 +122,7 @@ module.exports = {
|
|
120
122
|
check(node);
|
121
123
|
},
|
122
124
|
VariableDeclaration(node) {
|
123
|
-
if (
|
125
|
+
if (both && node.kind === "var") {
|
124
126
|
check(node);
|
125
127
|
}
|
126
128
|
}
|
@@ -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,10 @@ module.exports = {
|
|
15
15
|
meta: {
|
16
16
|
type: "suggestion",
|
17
17
|
|
18
|
+
defaultOptions: [{
|
19
|
+
ignoreNonDeclaration: false
|
20
|
+
}],
|
21
|
+
|
18
22
|
docs: {
|
19
23
|
description: "Disallow use of chained assignment expressions",
|
20
24
|
recommended: false,
|
@@ -25,8 +29,7 @@ module.exports = {
|
|
25
29
|
type: "object",
|
26
30
|
properties: {
|
27
31
|
ignoreNonDeclaration: {
|
28
|
-
type: "boolean"
|
29
|
-
default: false
|
32
|
+
type: "boolean"
|
30
33
|
}
|
31
34
|
},
|
32
35
|
additionalProperties: false
|
@@ -38,19 +41,13 @@ module.exports = {
|
|
38
41
|
},
|
39
42
|
|
40
43
|
create(context) {
|
41
|
-
|
42
|
-
//--------------------------------------------------------------------------
|
43
|
-
// Public
|
44
|
-
//--------------------------------------------------------------------------
|
45
|
-
const options = context.options[0] || {
|
46
|
-
ignoreNonDeclaration: false
|
47
|
-
};
|
44
|
+
const [{ ignoreNonDeclaration }] = context.options;
|
48
45
|
const selectors = [
|
49
46
|
"VariableDeclarator > AssignmentExpression.init",
|
50
47
|
"PropertyDefinition > AssignmentExpression.value"
|
51
48
|
];
|
52
49
|
|
53
|
-
if (!
|
50
|
+
if (!ignoreNonDeclaration) {
|
54
51
|
selectors.push("AssignmentExpression > AssignmentExpression.right");
|
55
52
|
}
|
56
53
|
|
package/lib/rules/no-plusplus.js
CHANGED
@@ -50,6 +50,10 @@ module.exports = {
|
|
50
50
|
meta: {
|
51
51
|
type: "suggestion",
|
52
52
|
|
53
|
+
defaultOptions: [{
|
54
|
+
allowForLoopAfterthoughts: false
|
55
|
+
}],
|
56
|
+
|
53
57
|
docs: {
|
54
58
|
description: "Disallow the unary operators `++` and `--`",
|
55
59
|
recommended: false,
|
@@ -61,8 +65,7 @@ module.exports = {
|
|
61
65
|
type: "object",
|
62
66
|
properties: {
|
63
67
|
allowForLoopAfterthoughts: {
|
64
|
-
type: "boolean"
|
65
|
-
default: false
|
68
|
+
type: "boolean"
|
66
69
|
}
|
67
70
|
},
|
68
71
|
additionalProperties: false
|
@@ -75,13 +78,7 @@ module.exports = {
|
|
75
78
|
},
|
76
79
|
|
77
80
|
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
|
-
}
|
81
|
+
const [{ allowForLoopAfterthoughts }] = context.options;
|
85
82
|
|
86
83
|
return {
|
87
84
|
|
@@ -141,6 +141,10 @@ module.exports = {
|
|
141
141
|
meta: {
|
142
142
|
type: "problem",
|
143
143
|
|
144
|
+
defaultOptions: [{
|
145
|
+
allowVoid: false
|
146
|
+
}],
|
147
|
+
|
144
148
|
docs: {
|
145
149
|
description: "Disallow returning values from Promise executor functions",
|
146
150
|
recommended: false,
|
@@ -153,8 +157,7 @@ module.exports = {
|
|
153
157
|
type: "object",
|
154
158
|
properties: {
|
155
159
|
allowVoid: {
|
156
|
-
type: "boolean"
|
157
|
-
default: false
|
160
|
+
type: "boolean"
|
158
161
|
}
|
159
162
|
},
|
160
163
|
additionalProperties: false
|
@@ -172,12 +175,9 @@ module.exports = {
|
|
172
175
|
},
|
173
176
|
|
174
177
|
create(context) {
|
175
|
-
|
176
178
|
let funcInfo = null;
|
177
179
|
const sourceCode = context.sourceCode;
|
178
|
-
const {
|
179
|
-
allowVoid = false
|
180
|
-
} = context.options[0] || {};
|
180
|
+
const [{ allowVoid }] = context.options;
|
181
181
|
|
182
182
|
return {
|
183
183
|
|
@@ -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,13 @@ module.exports = {
|
|
29
29
|
meta: {
|
30
30
|
type: "suggestion",
|
31
31
|
|
32
|
+
defaultOptions: [{
|
33
|
+
allow: [],
|
34
|
+
builtinGlobals: false,
|
35
|
+
hoist: "functions",
|
36
|
+
ignoreOnInitialization: false
|
37
|
+
}],
|
38
|
+
|
32
39
|
docs: {
|
33
40
|
description: "Disallow variable declarations from shadowing variables declared in the outer scope",
|
34
41
|
recommended: false,
|
@@ -39,15 +46,15 @@ module.exports = {
|
|
39
46
|
{
|
40
47
|
type: "object",
|
41
48
|
properties: {
|
42
|
-
builtinGlobals: { type: "boolean"
|
43
|
-
hoist: { enum: ["all", "functions", "never"]
|
49
|
+
builtinGlobals: { type: "boolean" },
|
50
|
+
hoist: { enum: ["all", "functions", "never"] },
|
44
51
|
allow: {
|
45
52
|
type: "array",
|
46
53
|
items: {
|
47
54
|
type: "string"
|
48
55
|
}
|
49
56
|
},
|
50
|
-
ignoreOnInitialization: { type: "boolean"
|
57
|
+
ignoreOnInitialization: { type: "boolean" }
|
51
58
|
},
|
52
59
|
additionalProperties: false
|
53
60
|
}
|
@@ -60,13 +67,12 @@ module.exports = {
|
|
60
67
|
},
|
61
68
|
|
62
69
|
create(context) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
};
|
70
|
+
const [{
|
71
|
+
builtinGlobals,
|
72
|
+
hoist,
|
73
|
+
allow,
|
74
|
+
ignoreOnInitialization
|
75
|
+
}] = context.options;
|
70
76
|
const sourceCode = context.sourceCode;
|
71
77
|
|
72
78
|
/**
|
@@ -174,7 +180,7 @@ module.exports = {
|
|
174
180
|
* @returns {boolean} Whether or not the variable name is allowed.
|
175
181
|
*/
|
176
182
|
function isAllowed(variable) {
|
177
|
-
return
|
183
|
+
return allow.includes(variable.name);
|
178
184
|
}
|
179
185
|
|
180
186
|
/**
|
@@ -269,7 +275,7 @@ module.exports = {
|
|
269
275
|
inner[1] < outer[0] &&
|
270
276
|
|
271
277
|
// Excepts FunctionDeclaration if is {"hoist":"function"}.
|
272
|
-
(
|
278
|
+
(hoist !== "functions" || !outerDef || outerDef.node.type !== "FunctionDeclaration")
|
273
279
|
);
|
274
280
|
}
|
275
281
|
|
@@ -296,10 +302,10 @@ module.exports = {
|
|
296
302
|
const shadowed = astUtils.getVariableByName(scope.upper, variable.name);
|
297
303
|
|
298
304
|
if (shadowed &&
|
299
|
-
(shadowed.identifiers.length > 0 || (
|
305
|
+
(shadowed.identifiers.length > 0 || (builtinGlobals && "writeable" in shadowed)) &&
|
300
306
|
!isOnInitializer(variable, shadowed) &&
|
301
|
-
!(
|
302
|
-
!(
|
307
|
+
!(ignoreOnInitialization && isInitPatternNode(variable, shadowed)) &&
|
308
|
+
!(hoist !== "all" && isInTdz(variable, shadowed))
|
303
309
|
) {
|
304
310
|
const location = getDeclaredLocation(shadowed);
|
305
311
|
const messageId = location.global ? "noShadowGlobal" : "noShadow";
|
package/lib/rules/no-undef.js
CHANGED
@@ -28,6 +28,10 @@ module.exports = {
|
|
28
28
|
meta: {
|
29
29
|
type: "problem",
|
30
30
|
|
31
|
+
defaultOptions: [{
|
32
|
+
typeof: false
|
33
|
+
}],
|
34
|
+
|
31
35
|
docs: {
|
32
36
|
description: "Disallow the use of undeclared variables unless mentioned in `/*global */` comments",
|
33
37
|
recommended: true,
|
@@ -39,8 +43,7 @@ module.exports = {
|
|
39
43
|
type: "object",
|
40
44
|
properties: {
|
41
45
|
typeof: {
|
42
|
-
type: "boolean"
|
43
|
-
default: false
|
46
|
+
type: "boolean"
|
44
47
|
}
|
45
48
|
},
|
46
49
|
additionalProperties: false
|
@@ -52,8 +55,7 @@ module.exports = {
|
|
52
55
|
},
|
53
56
|
|
54
57
|
create(context) {
|
55
|
-
const
|
56
|
-
const considerTypeOf = options && options.typeof === true || false;
|
58
|
+
const [{ typeof: considerTypeOf }] = context.options;
|
57
59
|
const sourceCode = context.sourceCode;
|
58
60
|
|
59
61
|
return {
|