eslint 7.28.0 → 7.32.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/CHANGELOG.md +58 -0
- package/README.md +17 -2
- package/lib/cli-engine/cli-engine.js +6 -0
- package/lib/cli.js +11 -2
- package/lib/config/default-config.js +52 -0
- package/lib/config/flat-config-array.js +125 -0
- package/lib/config/flat-config-schema.js +452 -0
- package/lib/config/rule-validator.js +169 -0
- package/lib/eslint/eslint.js +38 -2
- package/lib/init/npm-utils.js +1 -2
- package/lib/linter/linter.js +16 -12
- package/lib/options.js +6 -0
- package/lib/rule-tester/rule-tester.js +75 -13
- package/lib/rules/comma-style.js +3 -2
- package/lib/rules/consistent-return.js +3 -3
- package/lib/rules/curly.js +2 -11
- package/lib/rules/dot-notation.js +3 -3
- package/lib/rules/indent.js +2 -4
- package/lib/rules/no-fallthrough.js +17 -6
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/operator-assignment.js +6 -3
- package/lib/rules/prefer-arrow-callback.js +4 -4
- package/lib/rules/use-isnan.js +4 -1
- package/lib/source-code/source-code.js +2 -2
- package/package.json +5 -4
package/lib/linter/linter.js
CHANGED
@@ -37,8 +37,10 @@ const
|
|
37
37
|
const debug = require("debug")("eslint:linter");
|
38
38
|
const MAX_AUTOFIX_PASSES = 10;
|
39
39
|
const DEFAULT_PARSER_NAME = "espree";
|
40
|
+
const DEFAULT_ECMA_VERSION = 5;
|
40
41
|
const commentParser = new ConfigCommentParser();
|
41
42
|
const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, column: 1 } };
|
43
|
+
const parserSymbol = Symbol.for("eslint.RuleTester.parser");
|
42
44
|
|
43
45
|
//------------------------------------------------------------------------------
|
44
46
|
// Typedefs
|
@@ -432,10 +434,16 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
|
|
432
434
|
|
433
435
|
/**
|
434
436
|
* Normalize ECMAScript version from the initial config
|
435
|
-
* @param
|
437
|
+
* @param {Parser} parser The parser which uses this options.
|
438
|
+
* @param {number} ecmaVersion ECMAScript version from the initial config
|
436
439
|
* @returns {number} normalized ECMAScript version
|
437
440
|
*/
|
438
|
-
function normalizeEcmaVersion(ecmaVersion) {
|
441
|
+
function normalizeEcmaVersion(parser, ecmaVersion) {
|
442
|
+
if ((parser[parserSymbol] || parser) === espree) {
|
443
|
+
if (ecmaVersion === "latest") {
|
444
|
+
return espree.latestEcmaVersion;
|
445
|
+
}
|
446
|
+
}
|
439
447
|
|
440
448
|
/*
|
441
449
|
* Calculate ECMAScript edition number from official year version starting with
|
@@ -521,12 +529,13 @@ function normalizeVerifyOptions(providedOptions, config) {
|
|
521
529
|
|
522
530
|
/**
|
523
531
|
* Combines the provided parserOptions with the options from environments
|
524
|
-
* @param {
|
532
|
+
* @param {Parser} parser The parser which uses this options.
|
525
533
|
* @param {ParserOptions} providedOptions The provided 'parserOptions' key in a config
|
526
534
|
* @param {Environment[]} enabledEnvironments The environments enabled in configuration and with inline comments
|
527
535
|
* @returns {ParserOptions} Resulting parser options after merge
|
528
536
|
*/
|
529
|
-
function resolveParserOptions(
|
537
|
+
function resolveParserOptions(parser, providedOptions, enabledEnvironments) {
|
538
|
+
|
530
539
|
const parserOptionsFromEnv = enabledEnvironments
|
531
540
|
.filter(env => env.parserOptions)
|
532
541
|
.reduce((parserOptions, env) => merge(parserOptions, env.parserOptions), {});
|
@@ -542,12 +551,7 @@ function resolveParserOptions(parserName, providedOptions, enabledEnvironments)
|
|
542
551
|
mergedParserOptions.ecmaFeatures = Object.assign({}, mergedParserOptions.ecmaFeatures, { globalReturn: false });
|
543
552
|
}
|
544
553
|
|
545
|
-
|
546
|
-
* TODO: @aladdin-add
|
547
|
-
* 1. for a 3rd-party parser, do not normalize parserOptions
|
548
|
-
* 2. for espree, no need to do this (espree will do it)
|
549
|
-
*/
|
550
|
-
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(mergedParserOptions.ecmaVersion);
|
554
|
+
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(parser, mergedParserOptions.ecmaVersion);
|
551
555
|
|
552
556
|
return mergedParserOptions;
|
553
557
|
}
|
@@ -606,7 +610,7 @@ function getRuleOptions(ruleConfig) {
|
|
606
610
|
*/
|
607
611
|
function analyzeScope(ast, parserOptions, visitorKeys) {
|
608
612
|
const ecmaFeatures = parserOptions.ecmaFeatures || {};
|
609
|
-
const ecmaVersion = parserOptions.ecmaVersion ||
|
613
|
+
const ecmaVersion = parserOptions.ecmaVersion || DEFAULT_ECMA_VERSION;
|
610
614
|
|
611
615
|
return eslintScope.analyze(ast, {
|
612
616
|
ignoreEval: true,
|
@@ -1123,7 +1127,7 @@ class Linter {
|
|
1123
1127
|
.map(envName => getEnv(slots, envName))
|
1124
1128
|
.filter(env => env);
|
1125
1129
|
|
1126
|
-
const parserOptions = resolveParserOptions(
|
1130
|
+
const parserOptions = resolveParserOptions(parser, config.parserOptions || {}, enabledEnvs);
|
1127
1131
|
const configuredGlobals = resolveGlobals(config.globals || {}, enabledEnvs);
|
1128
1132
|
const settings = config.settings || {};
|
1129
1133
|
|
package/lib/options.js
CHANGED
@@ -290,6 +290,12 @@ module.exports = optionator({
|
|
290
290
|
default: "true",
|
291
291
|
description: "Prevent errors when pattern is unmatched"
|
292
292
|
},
|
293
|
+
{
|
294
|
+
option: "exit-on-fatal-error",
|
295
|
+
type: "Boolean",
|
296
|
+
default: "false",
|
297
|
+
description: "Exit with exit code 2 in case of fatal error"
|
298
|
+
},
|
293
299
|
{
|
294
300
|
option: "debug",
|
295
301
|
type: "Boolean",
|
@@ -53,6 +53,7 @@ const
|
|
53
53
|
const ajv = require("../shared/ajv")({ strictDefaults: true });
|
54
54
|
|
55
55
|
const espreePath = require.resolve("espree");
|
56
|
+
const parserSymbol = Symbol.for("eslint.RuleTester.parser");
|
56
57
|
|
57
58
|
//------------------------------------------------------------------------------
|
58
59
|
// Typedefs
|
@@ -71,6 +72,7 @@ const espreePath = require.resolve("espree");
|
|
71
72
|
* @property {{ [name: string]: any }} [parserOptions] Options for the parser.
|
72
73
|
* @property {{ [name: string]: "readonly" | "writable" | "off" }} [globals] The additional global variables.
|
73
74
|
* @property {{ [name: string]: boolean }} [env] Environments for the test case.
|
75
|
+
* @property {boolean} [only] Run only this test case or the subset of test cases with this property.
|
74
76
|
*/
|
75
77
|
|
76
78
|
/**
|
@@ -86,6 +88,7 @@ const espreePath = require.resolve("espree");
|
|
86
88
|
* @property {{ [name: string]: any }} [parserOptions] Options for the parser.
|
87
89
|
* @property {{ [name: string]: "readonly" | "writable" | "off" }} [globals] The additional global variables.
|
88
90
|
* @property {{ [name: string]: boolean }} [env] Environments for the test case.
|
91
|
+
* @property {boolean} [only] Run only this test case or the subset of test cases with this property.
|
89
92
|
*/
|
90
93
|
|
91
94
|
/**
|
@@ -121,7 +124,8 @@ const RuleTesterParameters = [
|
|
121
124
|
"filename",
|
122
125
|
"options",
|
123
126
|
"errors",
|
124
|
-
"output"
|
127
|
+
"output",
|
128
|
+
"only"
|
125
129
|
];
|
126
130
|
|
127
131
|
/*
|
@@ -236,6 +240,7 @@ function defineStartEndAsError(objName, node) {
|
|
236
240
|
});
|
237
241
|
}
|
238
242
|
|
243
|
+
|
239
244
|
/**
|
240
245
|
* Define `start`/`end` properties of all nodes of the given AST as throwing error.
|
241
246
|
* @param {ASTNode} ast The root node to errorize `start`/`end` properties.
|
@@ -255,8 +260,10 @@ function defineStartEndAsErrorInTree(ast, visitorKeys) {
|
|
255
260
|
* @returns {Parser} Wrapped parser object.
|
256
261
|
*/
|
257
262
|
function wrapParser(parser) {
|
263
|
+
|
258
264
|
if (typeof parser.parseForESLint === "function") {
|
259
265
|
return {
|
266
|
+
[parserSymbol]: parser,
|
260
267
|
parseForESLint(...args) {
|
261
268
|
const ret = parser.parseForESLint(...args);
|
262
269
|
|
@@ -265,7 +272,9 @@ function wrapParser(parser) {
|
|
265
272
|
}
|
266
273
|
};
|
267
274
|
}
|
275
|
+
|
268
276
|
return {
|
277
|
+
[parserSymbol]: parser,
|
269
278
|
parse(...args) {
|
270
279
|
const ast = parser.parse(...args);
|
271
280
|
|
@@ -282,6 +291,7 @@ function wrapParser(parser) {
|
|
282
291
|
// default separators for testing
|
283
292
|
const DESCRIBE = Symbol("describe");
|
284
293
|
const IT = Symbol("it");
|
294
|
+
const IT_ONLY = Symbol("itOnly");
|
285
295
|
|
286
296
|
/**
|
287
297
|
* This is `it` default handler if `it` don't exist.
|
@@ -400,6 +410,46 @@ class RuleTester {
|
|
400
410
|
this[IT] = value;
|
401
411
|
}
|
402
412
|
|
413
|
+
/**
|
414
|
+
* Adds the `only` property to a test to run it in isolation.
|
415
|
+
* @param {string | ValidTestCase | InvalidTestCase} item A single test to run by itself.
|
416
|
+
* @returns {ValidTestCase | InvalidTestCase} The test with `only` set.
|
417
|
+
*/
|
418
|
+
static only(item) {
|
419
|
+
if (typeof item === "string") {
|
420
|
+
return { code: item, only: true };
|
421
|
+
}
|
422
|
+
|
423
|
+
return { ...item, only: true };
|
424
|
+
}
|
425
|
+
|
426
|
+
static get itOnly() {
|
427
|
+
if (typeof this[IT_ONLY] === "function") {
|
428
|
+
return this[IT_ONLY];
|
429
|
+
}
|
430
|
+
if (typeof this[IT] === "function" && typeof this[IT].only === "function") {
|
431
|
+
return Function.bind.call(this[IT].only, this[IT]);
|
432
|
+
}
|
433
|
+
if (typeof it === "function" && typeof it.only === "function") {
|
434
|
+
return Function.bind.call(it.only, it);
|
435
|
+
}
|
436
|
+
|
437
|
+
if (typeof this[DESCRIBE] === "function" || typeof this[IT] === "function") {
|
438
|
+
throw new Error(
|
439
|
+
"Set `RuleTester.itOnly` to use `only` with a custom test framework.\n" +
|
440
|
+
"See https://eslint.org/docs/developer-guide/nodejs-api#customizing-ruletester for more."
|
441
|
+
);
|
442
|
+
}
|
443
|
+
if (typeof it === "function") {
|
444
|
+
throw new Error("The current test framework does not support exclusive tests with `only`.");
|
445
|
+
}
|
446
|
+
throw new Error("To use `only`, use RuleTester with a test framework that provides `it.only()` like Mocha.");
|
447
|
+
}
|
448
|
+
|
449
|
+
static set itOnly(value) {
|
450
|
+
this[IT_ONLY] = value;
|
451
|
+
}
|
452
|
+
|
403
453
|
/**
|
404
454
|
* Define a rule for one particular run of tests.
|
405
455
|
* @param {string} name The name of the rule to define.
|
@@ -610,7 +660,8 @@ class RuleTester {
|
|
610
660
|
const messages = result.messages;
|
611
661
|
|
612
662
|
assert.strictEqual(messages.length, 0, util.format("Should have no errors but had %d: %s",
|
613
|
-
messages.length,
|
663
|
+
messages.length,
|
664
|
+
util.inspect(messages)));
|
614
665
|
|
615
666
|
assertASTDidntChange(result.beforeAST, result.afterAST);
|
616
667
|
}
|
@@ -665,13 +716,18 @@ class RuleTester {
|
|
665
716
|
}
|
666
717
|
|
667
718
|
assert.strictEqual(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
|
668
|
-
item.errors,
|
719
|
+
item.errors,
|
720
|
+
item.errors === 1 ? "" : "s",
|
721
|
+
messages.length,
|
722
|
+
util.inspect(messages)));
|
669
723
|
} else {
|
670
724
|
assert.strictEqual(
|
671
|
-
messages.length, item.errors.length,
|
672
|
-
util.format(
|
725
|
+
messages.length, item.errors.length, util.format(
|
673
726
|
"Should have %d error%s but had %d: %s",
|
674
|
-
item.errors.length,
|
727
|
+
item.errors.length,
|
728
|
+
item.errors.length === 1 ? "" : "s",
|
729
|
+
messages.length,
|
730
|
+
util.inspect(messages)
|
675
731
|
)
|
676
732
|
);
|
677
733
|
|
@@ -885,23 +941,29 @@ class RuleTester {
|
|
885
941
|
RuleTester.describe(ruleName, () => {
|
886
942
|
RuleTester.describe("valid", () => {
|
887
943
|
test.valid.forEach(valid => {
|
888
|
-
RuleTester.
|
889
|
-
|
890
|
-
|
944
|
+
RuleTester[valid.only ? "itOnly" : "it"](
|
945
|
+
sanitize(typeof valid === "object" ? valid.code : valid),
|
946
|
+
() => {
|
947
|
+
testValidTemplate(valid);
|
948
|
+
}
|
949
|
+
);
|
891
950
|
});
|
892
951
|
});
|
893
952
|
|
894
953
|
RuleTester.describe("invalid", () => {
|
895
954
|
test.invalid.forEach(invalid => {
|
896
|
-
RuleTester
|
897
|
-
|
898
|
-
|
955
|
+
RuleTester[invalid.only ? "itOnly" : "it"](
|
956
|
+
sanitize(invalid.code),
|
957
|
+
() => {
|
958
|
+
testInvalidTemplate(invalid);
|
959
|
+
}
|
960
|
+
);
|
899
961
|
});
|
900
962
|
});
|
901
963
|
});
|
902
964
|
}
|
903
965
|
}
|
904
966
|
|
905
|
-
RuleTester[DESCRIBE] = RuleTester[IT] = null;
|
967
|
+
RuleTester[DESCRIBE] = RuleTester[IT] = RuleTester[IT_ONLY] = null;
|
906
968
|
|
907
969
|
module.exports = RuleTester;
|
package/lib/rules/comma-style.js
CHANGED
@@ -207,8 +207,7 @@ module.exports = {
|
|
207
207
|
* they are always valid regardless of an undefined item.
|
208
208
|
*/
|
209
209
|
if (astUtils.isCommaToken(commaToken)) {
|
210
|
-
validateCommaItemSpacing(previousItemToken, commaToken,
|
211
|
-
currentItemToken, reportItem);
|
210
|
+
validateCommaItemSpacing(previousItemToken, commaToken, currentItemToken, reportItem);
|
212
211
|
}
|
213
212
|
|
214
213
|
if (item) {
|
@@ -217,6 +216,8 @@ module.exports = {
|
|
217
216
|
previousItemToken = tokenAfterItem
|
218
217
|
? sourceCode.getTokenBefore(tokenAfterItem)
|
219
218
|
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
|
219
|
+
} else {
|
220
|
+
previousItemToken = currentItemToken;
|
220
221
|
}
|
221
222
|
});
|
222
223
|
|
@@ -104,18 +104,18 @@ module.exports = {
|
|
104
104
|
} else if (node.type === "ArrowFunctionExpression") {
|
105
105
|
|
106
106
|
// `=>` token
|
107
|
-
loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc
|
107
|
+
loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc;
|
108
108
|
} else if (
|
109
109
|
node.parent.type === "MethodDefinition" ||
|
110
110
|
(node.parent.type === "Property" && node.parent.method)
|
111
111
|
) {
|
112
112
|
|
113
113
|
// Method name.
|
114
|
-
loc = node.parent.key.loc
|
114
|
+
loc = node.parent.key.loc;
|
115
115
|
} else {
|
116
116
|
|
117
117
|
// Function name or `function` keyword.
|
118
|
-
loc = (node.id || node).loc
|
118
|
+
loc = (node.id || context.getSourceCode().getFirstToken(node)).loc;
|
119
119
|
}
|
120
120
|
|
121
121
|
if (!name) {
|
package/lib/rules/curly.js
CHANGED
@@ -131,15 +131,6 @@ module.exports = {
|
|
131
131
|
return token.value === "else" && token.type === "Keyword";
|
132
132
|
}
|
133
133
|
|
134
|
-
/**
|
135
|
-
* Gets the `else` keyword token of a given `IfStatement` node.
|
136
|
-
* @param {ASTNode} node A `IfStatement` node to get.
|
137
|
-
* @returns {Token} The `else` keyword token.
|
138
|
-
*/
|
139
|
-
function getElseKeyword(node) {
|
140
|
-
return node.alternate && sourceCode.getFirstTokenBetween(node.consequent, node.alternate, isElseKeywordToken);
|
141
|
-
}
|
142
|
-
|
143
134
|
/**
|
144
135
|
* Determines whether the given node has an `else` keyword token as the first token after.
|
145
136
|
* @param {ASTNode} node The node to check.
|
@@ -361,7 +352,7 @@ module.exports = {
|
|
361
352
|
if (this.expected) {
|
362
353
|
context.report({
|
363
354
|
node,
|
364
|
-
loc:
|
355
|
+
loc: body.loc,
|
365
356
|
messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
|
366
357
|
data: {
|
367
358
|
name
|
@@ -371,7 +362,7 @@ module.exports = {
|
|
371
362
|
} else {
|
372
363
|
context.report({
|
373
364
|
node,
|
374
|
-
loc:
|
365
|
+
loc: body.loc,
|
375
366
|
messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
|
376
367
|
data: {
|
377
368
|
name
|
@@ -94,7 +94,7 @@ module.exports = {
|
|
94
94
|
|
95
95
|
// Don't perform any fixes if there are comments inside the brackets.
|
96
96
|
if (sourceCode.commentsExistBetween(leftBracket, rightBracket)) {
|
97
|
-
return;
|
97
|
+
return;
|
98
98
|
}
|
99
99
|
|
100
100
|
// Replace the brackets by an identifier.
|
@@ -154,12 +154,12 @@ module.exports = {
|
|
154
154
|
|
155
155
|
// A statement that starts with `let[` is parsed as a destructuring variable declaration, not a MemberExpression.
|
156
156
|
if (node.object.type === "Identifier" && node.object.name === "let" && !node.optional) {
|
157
|
-
return;
|
157
|
+
return;
|
158
158
|
}
|
159
159
|
|
160
160
|
// Don't perform any fixes if there are comments between the dot and the property name.
|
161
161
|
if (sourceCode.commentsExistBetween(dotToken, node.property)) {
|
162
|
-
return;
|
162
|
+
return;
|
163
163
|
}
|
164
164
|
|
165
165
|
// Replace the identifier to brackets.
|
package/lib/rules/indent.js
CHANGED
@@ -1177,8 +1177,7 @@ module.exports = {
|
|
1177
1177
|
offsets.setDesiredOffset(questionMarkToken, firstToken, 1);
|
1178
1178
|
offsets.setDesiredOffset(colonToken, firstToken, 1);
|
1179
1179
|
|
1180
|
-
offsets.setDesiredOffset(firstConsequentToken, firstToken,
|
1181
|
-
firstConsequentToken.type === "Punctuator" &&
|
1180
|
+
offsets.setDesiredOffset(firstConsequentToken, firstToken, firstConsequentToken.type === "Punctuator" &&
|
1182
1181
|
options.offsetTernaryExpressions ? 2 : 1);
|
1183
1182
|
|
1184
1183
|
/*
|
@@ -1204,8 +1203,7 @@ module.exports = {
|
|
1204
1203
|
* If `baz` were aligned with `bar` rather than being offset by 1 from `foo`, `baz` would end up
|
1205
1204
|
* having no expected indentation.
|
1206
1205
|
*/
|
1207
|
-
offsets.setDesiredOffset(firstAlternateToken, firstToken,
|
1208
|
-
firstAlternateToken.type === "Punctuator" &&
|
1206
|
+
offsets.setDesiredOffset(firstAlternateToken, firstToken, firstAlternateToken.type === "Punctuator" &&
|
1209
1207
|
options.offsetTernaryExpressions ? 2 : 1);
|
1210
1208
|
}
|
1211
1209
|
}
|
@@ -11,15 +11,26 @@
|
|
11
11
|
const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
|
12
12
|
|
13
13
|
/**
|
14
|
-
* Checks whether or not a given
|
15
|
-
* @param {ASTNode}
|
14
|
+
* Checks whether or not a given case has a fallthrough comment.
|
15
|
+
* @param {ASTNode} caseWhichFallsThrough SwitchCase node which falls through.
|
16
|
+
* @param {ASTNode} subsequentCase The case after caseWhichFallsThrough.
|
16
17
|
* @param {RuleContext} context A rule context which stores comments.
|
17
18
|
* @param {RegExp} fallthroughCommentPattern A pattern to match comment to.
|
18
|
-
* @returns {boolean} `true` if the
|
19
|
+
* @returns {boolean} `true` if the case has a valid fallthrough comment.
|
19
20
|
*/
|
20
|
-
function hasFallthroughComment(
|
21
|
+
function hasFallthroughComment(caseWhichFallsThrough, subsequentCase, context, fallthroughCommentPattern) {
|
21
22
|
const sourceCode = context.getSourceCode();
|
22
|
-
|
23
|
+
|
24
|
+
if (caseWhichFallsThrough.consequent.length === 1 && caseWhichFallsThrough.consequent[0].type === "BlockStatement") {
|
25
|
+
const trailingCloseBrace = sourceCode.getLastToken(caseWhichFallsThrough.consequent[0]);
|
26
|
+
const commentInBlock = sourceCode.getCommentsBefore(trailingCloseBrace).pop();
|
27
|
+
|
28
|
+
if (commentInBlock && fallthroughCommentPattern.test(commentInBlock.value)) {
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
const comment = sourceCode.getCommentsBefore(subsequentCase).pop();
|
23
34
|
|
24
35
|
return Boolean(comment && fallthroughCommentPattern.test(comment.value));
|
25
36
|
}
|
@@ -108,7 +119,7 @@ module.exports = {
|
|
108
119
|
* Checks whether or not there is a fallthrough comment.
|
109
120
|
* And reports the previous fallthrough node if that does not exist.
|
110
121
|
*/
|
111
|
-
if (fallthroughCase && !hasFallthroughComment(node, context, fallthroughCommentPattern)) {
|
122
|
+
if (fallthroughCase && !hasFallthroughComment(fallthroughCase, node, context, fallthroughCommentPattern)) {
|
112
123
|
context.report({
|
113
124
|
messageId: node.test ? "case" : "default",
|
114
125
|
node
|
@@ -117,7 +117,7 @@ module.exports = {
|
|
117
117
|
],
|
118
118
|
|
119
119
|
messages: {
|
120
|
-
unexpectedMixedOperator: "Unexpected mix of '{{leftOperator}}' and '{{rightOperator}}'."
|
120
|
+
unexpectedMixedOperator: "Unexpected mix of '{{leftOperator}}' and '{{rightOperator}}'. Use parentheses to clarify the intended order of operations."
|
121
121
|
}
|
122
122
|
},
|
123
123
|
|
@@ -76,8 +76,8 @@ module.exports = {
|
|
76
76
|
|
77
77
|
fixable: "code",
|
78
78
|
messages: {
|
79
|
-
replaced: "Assignment can be replaced with operator assignment.",
|
80
|
-
unexpected: "Unexpected operator assignment shorthand."
|
79
|
+
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}=).",
|
80
|
+
unexpected: "Unexpected operator assignment ({{operator}}=) shorthand."
|
81
81
|
}
|
82
82
|
},
|
83
83
|
|
@@ -113,6 +113,7 @@ module.exports = {
|
|
113
113
|
context.report({
|
114
114
|
node,
|
115
115
|
messageId: "replaced",
|
116
|
+
data: { operator },
|
116
117
|
fix(fixer) {
|
117
118
|
if (canBeFixed(left) && canBeFixed(expr.left)) {
|
118
119
|
const equalsToken = getOperatorToken(node);
|
@@ -139,7 +140,8 @@ module.exports = {
|
|
139
140
|
*/
|
140
141
|
context.report({
|
141
142
|
node,
|
142
|
-
messageId: "replaced"
|
143
|
+
messageId: "replaced",
|
144
|
+
data: { operator }
|
143
145
|
});
|
144
146
|
}
|
145
147
|
}
|
@@ -155,6 +157,7 @@ module.exports = {
|
|
155
157
|
context.report({
|
156
158
|
node,
|
157
159
|
messageId: "unexpected",
|
160
|
+
data: { operator: node.operator },
|
158
161
|
fix(fixer) {
|
159
162
|
if (canBeFixed(node.left)) {
|
160
163
|
const firstToken = sourceCode.getFirstToken(node);
|
@@ -295,7 +295,7 @@ module.exports = {
|
|
295
295
|
* If the callback function has duplicates in its list of parameters (possible in sloppy mode),
|
296
296
|
* don't replace it with an arrow function, because this is a SyntaxError with arrow functions.
|
297
297
|
*/
|
298
|
-
return;
|
298
|
+
return;
|
299
299
|
}
|
300
300
|
|
301
301
|
// Remove `.bind(this)` if exists.
|
@@ -307,7 +307,7 @@ module.exports = {
|
|
307
307
|
* E.g. `(foo || function(){}).bind(this)`
|
308
308
|
*/
|
309
309
|
if (memberNode.type !== "MemberExpression") {
|
310
|
-
return;
|
310
|
+
return;
|
311
311
|
}
|
312
312
|
|
313
313
|
const callNode = memberNode.parent;
|
@@ -320,12 +320,12 @@ module.exports = {
|
|
320
320
|
* ^^^^^^^^^^^^
|
321
321
|
*/
|
322
322
|
if (astUtils.isParenthesised(sourceCode, memberNode)) {
|
323
|
-
return;
|
323
|
+
return;
|
324
324
|
}
|
325
325
|
|
326
326
|
// If comments exist in the `.bind(this)`, don't remove those.
|
327
327
|
if (sourceCode.commentsExistBetween(firstTokenToRemove, lastTokenToRemove)) {
|
328
|
-
return;
|
328
|
+
return;
|
329
329
|
}
|
330
330
|
|
331
331
|
yield fixer.removeRange([firstTokenToRemove.range[0], lastTokenToRemove.range[1]]);
|
package/lib/rules/use-isnan.js
CHANGED
@@ -21,7 +21,10 @@ const astUtils = require("./utils/ast-utils");
|
|
21
21
|
* @returns {boolean} `true` if the node is 'NaN' identifier.
|
22
22
|
*/
|
23
23
|
function isNaNIdentifier(node) {
|
24
|
-
return Boolean(node) &&
|
24
|
+
return Boolean(node) && (
|
25
|
+
astUtils.isSpecificId(node, "NaN") ||
|
26
|
+
astUtils.isSpecificMemberAccess(node, "Number", "NaN")
|
27
|
+
);
|
25
28
|
}
|
26
29
|
|
27
30
|
//------------------------------------------------------------------------------
|
@@ -349,7 +349,7 @@ class SourceCode extends TokenStore {
|
|
349
349
|
let currentToken = this.getTokenBefore(node, { includeComments: true });
|
350
350
|
|
351
351
|
while (currentToken && isCommentToken(currentToken)) {
|
352
|
-
if (node.parent && (currentToken.start < node.parent.start)) {
|
352
|
+
if (node.parent && node.parent.type !== "Program" && (currentToken.start < node.parent.start)) {
|
353
353
|
break;
|
354
354
|
}
|
355
355
|
comments.leading.push(currentToken);
|
@@ -361,7 +361,7 @@ class SourceCode extends TokenStore {
|
|
361
361
|
currentToken = this.getTokenAfter(node, { includeComments: true });
|
362
362
|
|
363
363
|
while (currentToken && isCommentToken(currentToken)) {
|
364
|
-
if (node.parent && (currentToken.end > node.parent.end)) {
|
364
|
+
if (node.parent && node.parent.type !== "Program" && (currentToken.end > node.parent.end)) {
|
365
365
|
break;
|
366
366
|
}
|
367
367
|
comments.trailing.push(currentToken);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.32.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -44,7 +44,8 @@
|
|
44
44
|
"bugs": "https://github.com/eslint/eslint/issues/",
|
45
45
|
"dependencies": {
|
46
46
|
"@babel/code-frame": "7.12.11",
|
47
|
-
"@eslint/eslintrc": "^0.4.
|
47
|
+
"@eslint/eslintrc": "^0.4.3",
|
48
|
+
"@humanwhocodes/config-array": "^0.5.0",
|
48
49
|
"ajv": "^6.10.0",
|
49
50
|
"chalk": "^4.0.0",
|
50
51
|
"cross-spawn": "^7.0.2",
|
@@ -95,14 +96,14 @@
|
|
95
96
|
"ejs": "^3.0.2",
|
96
97
|
"eslint": "file:.",
|
97
98
|
"eslint-config-eslint": "file:packages/eslint-config-eslint",
|
98
|
-
"eslint-plugin-eslint-plugin": "^3.
|
99
|
+
"eslint-plugin-eslint-plugin": "^3.5.3",
|
99
100
|
"eslint-plugin-internal-rules": "file:tools/internal-rules",
|
100
101
|
"eslint-plugin-jsdoc": "^25.4.3",
|
101
102
|
"eslint-plugin-node": "^11.1.0",
|
102
103
|
"eslint-release": "^2.0.0",
|
103
104
|
"eslump": "^3.0.0",
|
104
105
|
"esprima": "^4.0.1",
|
105
|
-
"fs-teardown": "
|
106
|
+
"fs-teardown": "0.1.1",
|
106
107
|
"glob": "^7.1.6",
|
107
108
|
"jsdoc": "^3.5.5",
|
108
109
|
"karma": "^6.1.1",
|