eslint 6.3.0 → 6.6.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 +126 -0
- package/README.md +11 -10
- package/bin/eslint.js +38 -12
- package/lib/cli-engine/cascading-config-array-factory.js +2 -1
- package/lib/cli-engine/cli-engine.js +11 -11
- package/lib/cli-engine/config-array/config-array.js +0 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +4 -2
- package/lib/cli-engine/config-array-factory.js +7 -1
- package/lib/cli-engine/file-enumerator.js +5 -3
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/cli-engine/ignored-paths.js +4 -3
- package/lib/cli-engine/lint-result-cache.js +0 -1
- package/lib/cli.js +13 -12
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +0 -1
- package/lib/init/config-rule.js +3 -7
- package/lib/init/npm-utils.js +1 -6
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +9 -13
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -96
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/options.js +6 -0
- package/lib/rule-tester/rule-tester.js +7 -10
- package/lib/rules/accessor-pairs.js +59 -19
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/capitalized-comments.js +2 -9
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +15 -23
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +28 -11
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +3 -5
- package/lib/rules/default-param-last.js +62 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/eqeqeq.js +7 -19
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +5 -5
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +46 -8
- package/lib/rules/index.js +3 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/new-parens.js +5 -1
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +12 -13
- package/lib/rules/no-extra-boolean-cast.js +1 -3
- package/lib/rules/no-extra-label.js +13 -10
- package/lib/rules/no-extra-parens.js +32 -17
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-import-assign.js +238 -0
- package/lib/rules/no-invalid-this.js +1 -3
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +7 -2
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-obj-calls.js +29 -9
- package/lib/rules/no-octal-escape.js +14 -8
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +105 -45
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +18 -18
- package/lib/rules/no-sequences.js +5 -5
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-undef-init.js +7 -1
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +34 -19
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +3 -5
- package/lib/rules/no-useless-rename.js +32 -20
- package/lib/rules/no-useless-return.js +11 -17
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +14 -15
- package/lib/rules/object-shorthand.js +36 -10
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +22 -1
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +13 -21
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-named-capture-group.js +3 -16
- package/lib/rules/prefer-numeric-literals.js +35 -3
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-regex-literals.js +125 -0
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +11 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +2 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-before-function-paren.js +12 -1
- package/lib/rules/space-in-parens.js +81 -75
- package/lib/rules/space-infix-ops.js +5 -5
- package/lib/rules/spaced-comment.js +15 -18
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +104 -6
- package/lib/rules/utils/ast-utils.js +53 -81
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/logging.js +2 -0
- package/lib/shared/runtime-info.js +163 -0
- package/lib/shared/traverser.js +2 -0
- package/lib/source-code/source-code.js +11 -12
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +8 -5
@@ -11,8 +11,7 @@
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Checks whether a given code path segment is reachable or not.
|
14
|
-
*
|
15
|
-
* @param {CodePathSegment} segment - A code path segment to check.
|
14
|
+
* @param {CodePathSegment} segment A code path segment to check.
|
16
15
|
* @returns {boolean} `true` if the segment is reachable.
|
17
16
|
*/
|
18
17
|
function isReachable(segment) {
|
@@ -21,7 +20,7 @@ function isReachable(segment) {
|
|
21
20
|
|
22
21
|
/**
|
23
22
|
* Checks whether or not a given node is a constructor.
|
24
|
-
* @param {ASTNode} node
|
23
|
+
* @param {ASTNode} node A node to check. This node type is one of
|
25
24
|
* `Program`, `FunctionDeclaration`, `FunctionExpression`, and
|
26
25
|
* `ArrowFunctionExpression`.
|
27
26
|
* @returns {boolean} `true` if the node is a constructor.
|
@@ -36,8 +35,7 @@ function isConstructorFunction(node) {
|
|
36
35
|
|
37
36
|
/**
|
38
37
|
* Checks whether a given node can be a constructor or not.
|
39
|
-
*
|
40
|
-
* @param {ASTNode} node - A node to check.
|
38
|
+
* @param {ASTNode} node A node to check.
|
41
39
|
* @returns {boolean} `true` if the node can be a constructor.
|
42
40
|
*/
|
43
41
|
function isPossibleConstructor(node) {
|
@@ -137,7 +135,7 @@ module.exports = {
|
|
137
135
|
|
138
136
|
/**
|
139
137
|
* Gets the flag which shows `super()` is called in some paths.
|
140
|
-
* @param {CodePathSegment} segment
|
138
|
+
* @param {CodePathSegment} segment A code path segment to get.
|
141
139
|
* @returns {boolean} The flag which shows `super()` is called in some paths
|
142
140
|
*/
|
143
141
|
function isCalledInSomePath(segment) {
|
@@ -146,7 +144,7 @@ module.exports = {
|
|
146
144
|
|
147
145
|
/**
|
148
146
|
* Gets the flag which shows `super()` is called in all paths.
|
149
|
-
* @param {CodePathSegment} segment
|
147
|
+
* @param {CodePathSegment} segment A code path segment to get.
|
150
148
|
* @returns {boolean} The flag which shows `super()` is called in all paths.
|
151
149
|
*/
|
152
150
|
function isCalledInEveryPath(segment) {
|
@@ -168,8 +166,8 @@ module.exports = {
|
|
168
166
|
|
169
167
|
/**
|
170
168
|
* Stacks a constructor information.
|
171
|
-
* @param {CodePath} codePath
|
172
|
-
* @param {ASTNode} node
|
169
|
+
* @param {CodePath} codePath A code path which was started.
|
170
|
+
* @param {ASTNode} node The current node.
|
173
171
|
* @returns {void}
|
174
172
|
*/
|
175
173
|
onCodePathStart(codePath, node) {
|
@@ -200,8 +198,8 @@ module.exports = {
|
|
200
198
|
/**
|
201
199
|
* Pops a constructor information.
|
202
200
|
* And reports if `super()` lacked.
|
203
|
-
* @param {CodePath} codePath
|
204
|
-
* @param {ASTNode} node
|
201
|
+
* @param {CodePath} codePath A code path which was ended.
|
202
|
+
* @param {ASTNode} node The current node.
|
205
203
|
* @returns {void}
|
206
204
|
*/
|
207
205
|
onCodePathEnd(codePath, node) {
|
@@ -231,7 +229,7 @@ module.exports = {
|
|
231
229
|
|
232
230
|
/**
|
233
231
|
* Initialize information of a given code path segment.
|
234
|
-
* @param {CodePathSegment} segment
|
232
|
+
* @param {CodePathSegment} segment A code path segment to initialize.
|
235
233
|
* @returns {void}
|
236
234
|
*/
|
237
235
|
onCodePathSegmentStart(segment) {
|
@@ -258,9 +256,9 @@ module.exports = {
|
|
258
256
|
/**
|
259
257
|
* Update information of the code path segment when a code path was
|
260
258
|
* looped.
|
261
|
-
* @param {CodePathSegment} fromSegment
|
259
|
+
* @param {CodePathSegment} fromSegment The code path segment of the
|
262
260
|
* end of a loop.
|
263
|
-
* @param {CodePathSegment} toSegment
|
261
|
+
* @param {CodePathSegment} toSegment A code path segment of the head
|
264
262
|
* of a loop.
|
265
263
|
* @returns {void}
|
266
264
|
*/
|
@@ -303,7 +301,7 @@ module.exports = {
|
|
303
301
|
|
304
302
|
/**
|
305
303
|
* Checks for a call of `super()`.
|
306
|
-
* @param {ASTNode} node
|
304
|
+
* @param {ASTNode} node A CallExpression node to check.
|
307
305
|
* @returns {void}
|
308
306
|
*/
|
309
307
|
"CallExpression:exit"(node) {
|
@@ -358,7 +356,7 @@ module.exports = {
|
|
358
356
|
|
359
357
|
/**
|
360
358
|
* Set the mark to the returned path as `super()` was called.
|
361
|
-
* @param {ASTNode} node
|
359
|
+
* @param {ASTNode} node A ReturnStatement node to check.
|
362
360
|
* @returns {void}
|
363
361
|
*/
|
364
362
|
ReturnStatement(node) {
|
package/lib/rules/curly.js
CHANGED
@@ -119,8 +119,7 @@ module.exports = {
|
|
119
119
|
|
120
120
|
/**
|
121
121
|
* Checks if the given token is an `else` token or not.
|
122
|
-
*
|
123
|
-
* @param {Token} token - The token to check.
|
122
|
+
* @param {Token} token The token to check.
|
124
123
|
* @returns {boolean} `true` if the token is an `else` token.
|
125
124
|
*/
|
126
125
|
function isElseKeywordToken(token) {
|
@@ -129,7 +128,7 @@ module.exports = {
|
|
129
128
|
|
130
129
|
/**
|
131
130
|
* Gets the `else` keyword token of a given `IfStatement` node.
|
132
|
-
* @param {ASTNode} node
|
131
|
+
* @param {ASTNode} node A `IfStatement` node to get.
|
133
132
|
* @returns {Token} The `else` keyword token.
|
134
133
|
*/
|
135
134
|
function getElseKeyword(node) {
|
@@ -143,8 +142,7 @@ module.exports = {
|
|
143
142
|
* 1. The given node has the `alternate` node.
|
144
143
|
* 2. There is a `IfStatement` which doesn't have `alternate` node in the
|
145
144
|
* trailing statement chain of the `consequent` node.
|
146
|
-
*
|
147
|
-
* @param {ASTNode} node - A IfStatement node to check.
|
145
|
+
* @param {ASTNode} node A IfStatement node to check.
|
148
146
|
* @returns {boolean} `true` if the node requires braces of the consequent chunk.
|
149
147
|
*/
|
150
148
|
function requiresBraceOfConsequent(node) {
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview enforce default parameters to be last
|
3
|
+
* @author Chiawen Chen
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
module.exports = {
|
9
|
+
meta: {
|
10
|
+
type: "suggestion",
|
11
|
+
|
12
|
+
docs: {
|
13
|
+
description: "enforce default parameters to be last",
|
14
|
+
category: "Best Practices",
|
15
|
+
recommended: false,
|
16
|
+
url: "https://eslint.org/docs/rules/default-param-last"
|
17
|
+
},
|
18
|
+
|
19
|
+
schema: [],
|
20
|
+
|
21
|
+
messages: {
|
22
|
+
shouldBeLast: "Default parameters should be last."
|
23
|
+
}
|
24
|
+
},
|
25
|
+
|
26
|
+
create(context) {
|
27
|
+
|
28
|
+
// eslint-disable-next-line jsdoc/require-description
|
29
|
+
/**
|
30
|
+
* @param {ASTNode} node function node
|
31
|
+
* @returns {void}
|
32
|
+
*/
|
33
|
+
function handleFunction(node) {
|
34
|
+
let hasSeenPlainParam = false;
|
35
|
+
|
36
|
+
for (let i = node.params.length - 1; i >= 0; i -= 1) {
|
37
|
+
const param = node.params[i];
|
38
|
+
|
39
|
+
if (
|
40
|
+
param.type !== "AssignmentPattern" &&
|
41
|
+
param.type !== "RestElement"
|
42
|
+
) {
|
43
|
+
hasSeenPlainParam = true;
|
44
|
+
continue;
|
45
|
+
}
|
46
|
+
|
47
|
+
if (hasSeenPlainParam && param.type === "AssignmentPattern") {
|
48
|
+
context.report({
|
49
|
+
node: param,
|
50
|
+
messageId: "shouldBeLast"
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return {
|
57
|
+
FunctionDeclaration: handleFunction,
|
58
|
+
FunctionExpression: handleFunction,
|
59
|
+
ArrowFunctionExpression: handleFunction
|
60
|
+
};
|
61
|
+
}
|
62
|
+
};
|
@@ -47,19 +47,18 @@ module.exports = {
|
|
47
47
|
|
48
48
|
/**
|
49
49
|
* Reports if the dot between object and property is on the correct loccation.
|
50
|
-
* @param {ASTNode}
|
51
|
-
* @param {ASTNode} prop The property of the object.
|
52
|
-
* @param {ASTNode} node The corresponding node of the token.
|
50
|
+
* @param {ASTNode} node The `MemberExpression` node.
|
53
51
|
* @returns {void}
|
54
52
|
*/
|
55
|
-
function checkDotLocation(
|
56
|
-
const
|
53
|
+
function checkDotLocation(node) {
|
54
|
+
const property = node.property;
|
55
|
+
const dot = sourceCode.getTokenBefore(property);
|
57
56
|
|
58
57
|
// `obj` expression can be parenthesized, but those paren tokens are not a part of the `obj` node.
|
59
58
|
const tokenBeforeDot = sourceCode.getTokenBefore(dot);
|
60
59
|
|
61
60
|
const textBeforeDot = sourceCode.getText().slice(tokenBeforeDot.range[1], dot.range[0]);
|
62
|
-
const textAfterDot = sourceCode.getText().slice(dot.range[1],
|
61
|
+
const textAfterDot = sourceCode.getText().slice(dot.range[1], property.range[0]);
|
63
62
|
|
64
63
|
if (onObject) {
|
65
64
|
if (!astUtils.isTokenOnSameLine(tokenBeforeDot, dot)) {
|
@@ -67,17 +66,17 @@ module.exports = {
|
|
67
66
|
|
68
67
|
context.report({
|
69
68
|
node,
|
70
|
-
loc: dot.loc
|
69
|
+
loc: dot.loc,
|
71
70
|
messageId: "expectedDotAfterObject",
|
72
|
-
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1],
|
71
|
+
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${neededTextAfterToken}.${textBeforeDot}${textAfterDot}`)
|
73
72
|
});
|
74
73
|
}
|
75
|
-
} else if (!astUtils.isTokenOnSameLine(dot,
|
74
|
+
} else if (!astUtils.isTokenOnSameLine(dot, property)) {
|
76
75
|
context.report({
|
77
76
|
node,
|
78
|
-
loc: dot.loc
|
77
|
+
loc: dot.loc,
|
79
78
|
messageId: "expectedDotBeforeProperty",
|
80
|
-
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1],
|
79
|
+
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${textBeforeDot}${textAfterDot}.`)
|
81
80
|
});
|
82
81
|
}
|
83
82
|
}
|
@@ -89,7 +88,7 @@ module.exports = {
|
|
89
88
|
*/
|
90
89
|
function checkNode(node) {
|
91
90
|
if (!node.computed) {
|
92
|
-
checkDotLocation(node
|
91
|
+
checkDotLocation(node);
|
93
92
|
}
|
94
93
|
}
|
95
94
|
|
package/lib/rules/eqeqeq.js
CHANGED
@@ -116,18 +116,6 @@ module.exports = {
|
|
116
116
|
return astUtils.isNullLiteral(node.right) || astUtils.isNullLiteral(node.left);
|
117
117
|
}
|
118
118
|
|
119
|
-
/**
|
120
|
-
* Gets the location (line and column) of the binary expression's operator
|
121
|
-
* @param {ASTNode} node The binary expression node to check
|
122
|
-
* @returns {Object} { line, column } location of operator
|
123
|
-
* @private
|
124
|
-
*/
|
125
|
-
function getOperatorLocation(node) {
|
126
|
-
const opToken = sourceCode.getTokenAfter(node.left);
|
127
|
-
|
128
|
-
return { line: opToken.loc.start.line, column: opToken.loc.start.column };
|
129
|
-
}
|
130
|
-
|
131
119
|
/**
|
132
120
|
* Reports a message for this rule.
|
133
121
|
* @param {ASTNode} node The binary expression node that was checked
|
@@ -136,21 +124,21 @@ module.exports = {
|
|
136
124
|
* @private
|
137
125
|
*/
|
138
126
|
function report(node, expectedOperator) {
|
127
|
+
const operatorToken = sourceCode.getFirstTokenBetween(
|
128
|
+
node.left,
|
129
|
+
node.right,
|
130
|
+
token => token.value === node.operator
|
131
|
+
);
|
132
|
+
|
139
133
|
context.report({
|
140
134
|
node,
|
141
|
-
loc:
|
135
|
+
loc: operatorToken.loc,
|
142
136
|
messageId: "unexpected",
|
143
137
|
data: { expectedOperator, actualOperator: node.operator },
|
144
138
|
fix(fixer) {
|
145
139
|
|
146
140
|
// If the comparison is a `typeof` comparison or both sides are literals with the same type, then it's safe to fix.
|
147
141
|
if (isTypeOfBinary(node) || areLiteralsAndSameType(node)) {
|
148
|
-
const operatorToken = sourceCode.getFirstTokenBetween(
|
149
|
-
node.left,
|
150
|
-
node.right,
|
151
|
-
token => token.value === node.operator
|
152
|
-
);
|
153
|
-
|
154
142
|
return fixer.replaceText(operatorToken, expectedOperator);
|
155
143
|
}
|
156
144
|
return null;
|
package/lib/rules/func-names.js
CHANGED
@@ -13,7 +13,7 @@ const astUtils = require("./utils/ast-utils");
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Checks whether or not a given variable is a function name.
|
16
|
-
* @param {eslint-scope.Variable} variable
|
16
|
+
* @param {eslint-scope.Variable} variable A variable to check.
|
17
17
|
* @returns {boolean} `true` if the variable is a function name.
|
18
18
|
*/
|
19
19
|
function isFunctionName(variable) {
|
@@ -73,7 +73,7 @@ module.exports = {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Returns the config option for the given node.
|
76
|
-
* @param {ASTNode} node
|
76
|
+
* @param {ASTNode} node A node to get the config for.
|
77
77
|
* @returns {string} The config option.
|
78
78
|
*/
|
79
79
|
function getConfigForNode(node) {
|
@@ -91,7 +91,7 @@ module.exports = {
|
|
91
91
|
/**
|
92
92
|
* Determines whether the current FunctionExpression node is a get, set, or
|
93
93
|
* shorthand method in an object literal or a class.
|
94
|
-
* @param {ASTNode} node
|
94
|
+
* @param {ASTNode} node A node to check.
|
95
95
|
* @returns {boolean} True if the node is a get, set, or shorthand method.
|
96
96
|
*/
|
97
97
|
function isObjectOrClassMethod(node) {
|
@@ -109,7 +109,7 @@ module.exports = {
|
|
109
109
|
/**
|
110
110
|
* Determines whether the current FunctionExpression node has a name that would be
|
111
111
|
* inferred from context in a conforming ES6 environment.
|
112
|
-
* @param {ASTNode} node
|
112
|
+
* @param {ASTNode} node A node to check.
|
113
113
|
* @returns {boolean} True if the node would have a name assigned automatically.
|
114
114
|
*/
|
115
115
|
function hasInferredName(node) {
|
@@ -125,7 +125,7 @@ module.exports = {
|
|
125
125
|
|
126
126
|
/**
|
127
127
|
* Reports that an unnamed function should be named
|
128
|
-
* @param {ASTNode} node
|
128
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
129
129
|
* @returns {void}
|
130
130
|
*/
|
131
131
|
function reportUnexpectedUnnamedFunction(node) {
|
@@ -139,7 +139,7 @@ module.exports = {
|
|
139
139
|
|
140
140
|
/**
|
141
141
|
* Reports that a named function should be unnamed
|
142
|
-
* @param {ASTNode} node
|
142
|
+
* @param {ASTNode} node The node to report in the event of an error.
|
143
143
|
* @returns {void}
|
144
144
|
*/
|
145
145
|
function reportUnexpectedNamedFunction(node) {
|
@@ -40,13 +40,13 @@ module.exports = {
|
|
40
40
|
const checkers = {
|
41
41
|
unexpected: {
|
42
42
|
messageId: "unexpectedLineBreak",
|
43
|
-
check: (prevToken, currentToken) => prevToken.loc.
|
43
|
+
check: (prevToken, currentToken) => prevToken.loc.end.line !== currentToken.loc.start.line,
|
44
44
|
createFix: (token, tokenBefore) => fixer =>
|
45
45
|
fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], " ")
|
46
46
|
},
|
47
47
|
missing: {
|
48
48
|
messageId: "missingLineBreak",
|
49
|
-
check: (prevToken, currentToken) => prevToken.loc.
|
49
|
+
check: (prevToken, currentToken) => prevToken.loc.end.line === currentToken.loc.start.line,
|
50
50
|
createFix: (token, tokenBefore) => fixer =>
|
51
51
|
fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], "\n")
|
52
52
|
}
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
61
61
|
*/
|
62
62
|
function checkArguments(node, checker) {
|
63
63
|
for (let i = 1; i < node.arguments.length; i++) {
|
64
|
-
const prevArgToken = sourceCode.
|
64
|
+
const prevArgToken = sourceCode.getLastToken(node.arguments[i - 1]);
|
65
65
|
const currentArgToken = sourceCode.getFirstToken(node.arguments[i]);
|
66
66
|
|
67
67
|
if (checker.check(prevArgToken, currentArgToken)) {
|
@@ -101,10 +101,10 @@ module.exports = {
|
|
101
101
|
} else if (option === "always") {
|
102
102
|
checkArguments(node, checkers.missing);
|
103
103
|
} else if (option === "consistent") {
|
104
|
-
const firstArgToken = sourceCode.
|
104
|
+
const firstArgToken = sourceCode.getLastToken(node.arguments[0]);
|
105
105
|
const secondArgToken = sourceCode.getFirstToken(node.arguments[1]);
|
106
106
|
|
107
|
-
if (firstArgToken.loc.
|
107
|
+
if (firstArgToken.loc.end.line === secondArgToken.loc.start.line) {
|
108
108
|
checkArguments(node, checkers.unexpected);
|
109
109
|
} else {
|
110
110
|
checkArguments(node, checkers.missing);
|
@@ -78,9 +78,8 @@ module.exports = {
|
|
78
78
|
|
79
79
|
/**
|
80
80
|
* Returns resolved option definitions based on an option and defaults
|
81
|
-
*
|
82
|
-
* @param {
|
83
|
-
* @param {Object} defaults - The defaults to use if options are not present
|
81
|
+
* @param {any} option The option object or string value
|
82
|
+
* @param {Object} defaults The defaults to use if options are not present
|
84
83
|
* @returns {Object} the resolved object definition
|
85
84
|
*/
|
86
85
|
function optionToDefinition(option, defaults) {
|
@@ -107,8 +106,7 @@ module.exports = {
|
|
107
106
|
|
108
107
|
/**
|
109
108
|
* Checks if the given token is a star token or not.
|
110
|
-
*
|
111
|
-
* @param {Token} token - The token to check.
|
109
|
+
* @param {Token} token The token to check.
|
112
110
|
* @returns {boolean} `true` if the token is a star token.
|
113
111
|
*/
|
114
112
|
function isStarToken(token) {
|
@@ -117,8 +115,7 @@ module.exports = {
|
|
117
115
|
|
118
116
|
/**
|
119
117
|
* Gets the generator star token of the given function node.
|
120
|
-
*
|
121
|
-
* @param {ASTNode} node - The function node to get.
|
118
|
+
* @param {ASTNode} node The function node to get.
|
122
119
|
* @returns {Token} Found star token.
|
123
120
|
*/
|
124
121
|
function getStarToken(node) {
|
@@ -139,7 +136,6 @@ module.exports = {
|
|
139
136
|
|
140
137
|
/**
|
141
138
|
* Checks the spacing between two tokens before or after the star token.
|
142
|
-
*
|
143
139
|
* @param {string} kind Either "named", "anonymous", or "method"
|
144
140
|
* @param {string} side Either "before" or "after".
|
145
141
|
* @param {Token} leftToken `function` keyword token if side is "before", or
|
@@ -173,7 +169,6 @@ module.exports = {
|
|
173
169
|
|
174
170
|
/**
|
175
171
|
* Enforces the spacing around the star if node is a generator function.
|
176
|
-
*
|
177
172
|
* @param {ASTNode} node A function expression or declaration node.
|
178
173
|
* @returns {void}
|
179
174
|
*/
|
@@ -18,8 +18,7 @@ const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
|
|
18
18
|
|
19
19
|
/**
|
20
20
|
* Checks a given code path segment is reachable.
|
21
|
-
*
|
22
|
-
* @param {CodePathSegment} segment - A segment to check.
|
21
|
+
* @param {CodePathSegment} segment A segment to check.
|
23
22
|
* @returns {boolean} `true` if the segment is reachable.
|
24
23
|
*/
|
25
24
|
function isReachable(segment) {
|
@@ -30,8 +29,7 @@ function isReachable(segment) {
|
|
30
29
|
* Gets a readable location.
|
31
30
|
*
|
32
31
|
* - FunctionExpression -> the function name or `function` keyword.
|
33
|
-
*
|
34
|
-
* @param {ASTNode} node - A function node to get.
|
32
|
+
* @param {ASTNode} node A function node to get.
|
35
33
|
* @returns {ASTNode|Token} The node or the token of a location.
|
36
34
|
*/
|
37
35
|
function getId(node) {
|
@@ -92,8 +90,7 @@ module.exports = {
|
|
92
90
|
*
|
93
91
|
* If the last code path segment is reachable, there are paths which are not
|
94
92
|
* returned or thrown.
|
95
|
-
*
|
96
|
-
* @param {ASTNode} node - A node to check.
|
93
|
+
* @param {ASTNode} node A node to check.
|
97
94
|
* @returns {void}
|
98
95
|
*/
|
99
96
|
function checkLastSegment(node) {
|
@@ -113,7 +110,7 @@ module.exports = {
|
|
113
110
|
|
114
111
|
/**
|
115
112
|
* Checks whether a node means a getter function.
|
116
|
-
* @param {ASTNode} node
|
113
|
+
* @param {ASTNode} node a node to check.
|
117
114
|
* @returns {boolean} if node means a getter, return true; else return false.
|
118
115
|
*/
|
119
116
|
function isGetter(node) {
|
@@ -303,7 +303,7 @@ module.exports = {
|
|
303
303
|
* @param {int} needed Expected indentation character count
|
304
304
|
* @param {int} gottenSpaces Indentation space count in the actual node/code
|
305
305
|
* @param {int} gottenTabs Indentation tab count in the actual node/code
|
306
|
-
* @param {Object
|
306
|
+
* @param {Object} [loc] Error line and column location
|
307
307
|
* @param {boolean} isLastNodeCheck Is the error for last node check
|
308
308
|
* @returns {void}
|
309
309
|
*/
|
package/lib/rules/indent.js
CHANGED
@@ -81,6 +81,9 @@ const KNOWN_NODES = new Set([
|
|
81
81
|
"WhileStatement",
|
82
82
|
"WithStatement",
|
83
83
|
"YieldExpression",
|
84
|
+
"JSXFragment",
|
85
|
+
"JSXOpeningFragment",
|
86
|
+
"JSXClosingFragment",
|
84
87
|
"JSXIdentifier",
|
85
88
|
"JSXNamespacedName",
|
86
89
|
"JSXMemberExpression",
|
@@ -184,6 +187,7 @@ class BinarySearchTree {
|
|
184
187
|
*/
|
185
188
|
class TokenInfo {
|
186
189
|
|
190
|
+
// eslint-disable-next-line jsdoc/require-description
|
187
191
|
/**
|
188
192
|
* @param {SourceCode} sourceCode A SourceCode object
|
189
193
|
*/
|
@@ -233,6 +237,7 @@ class TokenInfo {
|
|
233
237
|
*/
|
234
238
|
class OffsetStorage {
|
235
239
|
|
240
|
+
// eslint-disable-next-line jsdoc/require-description
|
236
241
|
/**
|
237
242
|
* @param {TokenInfo} tokenInfo a TokenInfo instance
|
238
243
|
* @param {number} indentSize The desired size of each indentation level
|
@@ -326,7 +331,6 @@ class OffsetStorage {
|
|
326
331
|
* Instead, the correct way would be to offset `baz` by 1 level from `bar`, offset `bar` by 1 level from the `)`, and
|
327
332
|
* offset the `)` by 0 levels from `foo`. This ensures that the offset between `bar` and the `)` are correctly collapsed
|
328
333
|
* in the second case.
|
329
|
-
*
|
330
334
|
* @param {Token} token The token
|
331
335
|
* @param {Token} fromToken The token that `token` should be offset from
|
332
336
|
* @param {number} offset The desired indent level
|
@@ -355,7 +359,6 @@ class OffsetStorage {
|
|
355
359
|
*
|
356
360
|
* The `setDesiredOffsets` methods inserts ranges like the ones above. The third line above would be inserted by using:
|
357
361
|
* `setDesiredOffsets([30, 43], fooToken, 1);`
|
358
|
-
*
|
359
362
|
* @param {[number, number]} range A [start, end] pair. All tokens with range[0] <= token.start < range[1] will have the offset applied.
|
360
363
|
* @param {Token} fromToken The token that this is offset from
|
361
364
|
* @param {number} offset The desired indent level
|
@@ -1453,6 +1456,31 @@ module.exports = {
|
|
1453
1456
|
offsets.setDesiredOffsets(node.name.range, firstToken, 1);
|
1454
1457
|
},
|
1455
1458
|
|
1459
|
+
JSXFragment(node) {
|
1460
|
+
const firstOpeningToken = sourceCode.getFirstToken(node.openingFragment);
|
1461
|
+
const firstClosingToken = sourceCode.getFirstToken(node.closingFragment);
|
1462
|
+
|
1463
|
+
addElementListIndent(node.children, firstOpeningToken, firstClosingToken, 1);
|
1464
|
+
},
|
1465
|
+
|
1466
|
+
JSXOpeningFragment(node) {
|
1467
|
+
const firstToken = sourceCode.getFirstToken(node);
|
1468
|
+
const closingToken = sourceCode.getLastToken(node);
|
1469
|
+
|
1470
|
+
offsets.setDesiredOffsets(node.range, firstToken, 1);
|
1471
|
+
offsets.matchOffsetOf(firstToken, closingToken);
|
1472
|
+
},
|
1473
|
+
|
1474
|
+
JSXClosingFragment(node) {
|
1475
|
+
const firstToken = sourceCode.getFirstToken(node);
|
1476
|
+
const slashToken = sourceCode.getLastToken(node, { skip: 1 });
|
1477
|
+
const closingToken = sourceCode.getLastToken(node);
|
1478
|
+
const tokenToMatch = astUtils.isTokenOnSameLine(slashToken, closingToken) ? slashToken : closingToken;
|
1479
|
+
|
1480
|
+
offsets.setDesiredOffsets(node.range, firstToken, 1);
|
1481
|
+
offsets.matchOffsetOf(firstToken, tokenToMatch);
|
1482
|
+
},
|
1483
|
+
|
1456
1484
|
JSXExpressionContainer(node) {
|
1457
1485
|
const openingCurly = sourceCode.getFirstToken(node);
|
1458
1486
|
const closingCurly = sourceCode.getLastToken(node);
|
@@ -1588,18 +1616,23 @@ module.exports = {
|
|
1588
1616
|
return;
|
1589
1617
|
}
|
1590
1618
|
|
1591
|
-
// If the token matches the expected expected indentation, don't report it.
|
1592
|
-
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine))) {
|
1593
|
-
return;
|
1594
|
-
}
|
1595
|
-
|
1596
1619
|
if (astUtils.isCommentToken(firstTokenOfLine)) {
|
1597
1620
|
const tokenBefore = precedingTokens.get(firstTokenOfLine);
|
1598
1621
|
const tokenAfter = tokenBefore ? sourceCode.getTokenAfter(tokenBefore) : sourceCode.ast.tokens[0];
|
1599
|
-
|
1600
1622
|
const mayAlignWithBefore = tokenBefore && !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
|
1601
1623
|
const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);
|
1602
1624
|
|
1625
|
+
/*
|
1626
|
+
* If a comment precedes a line that begins with a semicolon token, align to that token, i.e.
|
1627
|
+
*
|
1628
|
+
* let foo
|
1629
|
+
* // comment
|
1630
|
+
* ;(async () => {})()
|
1631
|
+
*/
|
1632
|
+
if (tokenAfter && astUtils.isSemicolonToken(tokenAfter) && !astUtils.isTokenOnSameLine(firstTokenOfLine, tokenAfter)) {
|
1633
|
+
offsets.setDesiredOffset(firstTokenOfLine, tokenAfter, 0);
|
1634
|
+
}
|
1635
|
+
|
1603
1636
|
// If a comment matches the expected indentation of the token immediately before or after, don't report it.
|
1604
1637
|
if (
|
1605
1638
|
mayAlignWithBefore && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenBefore)) ||
|
@@ -1609,6 +1642,11 @@ module.exports = {
|
|
1609
1642
|
}
|
1610
1643
|
}
|
1611
1644
|
|
1645
|
+
// If the token matches the expected indentation, don't report it.
|
1646
|
+
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine))) {
|
1647
|
+
return;
|
1648
|
+
}
|
1649
|
+
|
1612
1650
|
// Otherwise, report the token/comment.
|
1613
1651
|
report(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine));
|
1614
1652
|
});
|
package/lib/rules/index.js
CHANGED
@@ -37,6 +37,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
37
37
|
"constructor-super": () => require("./constructor-super"),
|
38
38
|
curly: () => require("./curly"),
|
39
39
|
"default-case": () => require("./default-case"),
|
40
|
+
"default-param-last": () => require("./default-param-last"),
|
40
41
|
"dot-location": () => require("./dot-location"),
|
41
42
|
"dot-notation": () => require("./dot-notation"),
|
42
43
|
"eol-last": () => require("./eol-last"),
|
@@ -131,6 +132,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
131
132
|
"no-implicit-coercion": () => require("./no-implicit-coercion"),
|
132
133
|
"no-implicit-globals": () => require("./no-implicit-globals"),
|
133
134
|
"no-implied-eval": () => require("./no-implied-eval"),
|
135
|
+
"no-import-assign": () => require("./no-import-assign"),
|
134
136
|
"no-inline-comments": () => require("./no-inline-comments"),
|
135
137
|
"no-inner-declarations": () => require("./no-inner-declarations"),
|
136
138
|
"no-invalid-regexp": () => require("./no-invalid-regexp"),
|
@@ -241,6 +243,7 @@ module.exports = new LazyLoadingRuleMap(Object.entries({
|
|
241
243
|
"prefer-object-spread": () => require("./prefer-object-spread"),
|
242
244
|
"prefer-promise-reject-errors": () => require("./prefer-promise-reject-errors"),
|
243
245
|
"prefer-reflect": () => require("./prefer-reflect"),
|
246
|
+
"prefer-regex-literals": () => require("./prefer-regex-literals"),
|
244
247
|
"prefer-rest-params": () => require("./prefer-rest-params"),
|
245
248
|
"prefer-spread": () => require("./prefer-spread"),
|
246
249
|
"prefer-template": () => require("./prefer-template"),
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Checks whether or not a given node is a for loop.
|
14
|
-
* @param {ASTNode} block
|
14
|
+
* @param {ASTNode} block A node to check.
|
15
15
|
* @returns {boolean} `true` when the node is a for loop.
|
16
16
|
*/
|
17
17
|
function isForLoop(block) {
|
@@ -22,7 +22,7 @@ function isForLoop(block) {
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Checks whether or not a given declarator node has its initializer.
|
25
|
-
* @param {ASTNode} node
|
25
|
+
* @param {ASTNode} node A declarator node to check.
|
26
26
|
* @returns {boolean} `true` when the node has its initializer.
|
27
27
|
*/
|
28
28
|
function isInitialized(node) {
|
package/lib/rules/jsx-quotes.js
CHANGED
@@ -65,7 +65,7 @@ module.exports = {
|
|
65
65
|
|
66
66
|
/**
|
67
67
|
* Checks if the given string literal node uses the expected quotes
|
68
|
-
* @param {ASTNode} node
|
68
|
+
* @param {ASTNode} node A string literal node.
|
69
69
|
* @returns {boolean} Whether or not the string literal used the expected quotes.
|
70
70
|
* @public
|
71
71
|
*/
|