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/new-cap.js
CHANGED
@@ -29,23 +29,6 @@ const CAPS_ALLOWED = [
|
|
29
29
|
"BigInt"
|
30
30
|
];
|
31
31
|
|
32
|
-
/**
|
33
|
-
* Ensure that if the key is provided, it must be an array.
|
34
|
-
* @param {Object} obj Object to check with `key`.
|
35
|
-
* @param {string} key Object key to check on `obj`.
|
36
|
-
* @param {any} fallback If obj[key] is not present, this will be returned.
|
37
|
-
* @throws {TypeError} If key is not an own array type property of `obj`.
|
38
|
-
* @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
|
39
|
-
*/
|
40
|
-
function checkArray(obj, key, fallback) {
|
41
|
-
|
42
|
-
/* c8 ignore start */
|
43
|
-
if (Object.hasOwn(obj, key) && !Array.isArray(obj[key])) {
|
44
|
-
throw new TypeError(`${key}, if provided, must be an Array`);
|
45
|
-
}/* c8 ignore stop */
|
46
|
-
return obj[key] || fallback;
|
47
|
-
}
|
48
|
-
|
49
32
|
/**
|
50
33
|
* A reducer function to invert an array to an Object mapping the string form of the key, to `true`.
|
51
34
|
* @param {Object} map Accumulator object for the reduce.
|
@@ -63,11 +46,7 @@ function invert(map, key) {
|
|
63
46
|
* @returns {Object} Object with cap is new exceptions.
|
64
47
|
*/
|
65
48
|
function calculateCapIsNewExceptions(config) {
|
66
|
-
|
67
|
-
|
68
|
-
if (capIsNewExceptions !== CAPS_ALLOWED) {
|
69
|
-
capIsNewExceptions = capIsNewExceptions.concat(CAPS_ALLOWED);
|
70
|
-
}
|
49
|
+
const capIsNewExceptions = Array.from(new Set([...config.capIsNewExceptions, ...CAPS_ALLOWED]));
|
71
50
|
|
72
51
|
return capIsNewExceptions.reduce(invert, {});
|
73
52
|
}
|
@@ -92,12 +71,10 @@ module.exports = {
|
|
92
71
|
type: "object",
|
93
72
|
properties: {
|
94
73
|
newIsCap: {
|
95
|
-
type: "boolean"
|
96
|
-
default: true
|
74
|
+
type: "boolean"
|
97
75
|
},
|
98
76
|
capIsNew: {
|
99
|
-
type: "boolean"
|
100
|
-
default: true
|
77
|
+
type: "boolean"
|
101
78
|
},
|
102
79
|
newIsCapExceptions: {
|
103
80
|
type: "array",
|
@@ -118,13 +95,21 @@ module.exports = {
|
|
118
95
|
type: "string"
|
119
96
|
},
|
120
97
|
properties: {
|
121
|
-
type: "boolean"
|
122
|
-
default: true
|
98
|
+
type: "boolean"
|
123
99
|
}
|
124
100
|
},
|
125
101
|
additionalProperties: false
|
126
102
|
}
|
127
103
|
],
|
104
|
+
|
105
|
+
defaultOptions: [{
|
106
|
+
capIsNew: true,
|
107
|
+
capIsNewExceptions: CAPS_ALLOWED,
|
108
|
+
newIsCap: true,
|
109
|
+
newIsCapExceptions: [],
|
110
|
+
properties: true
|
111
|
+
}],
|
112
|
+
|
128
113
|
messages: {
|
129
114
|
upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
130
115
|
lower: "A constructor name should not start with a lowercase letter."
|
@@ -132,14 +117,10 @@ module.exports = {
|
|
132
117
|
},
|
133
118
|
|
134
119
|
create(context) {
|
135
|
-
|
136
|
-
const config = Object.assign({}, context.options[0]);
|
137
|
-
|
138
|
-
config.newIsCap = config.newIsCap !== false;
|
139
|
-
config.capIsNew = config.capIsNew !== false;
|
120
|
+
const [config] = context.options;
|
140
121
|
const skipProperties = config.properties === false;
|
141
122
|
|
142
|
-
const newIsCapExceptions =
|
123
|
+
const newIsCapExceptions = config.newIsCapExceptions.reduce(invert, {});
|
143
124
|
const newIsCapExceptionPattern = config.newIsCapExceptionPattern ? new RegExp(config.newIsCapExceptionPattern, "u") : null;
|
144
125
|
|
145
126
|
const capIsNewExceptions = calculateCapIsNewExceptions(config);
|
package/lib/rules/no-bitwise.js
CHANGED
@@ -25,6 +25,8 @@ module.exports = {
|
|
25
25
|
meta: {
|
26
26
|
type: "suggestion",
|
27
27
|
|
28
|
+
defaultOptions: [{ allow: [] }],
|
29
|
+
|
28
30
|
docs: {
|
29
31
|
description: "Disallow bitwise operators",
|
30
32
|
recommended: false,
|
@@ -43,8 +45,7 @@ module.exports = {
|
|
43
45
|
uniqueItems: true
|
44
46
|
},
|
45
47
|
int32Hint: {
|
46
|
-
type: "boolean"
|
47
|
-
default: false
|
48
|
+
type: "boolean"
|
48
49
|
}
|
49
50
|
},
|
50
51
|
additionalProperties: false
|
@@ -57,9 +58,7 @@ module.exports = {
|
|
57
58
|
},
|
58
59
|
|
59
60
|
create(context) {
|
60
|
-
const
|
61
|
-
const allowed = options.allow || [];
|
62
|
-
const int32Hint = options.int32Hint === true;
|
61
|
+
const [{ allow: allowed, int32Hint }] = context.options;
|
63
62
|
|
64
63
|
/**
|
65
64
|
* Reports an unexpected use of a bitwise operator.
|
@@ -33,6 +33,8 @@ module.exports = {
|
|
33
33
|
meta: {
|
34
34
|
type: "problem",
|
35
35
|
|
36
|
+
defaultOptions: ["except-parens"],
|
37
|
+
|
36
38
|
docs: {
|
37
39
|
description: "Disallow assignment operators in conditional expressions",
|
38
40
|
recommended: true,
|
@@ -54,9 +56,7 @@ module.exports = {
|
|
54
56
|
},
|
55
57
|
|
56
58
|
create(context) {
|
57
|
-
|
58
|
-
const prohibitAssign = (context.options[0] || "except-parens");
|
59
|
-
|
59
|
+
const [prohibitAssign] = context.options;
|
60
60
|
const sourceCode = context.sourceCode;
|
61
61
|
|
62
62
|
/**
|
package/lib/rules/no-console.js
CHANGED
@@ -20,6 +20,8 @@ module.exports = {
|
|
20
20
|
meta: {
|
21
21
|
type: "suggestion",
|
22
22
|
|
23
|
+
defaultOptions: [{}],
|
24
|
+
|
23
25
|
docs: {
|
24
26
|
description: "Disallow the use of `console`",
|
25
27
|
recommended: false,
|
@@ -52,8 +54,7 @@ module.exports = {
|
|
52
54
|
},
|
53
55
|
|
54
56
|
create(context) {
|
55
|
-
const
|
56
|
-
const allowed = options.allow || [];
|
57
|
+
const [{ allow: allowed = [] }] = context.options;
|
57
58
|
const sourceCode = context.sourceCode;
|
58
59
|
|
59
60
|
/**
|
@@ -20,6 +20,8 @@ module.exports = {
|
|
20
20
|
meta: {
|
21
21
|
type: "problem",
|
22
22
|
|
23
|
+
defaultOptions: [{ checkLoops: "allExceptWhileTrue" }],
|
24
|
+
|
23
25
|
docs: {
|
24
26
|
description: "Disallow constant expressions in conditions",
|
25
27
|
recommended: true,
|
@@ -44,14 +46,13 @@ module.exports = {
|
|
44
46
|
},
|
45
47
|
|
46
48
|
create(context) {
|
47
|
-
const options = context.options[0] || {};
|
48
|
-
let checkLoops = options.checkLoops ?? "allExceptWhileTrue";
|
49
49
|
const loopSetStack = [];
|
50
50
|
const sourceCode = context.sourceCode;
|
51
|
+
let [{ checkLoops }] = context.options;
|
51
52
|
|
52
|
-
if (
|
53
|
+
if (checkLoops === true) {
|
53
54
|
checkLoops = "all";
|
54
|
-
} else if (
|
55
|
+
} else if (checkLoops === false) {
|
55
56
|
checkLoops = "none";
|
56
57
|
}
|
57
58
|
|
@@ -232,6 +232,8 @@ module.exports = {
|
|
232
232
|
meta: {
|
233
233
|
type: "problem",
|
234
234
|
|
235
|
+
defaultOptions: [{}],
|
236
|
+
|
235
237
|
docs: {
|
236
238
|
description: "Disallow duplicate module imports",
|
237
239
|
recommended: false,
|
@@ -243,8 +245,7 @@ module.exports = {
|
|
243
245
|
type: "object",
|
244
246
|
properties: {
|
245
247
|
includeExports: {
|
246
|
-
type: "boolean"
|
247
|
-
default: false
|
248
|
+
type: "boolean"
|
248
249
|
}
|
249
250
|
},
|
250
251
|
additionalProperties: false
|
@@ -260,8 +261,8 @@ module.exports = {
|
|
260
261
|
},
|
261
262
|
|
262
263
|
create(context) {
|
263
|
-
const includeExports =
|
264
|
-
|
264
|
+
const [{ includeExports }] = context.options;
|
265
|
+
const modules = new Map();
|
265
266
|
const handlers = {
|
266
267
|
ImportDeclaration: handleImportsExports(
|
267
268
|
context,
|
@@ -21,6 +21,8 @@ module.exports = {
|
|
21
21
|
meta: {
|
22
22
|
type: "suggestion",
|
23
23
|
|
24
|
+
defaultOptions: [{ allowElseIf: true }],
|
25
|
+
|
24
26
|
docs: {
|
25
27
|
description: "Disallow `else` blocks after `return` statements in `if` statements",
|
26
28
|
recommended: false,
|
@@ -31,8 +33,7 @@ module.exports = {
|
|
31
33
|
type: "object",
|
32
34
|
properties: {
|
33
35
|
allowElseIf: {
|
34
|
-
type: "boolean"
|
35
|
-
default: true
|
36
|
+
type: "boolean"
|
36
37
|
}
|
37
38
|
},
|
38
39
|
additionalProperties: false
|
@@ -46,7 +47,7 @@ module.exports = {
|
|
46
47
|
},
|
47
48
|
|
48
49
|
create(context) {
|
49
|
-
|
50
|
+
const [{ allowElseIf }] = context.options;
|
50
51
|
const sourceCode = context.sourceCode;
|
51
52
|
|
52
53
|
//--------------------------------------------------------------------------
|
@@ -389,8 +390,6 @@ module.exports = {
|
|
389
390
|
}
|
390
391
|
}
|
391
392
|
|
392
|
-
const allowElseIf = !(context.options[0] && context.options[0].allowElseIf === false);
|
393
|
-
|
394
393
|
//--------------------------------------------------------------------------
|
395
394
|
// Public API
|
396
395
|
//--------------------------------------------------------------------------
|
@@ -94,6 +94,8 @@ module.exports = {
|
|
94
94
|
meta: {
|
95
95
|
type: "suggestion",
|
96
96
|
|
97
|
+
defaultOptions: [{ allow: [] }],
|
98
|
+
|
97
99
|
docs: {
|
98
100
|
description: "Disallow empty functions",
|
99
101
|
recommended: false,
|
@@ -120,9 +122,7 @@ module.exports = {
|
|
120
122
|
},
|
121
123
|
|
122
124
|
create(context) {
|
123
|
-
const
|
124
|
-
const allowed = options.allow || [];
|
125
|
-
|
125
|
+
const [{ allow }] = context.options;
|
126
126
|
const sourceCode = context.sourceCode;
|
127
127
|
|
128
128
|
/**
|
@@ -144,7 +144,7 @@ module.exports = {
|
|
144
144
|
filter: astUtils.isCommentToken
|
145
145
|
});
|
146
146
|
|
147
|
-
if (!
|
147
|
+
if (!allow.includes(kind) &&
|
148
148
|
node.body.type === "BlockStatement" &&
|
149
149
|
node.body.body.length === 0 &&
|
150
150
|
innerComments.length === 0
|
@@ -15,6 +15,8 @@ module.exports = {
|
|
15
15
|
meta: {
|
16
16
|
type: "problem",
|
17
17
|
|
18
|
+
defaultOptions: [{}],
|
19
|
+
|
18
20
|
docs: {
|
19
21
|
description: "Disallow empty destructuring patterns",
|
20
22
|
recommended: true,
|
@@ -26,8 +28,7 @@ module.exports = {
|
|
26
28
|
type: "object",
|
27
29
|
properties: {
|
28
30
|
allowObjectPatternsAsParameters: {
|
29
|
-
type: "boolean"
|
30
|
-
default: false
|
31
|
+
type: "boolean"
|
31
32
|
}
|
32
33
|
},
|
33
34
|
additionalProperties: false
|
@@ -40,8 +41,7 @@ module.exports = {
|
|
40
41
|
},
|
41
42
|
|
42
43
|
create(context) {
|
43
|
-
const
|
44
|
-
allowObjectPatternsAsParameters = options.allowObjectPatternsAsParameters || false;
|
44
|
+
const [{ allowObjectPatternsAsParameters }] = context.options;
|
45
45
|
|
46
46
|
return {
|
47
47
|
ObjectPattern(node) {
|
package/lib/rules/no-empty.js
CHANGED
@@ -20,6 +20,10 @@ module.exports = {
|
|
20
20
|
hasSuggestions: true,
|
21
21
|
type: "suggestion",
|
22
22
|
|
23
|
+
defaultOptions: [{
|
24
|
+
allowEmptyCatch: false
|
25
|
+
}],
|
26
|
+
|
23
27
|
docs: {
|
24
28
|
description: "Disallow empty block statements",
|
25
29
|
recommended: true,
|
@@ -31,8 +35,7 @@ module.exports = {
|
|
31
35
|
type: "object",
|
32
36
|
properties: {
|
33
37
|
allowEmptyCatch: {
|
34
|
-
type: "boolean"
|
35
|
-
default: false
|
38
|
+
type: "boolean"
|
36
39
|
}
|
37
40
|
},
|
38
41
|
additionalProperties: false
|
@@ -46,9 +49,7 @@ module.exports = {
|
|
46
49
|
},
|
47
50
|
|
48
51
|
create(context) {
|
49
|
-
const
|
50
|
-
allowEmptyCatch = options.allowEmptyCatch || false;
|
51
|
-
|
52
|
+
const [{ allowEmptyCatch }] = context.options;
|
52
53
|
const sourceCode = context.sourceCode;
|
53
54
|
|
54
55
|
return {
|
package/lib/rules/no-eval.js
CHANGED
@@ -42,6 +42,8 @@ module.exports = {
|
|
42
42
|
meta: {
|
43
43
|
type: "suggestion",
|
44
44
|
|
45
|
+
defaultOptions: [{}],
|
46
|
+
|
45
47
|
docs: {
|
46
48
|
description: "Disallow the use of `eval()`",
|
47
49
|
recommended: false,
|
@@ -52,7 +54,7 @@ module.exports = {
|
|
52
54
|
{
|
53
55
|
type: "object",
|
54
56
|
properties: {
|
55
|
-
allowIndirect: { type: "boolean"
|
57
|
+
allowIndirect: { type: "boolean" }
|
56
58
|
},
|
57
59
|
additionalProperties: false
|
58
60
|
}
|
@@ -64,10 +66,7 @@ module.exports = {
|
|
64
66
|
},
|
65
67
|
|
66
68
|
create(context) {
|
67
|
-
const allowIndirect =
|
68
|
-
context.options[0] &&
|
69
|
-
context.options[0].allowIndirect
|
70
|
-
);
|
69
|
+
const [{ allowIndirect }] = context.options;
|
71
70
|
const sourceCode = context.sourceCode;
|
72
71
|
let funcInfo = null;
|
73
72
|
|
@@ -20,6 +20,8 @@ module.exports = {
|
|
20
20
|
meta: {
|
21
21
|
type: "suggestion",
|
22
22
|
|
23
|
+
defaultOptions: [{ exceptions: [] }],
|
24
|
+
|
23
25
|
docs: {
|
24
26
|
description: "Disallow extending native types",
|
25
27
|
recommended: false,
|
@@ -48,10 +50,8 @@ module.exports = {
|
|
48
50
|
},
|
49
51
|
|
50
52
|
create(context) {
|
51
|
-
|
52
|
-
const config = context.options[0] || {};
|
53
53
|
const sourceCode = context.sourceCode;
|
54
|
-
const exceptions = new Set(
|
54
|
+
const exceptions = new Set(context.options[0].exceptions);
|
55
55
|
const modifiedBuiltins = new Set(
|
56
56
|
Object.keys(astUtils.ECMASCRIPT_GLOBALS)
|
57
57
|
.filter(builtin => builtin[0].toUpperCase() === builtin[0])
|
@@ -23,6 +23,8 @@ module.exports = {
|
|
23
23
|
meta: {
|
24
24
|
type: "suggestion",
|
25
25
|
|
26
|
+
defaultOptions: [{}],
|
27
|
+
|
26
28
|
docs: {
|
27
29
|
description: "Disallow unnecessary boolean casts",
|
28
30
|
recommended: true,
|
@@ -63,9 +65,7 @@ module.exports = {
|
|
63
65
|
|
64
66
|
create(context) {
|
65
67
|
const sourceCode = context.sourceCode;
|
66
|
-
const enforceForLogicalOperands = context.options
|
67
|
-
const enforceForInnerExpressions = context.options[0]?.enforceForInnerExpressions === true;
|
68
|
-
|
68
|
+
const [{ enforceForLogicalOperands, enforceForInnerExpressions }] = context.options;
|
69
69
|
|
70
70
|
// Node types which have a test which will coerce values to booleans.
|
71
71
|
const BOOLEAN_NODE_TYPES = new Set([
|
@@ -90,6 +90,11 @@ module.exports = {
|
|
90
90
|
meta: {
|
91
91
|
type: "problem",
|
92
92
|
|
93
|
+
defaultOptions: [{
|
94
|
+
allowEmptyCase: false,
|
95
|
+
reportUnusedFallthroughComment: false
|
96
|
+
}],
|
97
|
+
|
93
98
|
docs: {
|
94
99
|
description: "Disallow fallthrough of `case` statements",
|
95
100
|
recommended: true,
|
@@ -101,16 +106,13 @@ module.exports = {
|
|
101
106
|
type: "object",
|
102
107
|
properties: {
|
103
108
|
commentPattern: {
|
104
|
-
type: "string"
|
105
|
-
default: ""
|
109
|
+
type: "string"
|
106
110
|
},
|
107
111
|
allowEmptyCase: {
|
108
|
-
type: "boolean"
|
109
|
-
default: false
|
112
|
+
type: "boolean"
|
110
113
|
},
|
111
114
|
reportUnusedFallthroughComment: {
|
112
|
-
type: "boolean"
|
113
|
-
default: false
|
115
|
+
type: "boolean"
|
114
116
|
}
|
115
117
|
},
|
116
118
|
additionalProperties: false
|
@@ -124,25 +126,20 @@ module.exports = {
|
|
124
126
|
},
|
125
127
|
|
126
128
|
create(context) {
|
127
|
-
const options = context.options[0] || {};
|
128
129
|
const codePathSegments = [];
|
129
130
|
let currentCodePathSegments = new Set();
|
130
131
|
const sourceCode = context.sourceCode;
|
131
|
-
const allowEmptyCase = options
|
132
|
-
const
|
132
|
+
const [{ allowEmptyCase, commentPattern, reportUnusedFallthroughComment }] = context.options;
|
133
|
+
const fallthroughCommentPattern = commentPattern
|
134
|
+
? new RegExp(commentPattern, "u")
|
135
|
+
: DEFAULT_FALLTHROUGH_COMMENT;
|
133
136
|
|
134
137
|
/*
|
135
138
|
* We need to use leading comments of the next SwitchCase node because
|
136
139
|
* trailing comments is wrong if semicolons are omitted.
|
137
140
|
*/
|
138
141
|
let previousCase = null;
|
139
|
-
let fallthroughCommentPattern = null;
|
140
142
|
|
141
|
-
if (options.commentPattern) {
|
142
|
-
fallthroughCommentPattern = new RegExp(options.commentPattern, "u");
|
143
|
-
} else {
|
144
|
-
fallthroughCommentPattern = DEFAULT_FALLTHROUGH_COMMENT;
|
145
|
-
}
|
146
143
|
return {
|
147
144
|
|
148
145
|
onCodePathStart() {
|
@@ -14,6 +14,8 @@ module.exports = {
|
|
14
14
|
meta: {
|
15
15
|
type: "suggestion",
|
16
16
|
|
17
|
+
defaultOptions: [{ exceptions: [] }],
|
18
|
+
|
17
19
|
docs: {
|
18
20
|
description: "Disallow assignments to native objects or read-only global variables",
|
19
21
|
recommended: true,
|
@@ -40,9 +42,8 @@ module.exports = {
|
|
40
42
|
},
|
41
43
|
|
42
44
|
create(context) {
|
43
|
-
const config = context.options[0];
|
44
45
|
const sourceCode = context.sourceCode;
|
45
|
-
const exceptions =
|
46
|
+
const [{ exceptions }] = context.options;
|
46
47
|
|
47
48
|
/**
|
48
49
|
* Reports write references.
|
@@ -14,21 +14,6 @@ const astUtils = require("./utils/ast-utils");
|
|
14
14
|
const INDEX_OF_PATTERN = /^(?:i|lastI)ndexOf$/u;
|
15
15
|
const ALLOWABLE_OPERATORS = ["~", "!!", "+", "- -", "-", "*"];
|
16
16
|
|
17
|
-
/**
|
18
|
-
* Parses and normalizes an option object.
|
19
|
-
* @param {Object} options An option object to parse.
|
20
|
-
* @returns {Object} The parsed and normalized option object.
|
21
|
-
*/
|
22
|
-
function parseOptions(options) {
|
23
|
-
return {
|
24
|
-
boolean: "boolean" in options ? options.boolean : true,
|
25
|
-
number: "number" in options ? options.number : true,
|
26
|
-
string: "string" in options ? options.string : true,
|
27
|
-
disallowTemplateShorthand: "disallowTemplateShorthand" in options ? options.disallowTemplateShorthand : false,
|
28
|
-
allow: options.allow || []
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
17
|
/**
|
33
18
|
* Checks whether or not a node is a double logical negating.
|
34
19
|
* @param {ASTNode} node An UnaryExpression node to check.
|
@@ -203,20 +188,16 @@ module.exports = {
|
|
203
188
|
type: "object",
|
204
189
|
properties: {
|
205
190
|
boolean: {
|
206
|
-
type: "boolean"
|
207
|
-
default: true
|
191
|
+
type: "boolean"
|
208
192
|
},
|
209
193
|
number: {
|
210
|
-
type: "boolean"
|
211
|
-
default: true
|
194
|
+
type: "boolean"
|
212
195
|
},
|
213
196
|
string: {
|
214
|
-
type: "boolean"
|
215
|
-
default: true
|
197
|
+
type: "boolean"
|
216
198
|
},
|
217
199
|
disallowTemplateShorthand: {
|
218
|
-
type: "boolean"
|
219
|
-
default: false
|
200
|
+
type: "boolean"
|
220
201
|
},
|
221
202
|
allow: {
|
222
203
|
type: "array",
|
@@ -229,6 +210,14 @@ module.exports = {
|
|
229
210
|
additionalProperties: false
|
230
211
|
}],
|
231
212
|
|
213
|
+
defaultOptions: [{
|
214
|
+
allow: [],
|
215
|
+
boolean: true,
|
216
|
+
disallowTemplateShorthand: false,
|
217
|
+
number: true,
|
218
|
+
string: true
|
219
|
+
}],
|
220
|
+
|
232
221
|
messages: {
|
233
222
|
implicitCoercion: "Unexpected implicit coercion encountered. Use `{{recommendation}}` instead.",
|
234
223
|
useRecommendation: "Use `{{recommendation}}` instead."
|
@@ -236,7 +225,7 @@ module.exports = {
|
|
236
225
|
},
|
237
226
|
|
238
227
|
create(context) {
|
239
|
-
const options =
|
228
|
+
const [options] = context.options;
|
240
229
|
const sourceCode = context.sourceCode;
|
241
230
|
|
242
231
|
/**
|
@@ -14,6 +14,8 @@ module.exports = {
|
|
14
14
|
meta: {
|
15
15
|
type: "suggestion",
|
16
16
|
|
17
|
+
defaultOptions: [{}],
|
18
|
+
|
17
19
|
docs: {
|
18
20
|
description: "Disallow declarations in the global scope",
|
19
21
|
recommended: false,
|
@@ -24,8 +26,7 @@ module.exports = {
|
|
24
26
|
type: "object",
|
25
27
|
properties: {
|
26
28
|
lexicalBindings: {
|
27
|
-
type: "boolean"
|
28
|
-
default: false
|
29
|
+
type: "boolean"
|
29
30
|
}
|
30
31
|
},
|
31
32
|
additionalProperties: false
|
@@ -41,8 +42,7 @@ module.exports = {
|
|
41
42
|
},
|
42
43
|
|
43
44
|
create(context) {
|
44
|
-
|
45
|
-
const checkLexicalBindings = context.options[0] && context.options[0].lexicalBindings === true;
|
45
|
+
const [{ lexicalBindings: checkLexicalBindings }] = context.options;
|
46
46
|
const sourceCode = context.sourceCode;
|
47
47
|
|
48
48
|
/**
|
@@ -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 inline comments after code",
|
20
22
|
recommended: false,
|
@@ -40,12 +42,8 @@ module.exports = {
|
|
40
42
|
|
41
43
|
create(context) {
|
42
44
|
const sourceCode = context.sourceCode;
|
43
|
-
const
|
44
|
-
|
45
|
-
|
46
|
-
if (options && options.ignorePattern) {
|
47
|
-
customIgnoreRegExp = new RegExp(options.ignorePattern, "u");
|
48
|
-
}
|
45
|
+
const [{ ignorePattern }] = context.options;
|
46
|
+
const customIgnoreRegExp = ignorePattern && new RegExp(ignorePattern, "u");
|
49
47
|
|
50
48
|
/**
|
51
49
|
* Will check that comments are not on lines starting with or ending with code
|
@@ -47,6 +47,8 @@ module.exports = {
|
|
47
47
|
meta: {
|
48
48
|
type: "problem",
|
49
49
|
|
50
|
+
defaultOptions: ["functions"],
|
51
|
+
|
50
52
|
docs: {
|
51
53
|
description: "Disallow variable or `function` declarations in nested blocks",
|
52
54
|
recommended: false,
|
@@ -74,6 +76,7 @@ module.exports = {
|
|
74
76
|
},
|
75
77
|
|
76
78
|
create(context) {
|
79
|
+
const both = context.options[0] === "both";
|
77
80
|
|
78
81
|
const sourceCode = context.sourceCode;
|
79
82
|
const ecmaVersion = context.languageOptions.ecmaVersion;
|
@@ -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
|
}
|