eslint 6.5.1 → 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 +54 -0
- package/README.md +4 -3
- package/lib/cli-engine/cascading-config-array-factory.js +2 -1
- package/lib/cli-engine/cli-engine.js +9 -7
- 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 +2 -0
- 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 +1 -0
- 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 +1 -5
- package/lib/init/npm-utils.js +0 -5
- 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 +8 -12
- 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 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/rule-tester/rule-tester.js +6 -8
- package/lib/rules/accessor-pairs.js +8 -8
- 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 +0 -7
- 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 +10 -10
- 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 +1 -0
- package/lib/rules/dot-location.js +11 -12
- 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.js +2 -2
- 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/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 +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- 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-invalid-this.js +1 -3
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- 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-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- 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-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 +32 -9
- 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 +7 -7
- package/lib/rules/no-useless-return.js +8 -15
- 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 +13 -14
- package/lib/rules/object-shorthand.js +1 -1
- 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 +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- 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 +5 -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-in-parens.js +4 -4
- 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 +40 -3
- 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/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/source-code/source-code.js +8 -8
- 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 +6 -5
@@ -40,7 +40,7 @@ module.exports = {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Reports an unnecessary semicolon error.
|
43
|
-
* @param {Node|Token} nodeOrToken
|
43
|
+
* @param {Node|Token} nodeOrToken A node or a token to be reported.
|
44
44
|
* @returns {void}
|
45
45
|
*/
|
46
46
|
function report(nodeOrToken) {
|
@@ -64,8 +64,7 @@ module.exports = {
|
|
64
64
|
/**
|
65
65
|
* Checks for a part of a class body.
|
66
66
|
* This checks tokens from a specified token to a next MethodDefinition or the end of class body.
|
67
|
-
*
|
68
|
-
* @param {Token} firstToken - The first token to check.
|
67
|
+
* @param {Token} firstToken The first token to check.
|
69
68
|
* @returns {void}
|
70
69
|
*/
|
71
70
|
function checkForPartOfClassBody(firstToken) {
|
@@ -83,7 +82,7 @@ module.exports = {
|
|
83
82
|
|
84
83
|
/**
|
85
84
|
* Reports this empty statement, except if the parent node is a loop.
|
86
|
-
* @param {Node} node
|
85
|
+
* @param {Node} node A EmptyStatement node to be reported.
|
87
86
|
* @returns {void}
|
88
87
|
*/
|
89
88
|
EmptyStatement(node) {
|
@@ -106,7 +105,7 @@ module.exports = {
|
|
106
105
|
|
107
106
|
/**
|
108
107
|
* Checks tokens from the head of this class body to the first MethodDefinition or the end of this class body.
|
109
|
-
* @param {Node} node
|
108
|
+
* @param {Node} node A ClassBody node to check.
|
110
109
|
* @returns {void}
|
111
110
|
*/
|
112
111
|
ClassBody(node) {
|
@@ -115,7 +114,7 @@ module.exports = {
|
|
115
114
|
|
116
115
|
/**
|
117
116
|
* Checks tokens from this MethodDefinition to the next MethodDefinition or the end of this class body.
|
118
|
-
* @param {Node} node
|
117
|
+
* @param {Node} node A MethodDefinition node of the start point.
|
119
118
|
* @returns {void}
|
120
119
|
*/
|
121
120
|
MethodDefinition(node) {
|
@@ -18,9 +18,9 @@ const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
|
|
18
18
|
|
19
19
|
/**
|
20
20
|
* Checks whether or not a given node has a fallthrough comment.
|
21
|
-
* @param {ASTNode} node
|
22
|
-
* @param {RuleContext} context
|
23
|
-
* @param {RegExp} fallthroughCommentPattern
|
21
|
+
* @param {ASTNode} node A SwitchCase node to get comments.
|
22
|
+
* @param {RuleContext} context A rule context which stores comments.
|
23
|
+
* @param {RegExp} fallthroughCommentPattern A pattern to match comment to.
|
24
24
|
* @returns {boolean} `true` if the node has a valid fallthrough comment.
|
25
25
|
*/
|
26
26
|
function hasFallthroughComment(node, context, fallthroughCommentPattern) {
|
@@ -32,7 +32,7 @@ function hasFallthroughComment(node, context, fallthroughCommentPattern) {
|
|
32
32
|
|
33
33
|
/**
|
34
34
|
* Checks whether or not a given code path segment is reachable.
|
35
|
-
* @param {CodePathSegment} segment
|
35
|
+
* @param {CodePathSegment} segment A CodePathSegment to check.
|
36
36
|
* @returns {boolean} `true` if the segment is reachable.
|
37
37
|
*/
|
38
38
|
function isReachable(segment) {
|
@@ -41,8 +41,8 @@ function isReachable(segment) {
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* Checks whether a node and a token are separated by blank lines
|
44
|
-
* @param {ASTNode} node
|
45
|
-
* @param {Token} token
|
44
|
+
* @param {ASTNode} node The node to check
|
45
|
+
* @param {Token} token The token to compare against
|
46
46
|
* @returns {boolean} `true` if there are blank lines between node and token
|
47
47
|
*/
|
48
48
|
function hasBlankLinesBetween(node, token) {
|
@@ -29,7 +29,7 @@ module.exports = {
|
|
29
29
|
|
30
30
|
/**
|
31
31
|
* Reports a reference if is non initializer and writable.
|
32
|
-
* @param {References} references
|
32
|
+
* @param {References} references Collection of reference to check.
|
33
33
|
* @returns {void}
|
34
34
|
*/
|
35
35
|
function checkReference(references) {
|
@@ -40,7 +40,7 @@ module.exports = {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Finds and reports references that are non initializer and writable.
|
43
|
-
* @param {Variable} variable
|
43
|
+
* @param {Variable} variable A variable to check.
|
44
44
|
* @returns {void}
|
45
45
|
*/
|
46
46
|
function checkVariable(variable) {
|
@@ -51,7 +51,7 @@ module.exports = {
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
* Checks parameters of a given function node.
|
54
|
-
* @param {ASTNode} node
|
54
|
+
* @param {ASTNode} node A function node to check.
|
55
55
|
* @returns {void}
|
56
56
|
*/
|
57
57
|
function checkForFunction(node) {
|
@@ -41,9 +41,9 @@ module.exports = {
|
|
41
41
|
|
42
42
|
/**
|
43
43
|
* Reports write references.
|
44
|
-
* @param {Reference} reference
|
45
|
-
* @param {int} index
|
46
|
-
* @param {Reference[]} references
|
44
|
+
* @param {Reference} reference A reference to check.
|
45
|
+
* @param {int} index The index of the reference in the references.
|
46
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
47
47
|
* @returns {void}
|
48
48
|
*/
|
49
49
|
function checkReference(reference, index, references) {
|
@@ -68,7 +68,7 @@ module.exports = {
|
|
68
68
|
|
69
69
|
/**
|
70
70
|
* Reports write references if a given variable is read-only builtin.
|
71
|
-
* @param {Variable} variable
|
71
|
+
* @param {Variable} variable A variable to check.
|
72
72
|
* @returns {void}
|
73
73
|
*/
|
74
74
|
function checkVariable(variable) {
|
@@ -16,7 +16,7 @@ const ALLOWABLE_OPERATORS = ["~", "!!", "+", "*"];
|
|
16
16
|
|
17
17
|
/**
|
18
18
|
* Parses and normalizes an option object.
|
19
|
-
* @param {Object} options
|
19
|
+
* @param {Object} options An option object to parse.
|
20
20
|
* @returns {Object} The parsed and normalized option object.
|
21
21
|
*/
|
22
22
|
function parseOptions(options) {
|
@@ -30,7 +30,7 @@ function parseOptions(options) {
|
|
30
30
|
|
31
31
|
/**
|
32
32
|
* Checks whether or not a node is a double logical nigating.
|
33
|
-
* @param {ASTNode} node
|
33
|
+
* @param {ASTNode} node An UnaryExpression node to check.
|
34
34
|
* @returns {boolean} Whether or not the node is a double logical nigating.
|
35
35
|
*/
|
36
36
|
function isDoubleLogicalNegating(node) {
|
@@ -43,7 +43,7 @@ function isDoubleLogicalNegating(node) {
|
|
43
43
|
|
44
44
|
/**
|
45
45
|
* Checks whether or not a node is a binary negating of `.indexOf()` method calling.
|
46
|
-
* @param {ASTNode} node
|
46
|
+
* @param {ASTNode} node An UnaryExpression node to check.
|
47
47
|
* @returns {boolean} Whether or not the node is a binary negating of `.indexOf()` method calling.
|
48
48
|
*/
|
49
49
|
function isBinaryNegatingOfIndexOf(node) {
|
@@ -58,7 +58,7 @@ function isBinaryNegatingOfIndexOf(node) {
|
|
58
58
|
|
59
59
|
/**
|
60
60
|
* Checks whether or not a node is a multiplying by one.
|
61
|
-
* @param {BinaryExpression} node
|
61
|
+
* @param {BinaryExpression} node A BinaryExpression node to check.
|
62
62
|
* @returns {boolean} Whether or not the node is a multiplying by one.
|
63
63
|
*/
|
64
64
|
function isMultiplyByOne(node) {
|
@@ -118,7 +118,7 @@ function isEmptyString(node) {
|
|
118
118
|
|
119
119
|
/**
|
120
120
|
* Checks whether or not a node is a concatenating with an empty string.
|
121
|
-
* @param {ASTNode} node
|
121
|
+
* @param {ASTNode} node A BinaryExpression node to check.
|
122
122
|
* @returns {boolean} Whether or not the node is a concatenating with an empty string.
|
123
123
|
*/
|
124
124
|
function isConcatWithEmptyString(node) {
|
@@ -130,7 +130,7 @@ function isConcatWithEmptyString(node) {
|
|
130
130
|
|
131
131
|
/**
|
132
132
|
* Checks whether or not a node is appended with an empty string.
|
133
|
-
* @param {ASTNode} node
|
133
|
+
* @param {ASTNode} node An AssignmentExpression node to check.
|
134
134
|
* @returns {boolean} Whether or not the node is appended with an empty string.
|
135
135
|
*/
|
136
136
|
function isAppendEmptyString(node) {
|
@@ -139,7 +139,7 @@ function isAppendEmptyString(node) {
|
|
139
139
|
|
140
140
|
/**
|
141
141
|
* Returns the operand that is not an empty string from a flagged BinaryExpression.
|
142
|
-
* @param {ASTNode} node
|
142
|
+
* @param {ASTNode} node The flagged BinaryExpression node to check.
|
143
143
|
* @returns {ASTNode} The operand that is not an empty string from a flagged BinaryExpression.
|
144
144
|
*/
|
145
145
|
function getNonEmptyOperand(node) {
|
@@ -196,9 +196,9 @@ module.exports = {
|
|
196
196
|
|
197
197
|
/**
|
198
198
|
* Reports an error and autofixes the node
|
199
|
-
* @param {ASTNode} node
|
200
|
-
* @param {string} recommendation
|
201
|
-
* @param {bool} shouldFix
|
199
|
+
* @param {ASTNode} node An ast node to report the error on.
|
200
|
+
* @param {string} recommendation The recommended code for the issue
|
201
|
+
* @param {bool} shouldFix Whether this report should fix the node
|
202
202
|
* @returns {void}
|
203
203
|
*/
|
204
204
|
function report(node, recommendation, shouldFix) {
|
@@ -64,7 +64,6 @@ module.exports = {
|
|
64
64
|
* Determines if a node represents a call to a potentially implied eval.
|
65
65
|
*
|
66
66
|
* This checks the callee name and that there's an argument, but not the type of the argument.
|
67
|
-
*
|
68
67
|
* @param {ASTNode} node The CallExpression to check.
|
69
68
|
* @returns {boolean} True if the node matches, false if not.
|
70
69
|
* @private
|
@@ -38,7 +38,6 @@ module.exports = {
|
|
38
38
|
*
|
39
39
|
* The return value has a flag that whether or not `this` keyword is valid.
|
40
40
|
* The flag is initialized when got at the first time.
|
41
|
-
*
|
42
41
|
* @returns {{valid: boolean}}
|
43
42
|
* an object which has a flag that whether or not `this` keyword is valid.
|
44
43
|
*/
|
@@ -61,8 +60,7 @@ module.exports = {
|
|
61
60
|
* The checking context is not initialized yet.
|
62
61
|
* Because most functions don't have `this` keyword.
|
63
62
|
* When `this` keyword was found, the checking context is initialized.
|
64
|
-
*
|
65
|
-
* @param {ASTNode} node - A function node that was entered.
|
63
|
+
* @param {ASTNode} node A function node that was entered.
|
66
64
|
* @returns {void}
|
67
65
|
*/
|
68
66
|
function enterFunction(node) {
|
package/lib/rules/no-labels.js
CHANGED
@@ -51,8 +51,7 @@ module.exports = {
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
* Gets the kind of a given node.
|
54
|
-
*
|
55
|
-
* @param {ASTNode} node - A node to get.
|
54
|
+
* @param {ASTNode} node A node to get.
|
56
55
|
* @returns {string} The kind of the node.
|
57
56
|
*/
|
58
57
|
function getBodyKind(node) {
|
@@ -67,8 +66,7 @@ module.exports = {
|
|
67
66
|
|
68
67
|
/**
|
69
68
|
* Checks whether the label of a given kind is allowed or not.
|
70
|
-
*
|
71
|
-
* @param {string} kind - A kind to check.
|
69
|
+
* @param {string} kind A kind to check.
|
72
70
|
* @returns {boolean} `true` if the kind is allowed.
|
73
71
|
*/
|
74
72
|
function isAllowed(kind) {
|
@@ -81,8 +79,7 @@ module.exports = {
|
|
81
79
|
|
82
80
|
/**
|
83
81
|
* Checks whether a given name is a label of a loop or not.
|
84
|
-
*
|
85
|
-
* @param {string} label - A name of a label to check.
|
82
|
+
* @param {string} label A name of a label to check.
|
86
83
|
* @returns {boolean} `true` if the name is a label of a loop.
|
87
84
|
*/
|
88
85
|
function getKind(label) {
|
@@ -14,8 +14,7 @@
|
|
14
14
|
*
|
15
15
|
* We don't need to check nested functions, so this ignores those.
|
16
16
|
* `Scope.through` contains references of nested functions.
|
17
|
-
*
|
18
|
-
* @param {ASTNode} node - An AST node to get.
|
17
|
+
* @param {ASTNode} node An AST node to get.
|
19
18
|
* @returns {ASTNode|null} The containing loop node of the specified node, or
|
20
19
|
* `null`.
|
21
20
|
*/
|
@@ -63,9 +62,8 @@ function getContainingLoopNode(node) {
|
|
63
62
|
/**
|
64
63
|
* Gets the containing loop node of a given node.
|
65
64
|
* If the loop was nested, this returns the most outer loop.
|
66
|
-
*
|
67
|
-
* @param {ASTNode}
|
68
|
-
* @param {ASTNode|null} excludedNode - A node that the result node should not
|
65
|
+
* @param {ASTNode} node A node to get. This is a loop node.
|
66
|
+
* @param {ASTNode|null} excludedNode A node that the result node should not
|
69
67
|
* include.
|
70
68
|
* @returns {ASTNode} The most outer loop node.
|
71
69
|
*/
|
@@ -85,9 +83,8 @@ function getTopLoopNode(node, excludedNode) {
|
|
85
83
|
/**
|
86
84
|
* Checks whether a given reference which refers to an upper scope's variable is
|
87
85
|
* safe or not.
|
88
|
-
*
|
89
|
-
* @param {
|
90
|
-
* @param {eslint-scope.Reference} reference - A reference to check.
|
86
|
+
* @param {ASTNode} loopNode A containing loop node.
|
87
|
+
* @param {eslint-scope.Reference} reference A reference to check.
|
91
88
|
* @returns {boolean} `true` if the reference is safe or not.
|
92
89
|
*/
|
93
90
|
function isSafe(loopNode, reference) {
|
@@ -131,8 +128,7 @@ function isSafe(loopNode, reference) {
|
|
131
128
|
* It's safeafe if the reference matches one of the following condition.
|
132
129
|
* - is readonly.
|
133
130
|
* - doesn't exist inside a local function and after the border.
|
134
|
-
*
|
135
|
-
* @param {eslint-scope.Reference} upperRef - A reference to check.
|
131
|
+
* @param {eslint-scope.Reference} upperRef A reference to check.
|
136
132
|
* @returns {boolean} `true` if the reference is safe.
|
137
133
|
*/
|
138
134
|
function isSafeReference(upperRef) {
|
@@ -177,7 +173,6 @@ module.exports = {
|
|
177
173
|
*
|
178
174
|
* - has a loop node in ancestors.
|
179
175
|
* - has any references which refers to an unsafe variable.
|
180
|
-
*
|
181
176
|
* @param {ASTNode} node The AST node to check.
|
182
177
|
* @returns {boolean} Whether or not the node is within a loop.
|
183
178
|
*/
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Returns whether the node is number literal
|
64
|
-
* @param {Node} node
|
64
|
+
* @param {Node} node the node literal being evaluated
|
65
65
|
* @returns {boolean} true if the node is a number literal
|
66
66
|
*/
|
67
67
|
function isNumber(node) {
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
70
70
|
|
71
71
|
/**
|
72
72
|
* Returns whether the number should be ignored
|
73
|
-
* @param {number} num
|
73
|
+
* @param {number} num the number
|
74
74
|
* @returns {boolean} true if the number should be ignored
|
75
75
|
*/
|
76
76
|
function shouldIgnoreNumber(num) {
|
@@ -79,8 +79,8 @@ module.exports = {
|
|
79
79
|
|
80
80
|
/**
|
81
81
|
* Returns whether the number should be ignored when used as a radix within parseInt() or Number.parseInt()
|
82
|
-
* @param {ASTNode} parent
|
83
|
-
* @param {ASTNode} node
|
82
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent
|
83
|
+
* @param {ASTNode} node the node literal being evaluated
|
84
84
|
* @returns {boolean} true if the number should be ignored
|
85
85
|
*/
|
86
86
|
function shouldIgnoreParseInt(parent, node) {
|
@@ -93,7 +93,7 @@ module.exports = {
|
|
93
93
|
|
94
94
|
/**
|
95
95
|
* Returns whether the number should be ignored when used to define a JSX prop
|
96
|
-
* @param {ASTNode} parent
|
96
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent
|
97
97
|
* @returns {boolean} true if the number should be ignored
|
98
98
|
*/
|
99
99
|
function shouldIgnoreJSXNumbers(parent) {
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
102
102
|
|
103
103
|
/**
|
104
104
|
* Returns whether the number should be ignored when used as an array index with enabled 'ignoreArrayIndexes' option.
|
105
|
-
* @param {ASTNode} parent
|
105
|
+
* @param {ASTNode} parent the non-"UnaryExpression" parent.
|
106
106
|
* @returns {boolean} true if the number should be ignored
|
107
107
|
*/
|
108
108
|
function shouldIgnoreArrayIndexes(parent) {
|
@@ -16,7 +16,6 @@ const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurr
|
|
16
16
|
*
|
17
17
|
* CharacterClassRange syntax can steal a part of character sequence,
|
18
18
|
* so this function reverts CharacterClassRange syntax and restore the sequence.
|
19
|
-
*
|
20
19
|
* @param {regexpp.AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
|
21
20
|
* @returns {IterableIterator<number[]>} The list of character sequences.
|
22
21
|
*/
|
@@ -131,12 +130,6 @@ module.exports = {
|
|
131
130
|
* @returns {void}
|
132
131
|
*/
|
133
132
|
function verify(node, pattern, flags) {
|
134
|
-
const patternNode = parser.parsePattern(
|
135
|
-
pattern,
|
136
|
-
0,
|
137
|
-
pattern.length,
|
138
|
-
flags.includes("u")
|
139
|
-
);
|
140
133
|
const has = {
|
141
134
|
surrogatePairWithoutUFlag: false,
|
142
135
|
combiningClass: false,
|
@@ -145,6 +138,20 @@ module.exports = {
|
|
145
138
|
regionalIndicatorSymbol: false,
|
146
139
|
zwj: false
|
147
140
|
};
|
141
|
+
let patternNode;
|
142
|
+
|
143
|
+
try {
|
144
|
+
patternNode = parser.parsePattern(
|
145
|
+
pattern,
|
146
|
+
0,
|
147
|
+
pattern.length,
|
148
|
+
flags.includes("u")
|
149
|
+
);
|
150
|
+
} catch (e) {
|
151
|
+
|
152
|
+
// Ignore regular expressions with syntax errors
|
153
|
+
return;
|
154
|
+
}
|
148
155
|
|
149
156
|
visitRegExpAST(patternNode, {
|
150
157
|
onCharacterClassEnter(ccNode) {
|
@@ -40,8 +40,7 @@ const TARGET_NODE_TYPE = /^(?:Binary|Logical|Conditional)Expression$/u;
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* Normalizes options.
|
43
|
-
*
|
44
|
-
* @param {Object|undefined} options - A options object to normalize.
|
43
|
+
* @param {Object|undefined} options A options object to normalize.
|
45
44
|
* @returns {Object} Normalized option object.
|
46
45
|
*/
|
47
46
|
function normalizeOptions(options = {}) {
|
@@ -57,10 +56,9 @@ function normalizeOptions(options = {}) {
|
|
57
56
|
|
58
57
|
/**
|
59
58
|
* Checks whether any group which includes both given operator exists or not.
|
60
|
-
*
|
61
|
-
* @param {
|
62
|
-
* @param {string}
|
63
|
-
* @param {string} right - Another operator.
|
59
|
+
* @param {Array.<string[]>} groups A list of groups to check.
|
60
|
+
* @param {string} left An operator.
|
61
|
+
* @param {string} right Another operator.
|
64
62
|
* @returns {boolean} `true` if such group existed.
|
65
63
|
*/
|
66
64
|
function includesBothInAGroup(groups, left, right) {
|
@@ -69,8 +67,7 @@ function includesBothInAGroup(groups, left, right) {
|
|
69
67
|
|
70
68
|
/**
|
71
69
|
* Checks whether the given node is a conditional expression and returns the test node else the left node.
|
72
|
-
*
|
73
|
-
* @param {ASTNode} node - A node which can be a BinaryExpression or a LogicalExpression node.
|
70
|
+
* @param {ASTNode} node A node which can be a BinaryExpression or a LogicalExpression node.
|
74
71
|
* This parent node can be BinaryExpression, LogicalExpression
|
75
72
|
* , or a ConditionalExpression node
|
76
73
|
* @returns {ASTNode} node the appropriate node(left or test).
|
@@ -124,8 +121,7 @@ module.exports = {
|
|
124
121
|
|
125
122
|
/**
|
126
123
|
* Checks whether a given node should be ignored by options or not.
|
127
|
-
*
|
128
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
124
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
129
125
|
* node or a LogicalExpression node. This parent node is one of
|
130
126
|
* them, too.
|
131
127
|
* @returns {boolean} `true` if the node should be ignored.
|
@@ -146,8 +142,7 @@ module.exports = {
|
|
146
142
|
/**
|
147
143
|
* Checks whether the operator of a given node is mixed with parent
|
148
144
|
* node's operator or not.
|
149
|
-
*
|
150
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
145
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
151
146
|
* node or a LogicalExpression node. This parent node is one of
|
152
147
|
* them, too.
|
153
148
|
* @returns {boolean} `true` if the node was mixed.
|
@@ -163,8 +158,7 @@ module.exports = {
|
|
163
158
|
/**
|
164
159
|
* Checks whether the operator of a given node is mixed with a
|
165
160
|
* conditional expression.
|
166
|
-
*
|
167
|
-
* @param {ASTNode} node - A node to check. This is a conditional
|
161
|
+
* @param {ASTNode} node A node to check. This is a conditional
|
168
162
|
* expression node
|
169
163
|
* @returns {boolean} `true` if the node was mixed.
|
170
164
|
*/
|
@@ -174,8 +168,7 @@ module.exports = {
|
|
174
168
|
|
175
169
|
/**
|
176
170
|
* Gets the operator token of a given node.
|
177
|
-
*
|
178
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
171
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
179
172
|
* node or a LogicalExpression node.
|
180
173
|
* @returns {Token} The operator token of the node.
|
181
174
|
*/
|
@@ -186,8 +179,7 @@ module.exports = {
|
|
186
179
|
/**
|
187
180
|
* Reports both the operator of a given node and the operator of the
|
188
181
|
* parent node.
|
189
|
-
*
|
190
|
-
* @param {ASTNode} node - A node to check. This is a BinaryExpression
|
182
|
+
* @param {ASTNode} node A node to check. This is a BinaryExpression
|
191
183
|
* node or a LogicalExpression node. This parent node is one of
|
192
184
|
* them, too.
|
193
185
|
* @returns {void}
|
@@ -205,13 +197,13 @@ module.exports = {
|
|
205
197
|
|
206
198
|
context.report({
|
207
199
|
node: left,
|
208
|
-
loc: getOperatorToken(left).loc
|
200
|
+
loc: getOperatorToken(left).loc,
|
209
201
|
message,
|
210
202
|
data
|
211
203
|
});
|
212
204
|
context.report({
|
213
205
|
node: right,
|
214
|
-
loc: getOperatorToken(right).loc
|
206
|
+
loc: getOperatorToken(right).loc,
|
215
207
|
message,
|
216
208
|
data
|
217
209
|
});
|
@@ -220,8 +212,7 @@ module.exports = {
|
|
220
212
|
/**
|
221
213
|
* Checks between the operator of this node and the operator of the
|
222
214
|
* parent node.
|
223
|
-
*
|
224
|
-
* @param {ASTNode} node - A node to check.
|
215
|
+
* @param {ASTNode} node A node to check.
|
225
216
|
* @returns {void}
|
226
217
|
*/
|
227
218
|
function check(node) {
|
@@ -121,7 +121,7 @@ module.exports = {
|
|
121
121
|
|
122
122
|
context.report({
|
123
123
|
node: rightToken,
|
124
|
-
loc: rightToken.loc.start,
|
124
|
+
loc: { start: leftToken.loc.end, end: rightToken.loc.start },
|
125
125
|
message: "Multiple spaces found before '{{displayValue}}'.",
|
126
126
|
data: { displayValue },
|
127
127
|
fix: fixer => fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ")
|
@@ -46,9 +46,9 @@ module.exports = {
|
|
46
46
|
|
47
47
|
/**
|
48
48
|
* Reports write references.
|
49
|
-
* @param {Reference} reference
|
50
|
-
* @param {int} index
|
51
|
-
* @param {Reference[]} references
|
49
|
+
* @param {Reference} reference A reference to check.
|
50
|
+
* @param {int} index The index of the reference in the references.
|
51
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
52
52
|
* @returns {void}
|
53
53
|
*/
|
54
54
|
function checkReference(reference, index, references) {
|
@@ -73,7 +73,7 @@ module.exports = {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Reports write references if a given variable is read-only builtin.
|
76
|
-
* @param {Variable} variable
|
76
|
+
* @param {Variable} variable A variable to check.
|
77
77
|
* @returns {void}
|
78
78
|
*/
|
79
79
|
function checkVariable(variable) {
|
@@ -45,6 +45,13 @@ module.exports = {
|
|
45
45
|
type: "string"
|
46
46
|
},
|
47
47
|
uniqueItems: true
|
48
|
+
},
|
49
|
+
ignorePropertyModificationsForRegex: {
|
50
|
+
type: "array",
|
51
|
+
items: {
|
52
|
+
type: "string"
|
53
|
+
},
|
54
|
+
uniqueItems: true
|
48
55
|
}
|
49
56
|
},
|
50
57
|
additionalProperties: false
|
@@ -57,10 +64,11 @@ module.exports = {
|
|
57
64
|
create(context) {
|
58
65
|
const props = context.options[0] && context.options[0].props;
|
59
66
|
const ignoredPropertyAssignmentsFor = context.options[0] && context.options[0].ignorePropertyModificationsFor || [];
|
67
|
+
const ignoredPropertyAssignmentsForRegex = context.options[0] && context.options[0].ignorePropertyModificationsForRegex || [];
|
60
68
|
|
61
69
|
/**
|
62
70
|
* Checks whether or not the reference modifies properties of its variable.
|
63
|
-
* @param {Reference} reference
|
71
|
+
* @param {Reference} reference A reference to check.
|
64
72
|
* @returns {boolean} Whether or not the reference modifies properties of its variable.
|
65
73
|
*/
|
66
74
|
function isModifyingProp(reference) {
|
@@ -136,11 +144,24 @@ module.exports = {
|
|
136
144
|
return false;
|
137
145
|
}
|
138
146
|
|
147
|
+
/**
|
148
|
+
* Tests that an identifier name matches any of the ignored property assignments.
|
149
|
+
* First we test strings in ignoredPropertyAssignmentsFor.
|
150
|
+
* Then we instantiate and test RegExp objects from ignoredPropertyAssignmentsForRegex strings.
|
151
|
+
* @param {string} identifierName A string that describes the name of an identifier to
|
152
|
+
* ignore property assignments for.
|
153
|
+
* @returns {boolean} Whether the string matches an ignored property assignment regular expression or not.
|
154
|
+
*/
|
155
|
+
function isIgnoredPropertyAssignment(identifierName) {
|
156
|
+
return ignoredPropertyAssignmentsFor.includes(identifierName) ||
|
157
|
+
ignoredPropertyAssignmentsForRegex.some(ignored => new RegExp(ignored, "u").test(identifierName));
|
158
|
+
}
|
159
|
+
|
139
160
|
/**
|
140
161
|
* Reports a reference if is non initializer and writable.
|
141
|
-
* @param {Reference} reference
|
142
|
-
* @param {int} index
|
143
|
-
* @param {Reference[]} references
|
162
|
+
* @param {Reference} reference A reference to check.
|
163
|
+
* @param {int} index The index of the reference in the references.
|
164
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
144
165
|
* @returns {void}
|
145
166
|
*/
|
146
167
|
function checkReference(reference, index, references) {
|
@@ -157,7 +178,7 @@ module.exports = {
|
|
157
178
|
) {
|
158
179
|
if (reference.isWrite()) {
|
159
180
|
context.report({ node: identifier, message: "Assignment to function parameter '{{name}}'.", data: { name: identifier.name } });
|
160
|
-
} else if (props && isModifyingProp(reference) &&
|
181
|
+
} else if (props && isModifyingProp(reference) && !isIgnoredPropertyAssignment(identifier.name)) {
|
161
182
|
context.report({ node: identifier, message: "Assignment to property of function parameter '{{name}}'.", data: { name: identifier.name } });
|
162
183
|
}
|
163
184
|
}
|
@@ -165,7 +186,7 @@ module.exports = {
|
|
165
186
|
|
166
187
|
/**
|
167
188
|
* Finds and reports references that are non initializer and writable.
|
168
|
-
* @param {Variable} variable
|
189
|
+
* @param {Variable} variable A variable to check.
|
169
190
|
* @returns {void}
|
170
191
|
*/
|
171
192
|
function checkVariable(variable) {
|
@@ -176,7 +197,7 @@ module.exports = {
|
|
176
197
|
|
177
198
|
/**
|
178
199
|
* Checks parameters of a given function node.
|
179
|
-
* @param {ASTNode} node
|
200
|
+
* @param {ASTNode} node A function node to check.
|
180
201
|
* @returns {void}
|
181
202
|
*/
|
182
203
|
function checkForFunction(node) {
|
@@ -52,7 +52,6 @@ module.exports = {
|
|
52
52
|
|
53
53
|
/**
|
54
54
|
* Validate regular expression
|
55
|
-
*
|
56
55
|
* @param {ASTNode} nodeToReport Node to report.
|
57
56
|
* @param {string} pattern Regular expression pattern to validate.
|
58
57
|
* @param {string} rawPattern Raw representation of the pattern in the source code.
|