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
package/lib/rules/strict.js
CHANGED
@@ -43,8 +43,7 @@ function getUseStrictDirectives(statements) {
|
|
43
43
|
|
44
44
|
/**
|
45
45
|
* Checks whether a given parameter is a simple parameter.
|
46
|
-
*
|
47
|
-
* @param {ASTNode} node - A pattern node to check.
|
46
|
+
* @param {ASTNode} node A pattern node to check.
|
48
47
|
* @returns {boolean} `true` if the node is an Identifier node.
|
49
48
|
*/
|
50
49
|
function isSimpleParameter(node) {
|
@@ -53,8 +52,7 @@ function isSimpleParameter(node) {
|
|
53
52
|
|
54
53
|
/**
|
55
54
|
* Checks whether a given parameter list is a simple parameter list.
|
56
|
-
*
|
57
|
-
* @param {ASTNode[]} params - A parameter list to check.
|
55
|
+
* @param {ASTNode[]} params A parameter list to check.
|
58
56
|
* @returns {boolean} `true` if the every parameter is an Identifier node.
|
59
57
|
*/
|
60
58
|
function isSimpleParameterList(params) {
|
@@ -38,8 +38,7 @@ module.exports = {
|
|
38
38
|
/**
|
39
39
|
* Reports if node does not conform the rule in case rule is set to
|
40
40
|
* report missing description
|
41
|
-
*
|
42
|
-
* @param {ASTNode} node - A CallExpression node to check.
|
41
|
+
* @param {ASTNode} node A CallExpression node to check.
|
43
42
|
* @returns {void}
|
44
43
|
*/
|
45
44
|
function checkArgument(node) {
|
@@ -53,7 +53,7 @@ module.exports = {
|
|
53
53
|
|
54
54
|
/**
|
55
55
|
* Checks spacing before `}` of a given token.
|
56
|
-
* @param {Token} token
|
56
|
+
* @param {Token} token A token to check. This is a Template token.
|
57
57
|
* @returns {void}
|
58
58
|
*/
|
59
59
|
function checkSpacingBefore(token) {
|
@@ -82,7 +82,7 @@ module.exports = {
|
|
82
82
|
|
83
83
|
/**
|
84
84
|
* Checks spacing after `${` of a given token.
|
85
|
-
* @param {Token} token
|
85
|
+
* @param {Token} token A token to check. This is a Template token.
|
86
86
|
* @returns {void}
|
87
87
|
*/
|
88
88
|
function checkSpacingAfter(token) {
|
package/lib/rules/use-isnan.js
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Helpers
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -40,6 +46,10 @@ module.exports = {
|
|
40
46
|
enforceForSwitchCase: {
|
41
47
|
type: "boolean",
|
42
48
|
default: false
|
49
|
+
},
|
50
|
+
enforceForIndexOf: {
|
51
|
+
type: "boolean",
|
52
|
+
default: false
|
43
53
|
}
|
44
54
|
},
|
45
55
|
additionalProperties: false
|
@@ -49,16 +59,18 @@ module.exports = {
|
|
49
59
|
messages: {
|
50
60
|
comparisonWithNaN: "Use the isNaN function to compare with NaN.",
|
51
61
|
switchNaN: "'switch(NaN)' can never match a case clause. Use Number.isNaN instead of the switch.",
|
52
|
-
caseNaN: "'case NaN' can never match. Use Number.isNaN before the switch."
|
62
|
+
caseNaN: "'case NaN' can never match. Use Number.isNaN before the switch.",
|
63
|
+
indexOfNaN: "Array prototype method '{{ methodName }}' cannot find NaN."
|
53
64
|
}
|
54
65
|
},
|
55
66
|
|
56
67
|
create(context) {
|
57
68
|
|
58
69
|
const enforceForSwitchCase = context.options[0] && context.options[0].enforceForSwitchCase;
|
70
|
+
const enforceForIndexOf = context.options[0] && context.options[0].enforceForIndexOf;
|
59
71
|
|
60
72
|
/**
|
61
|
-
* Checks the given `BinaryExpression` node.
|
73
|
+
* Checks the given `BinaryExpression` node for `foo === NaN` and other comparisons.
|
62
74
|
* @param {ASTNode} node The node to check.
|
63
75
|
* @returns {void}
|
64
76
|
*/
|
@@ -72,7 +84,7 @@ module.exports = {
|
|
72
84
|
}
|
73
85
|
|
74
86
|
/**
|
75
|
-
* Checks the discriminant and all case clauses of the given `SwitchStatement` node
|
87
|
+
* Checks the discriminant and all case clauses of the given `SwitchStatement` node for `switch(NaN)` and `case NaN:`
|
76
88
|
* @param {ASTNode} node The node to check.
|
77
89
|
* @returns {void}
|
78
90
|
*/
|
@@ -88,6 +100,27 @@ module.exports = {
|
|
88
100
|
}
|
89
101
|
}
|
90
102
|
|
103
|
+
/**
|
104
|
+
* Checks the the given `CallExpression` node for `.indexOf(NaN)` and `.lastIndexOf(NaN)`.
|
105
|
+
* @param {ASTNode} node The node to check.
|
106
|
+
* @returns {void}
|
107
|
+
*/
|
108
|
+
function checkCallExpression(node) {
|
109
|
+
const callee = node.callee;
|
110
|
+
|
111
|
+
if (callee.type === "MemberExpression") {
|
112
|
+
const methodName = astUtils.getStaticPropertyName(callee);
|
113
|
+
|
114
|
+
if (
|
115
|
+
(methodName === "indexOf" || methodName === "lastIndexOf") &&
|
116
|
+
node.arguments.length === 1 &&
|
117
|
+
isNaNIdentifier(node.arguments[0])
|
118
|
+
) {
|
119
|
+
context.report({ node, messageId: "indexOfNaN", data: { methodName } });
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
91
124
|
const listeners = {
|
92
125
|
BinaryExpression: checkBinaryExpression
|
93
126
|
};
|
@@ -96,6 +129,10 @@ module.exports = {
|
|
96
129
|
listeners.SwitchStatement = checkSwitchStatement;
|
97
130
|
}
|
98
131
|
|
132
|
+
if (enforceForIndexOf) {
|
133
|
+
listeners.CallExpression = checkCallExpression;
|
134
|
+
}
|
135
|
+
|
99
136
|
return listeners;
|
100
137
|
}
|
101
138
|
};
|
@@ -42,9 +42,9 @@ const OCTAL_ESCAPE_PATTERN = /^(?:[^\\]|\\[^0-7]|\\0(?![0-9]))*\\(?:[1-7]|0[0-9]
|
|
42
42
|
|
43
43
|
/**
|
44
44
|
* Checks reference if is non initializer and writable.
|
45
|
-
* @param {Reference} reference
|
46
|
-
* @param {int} index
|
47
|
-
* @param {Reference[]} references
|
45
|
+
* @param {Reference} reference A reference to check.
|
46
|
+
* @param {int} index The index of the reference in the references.
|
47
|
+
* @param {Reference[]} references The array that the reference belongs to.
|
48
48
|
* @returns {boolean} Success/Failure
|
49
49
|
* @private
|
50
50
|
*/
|
@@ -68,8 +68,7 @@ function isModifyingReference(reference, index, references) {
|
|
68
68
|
|
69
69
|
/**
|
70
70
|
* Checks whether the given string starts with uppercase or not.
|
71
|
-
*
|
72
|
-
* @param {string} s - The string to check.
|
71
|
+
* @param {string} s The string to check.
|
73
72
|
* @returns {boolean} `true` if the string starts with uppercase.
|
74
73
|
*/
|
75
74
|
function startsWithUpperCase(s) {
|
@@ -78,7 +77,7 @@ function startsWithUpperCase(s) {
|
|
78
77
|
|
79
78
|
/**
|
80
79
|
* Checks whether or not a node is a constructor.
|
81
|
-
* @param {ASTNode} node
|
80
|
+
* @param {ASTNode} node A function node to check.
|
82
81
|
* @returns {boolean} Wehether or not a node is a constructor.
|
83
82
|
*/
|
84
83
|
function isES5Constructor(node) {
|
@@ -87,7 +86,7 @@ function isES5Constructor(node) {
|
|
87
86
|
|
88
87
|
/**
|
89
88
|
* Finds a function node from ancestors of a node.
|
90
|
-
* @param {ASTNode} node
|
89
|
+
* @param {ASTNode} node A start node to find.
|
91
90
|
* @returns {Node|null} A found function node.
|
92
91
|
*/
|
93
92
|
function getUpperFunction(node) {
|
@@ -106,8 +105,7 @@ function getUpperFunction(node) {
|
|
106
105
|
* - ArrowFunctionExpression
|
107
106
|
* - FunctionDeclaration
|
108
107
|
* - FunctionExpression
|
109
|
-
*
|
110
|
-
* @param {ASTNode|null} node - A node to check.
|
108
|
+
* @param {ASTNode|null} node A node to check.
|
111
109
|
* @returns {boolean} `true` if the node is a function node.
|
112
110
|
*/
|
113
111
|
function isFunction(node) {
|
@@ -123,8 +121,7 @@ function isFunction(node) {
|
|
123
121
|
* - ForOfStatement
|
124
122
|
* - ForStatement
|
125
123
|
* - WhileStatement
|
126
|
-
*
|
127
|
-
* @param {ASTNode|null} node - A node to check.
|
124
|
+
* @param {ASTNode|null} node A node to check.
|
128
125
|
* @returns {boolean} `true` if the node is a loop node.
|
129
126
|
*/
|
130
127
|
function isLoop(node) {
|
@@ -133,8 +130,7 @@ function isLoop(node) {
|
|
133
130
|
|
134
131
|
/**
|
135
132
|
* Checks whether the given node is in a loop or not.
|
136
|
-
*
|
137
|
-
* @param {ASTNode} node - The node to check.
|
133
|
+
* @param {ASTNode} node The node to check.
|
138
134
|
* @returns {boolean} `true` if the node is in a loop.
|
139
135
|
*/
|
140
136
|
function isInLoop(node) {
|
@@ -149,7 +145,7 @@ function isInLoop(node) {
|
|
149
145
|
|
150
146
|
/**
|
151
147
|
* Checks whether or not a node is `null` or `undefined`.
|
152
|
-
* @param {ASTNode} node
|
148
|
+
* @param {ASTNode} node A node to check.
|
153
149
|
* @returns {boolean} Whether or not the node is a `null` or `undefined`.
|
154
150
|
* @public
|
155
151
|
*/
|
@@ -163,7 +159,7 @@ function isNullOrUndefined(node) {
|
|
163
159
|
|
164
160
|
/**
|
165
161
|
* Checks whether or not a node is callee.
|
166
|
-
* @param {ASTNode} node
|
162
|
+
* @param {ASTNode} node A node to check.
|
167
163
|
* @returns {boolean} Whether or not the node is callee.
|
168
164
|
*/
|
169
165
|
function isCallee(node) {
|
@@ -172,7 +168,7 @@ function isCallee(node) {
|
|
172
168
|
|
173
169
|
/**
|
174
170
|
* Checks whether or not a node is `Reflect.apply`.
|
175
|
-
* @param {ASTNode} node
|
171
|
+
* @param {ASTNode} node A node to check.
|
176
172
|
* @returns {boolean} Whether or not the node is a `Reflect.apply`.
|
177
173
|
*/
|
178
174
|
function isReflectApply(node) {
|
@@ -188,7 +184,7 @@ function isReflectApply(node) {
|
|
188
184
|
|
189
185
|
/**
|
190
186
|
* Checks whether or not a node is `Array.from`.
|
191
|
-
* @param {ASTNode} node
|
187
|
+
* @param {ASTNode} node A node to check.
|
192
188
|
* @returns {boolean} Whether or not the node is a `Array.from`.
|
193
189
|
*/
|
194
190
|
function isArrayFromMethod(node) {
|
@@ -204,7 +200,7 @@ function isArrayFromMethod(node) {
|
|
204
200
|
|
205
201
|
/**
|
206
202
|
* Checks whether or not a node is a method which has `thisArg`.
|
207
|
-
* @param {ASTNode} node
|
203
|
+
* @param {ASTNode} node A node to check.
|
208
204
|
* @returns {boolean} Whether or not the node is a method which has `thisArg`.
|
209
205
|
*/
|
210
206
|
function isMethodWhichHasThisArg(node) {
|
@@ -223,7 +219,7 @@ function isMethodWhichHasThisArg(node) {
|
|
223
219
|
|
224
220
|
/**
|
225
221
|
* Creates the negate function of the given function.
|
226
|
-
* @param {Function} f
|
222
|
+
* @param {Function} f The function to negate.
|
227
223
|
* @returns {Function} Negated function.
|
228
224
|
*/
|
229
225
|
function negate(f) {
|
@@ -232,8 +228,8 @@ function negate(f) {
|
|
232
228
|
|
233
229
|
/**
|
234
230
|
* Checks whether or not a node has a `@this` tag in its comments.
|
235
|
-
* @param {ASTNode} node
|
236
|
-
* @param {SourceCode} sourceCode
|
231
|
+
* @param {ASTNode} node A node to check.
|
232
|
+
* @param {SourceCode} sourceCode A SourceCode instance to get comments.
|
237
233
|
* @returns {boolean} Whether or not the node has a `@this` tag in its comments.
|
238
234
|
*/
|
239
235
|
function hasJSDocThisTag(node, sourceCode) {
|
@@ -268,8 +264,7 @@ function isParenthesised(sourceCode, node) {
|
|
268
264
|
|
269
265
|
/**
|
270
266
|
* Checks if the given token is an arrow token or not.
|
271
|
-
*
|
272
|
-
* @param {Token} token - The token to check.
|
267
|
+
* @param {Token} token The token to check.
|
273
268
|
* @returns {boolean} `true` if the token is an arrow token.
|
274
269
|
*/
|
275
270
|
function isArrowToken(token) {
|
@@ -278,8 +273,7 @@ function isArrowToken(token) {
|
|
278
273
|
|
279
274
|
/**
|
280
275
|
* Checks if the given token is a comma token or not.
|
281
|
-
*
|
282
|
-
* @param {Token} token - The token to check.
|
276
|
+
* @param {Token} token The token to check.
|
283
277
|
* @returns {boolean} `true` if the token is a comma token.
|
284
278
|
*/
|
285
279
|
function isCommaToken(token) {
|
@@ -288,8 +282,7 @@ function isCommaToken(token) {
|
|
288
282
|
|
289
283
|
/**
|
290
284
|
* Checks if the given token is a dot token or not.
|
291
|
-
*
|
292
|
-
* @param {Token} token - The token to check.
|
285
|
+
* @param {Token} token The token to check.
|
293
286
|
* @returns {boolean} `true` if the token is a dot token.
|
294
287
|
*/
|
295
288
|
function isDotToken(token) {
|
@@ -298,8 +291,7 @@ function isDotToken(token) {
|
|
298
291
|
|
299
292
|
/**
|
300
293
|
* Checks if the given token is a semicolon token or not.
|
301
|
-
*
|
302
|
-
* @param {Token} token - The token to check.
|
294
|
+
* @param {Token} token The token to check.
|
303
295
|
* @returns {boolean} `true` if the token is a semicolon token.
|
304
296
|
*/
|
305
297
|
function isSemicolonToken(token) {
|
@@ -308,8 +300,7 @@ function isSemicolonToken(token) {
|
|
308
300
|
|
309
301
|
/**
|
310
302
|
* Checks if the given token is a colon token or not.
|
311
|
-
*
|
312
|
-
* @param {Token} token - The token to check.
|
303
|
+
* @param {Token} token The token to check.
|
313
304
|
* @returns {boolean} `true` if the token is a colon token.
|
314
305
|
*/
|
315
306
|
function isColonToken(token) {
|
@@ -318,8 +309,7 @@ function isColonToken(token) {
|
|
318
309
|
|
319
310
|
/**
|
320
311
|
* Checks if the given token is an opening parenthesis token or not.
|
321
|
-
*
|
322
|
-
* @param {Token} token - The token to check.
|
312
|
+
* @param {Token} token The token to check.
|
323
313
|
* @returns {boolean} `true` if the token is an opening parenthesis token.
|
324
314
|
*/
|
325
315
|
function isOpeningParenToken(token) {
|
@@ -328,8 +318,7 @@ function isOpeningParenToken(token) {
|
|
328
318
|
|
329
319
|
/**
|
330
320
|
* Checks if the given token is a closing parenthesis token or not.
|
331
|
-
*
|
332
|
-
* @param {Token} token - The token to check.
|
321
|
+
* @param {Token} token The token to check.
|
333
322
|
* @returns {boolean} `true` if the token is a closing parenthesis token.
|
334
323
|
*/
|
335
324
|
function isClosingParenToken(token) {
|
@@ -338,8 +327,7 @@ function isClosingParenToken(token) {
|
|
338
327
|
|
339
328
|
/**
|
340
329
|
* Checks if the given token is an opening square bracket token or not.
|
341
|
-
*
|
342
|
-
* @param {Token} token - The token to check.
|
330
|
+
* @param {Token} token The token to check.
|
343
331
|
* @returns {boolean} `true` if the token is an opening square bracket token.
|
344
332
|
*/
|
345
333
|
function isOpeningBracketToken(token) {
|
@@ -348,8 +336,7 @@ function isOpeningBracketToken(token) {
|
|
348
336
|
|
349
337
|
/**
|
350
338
|
* Checks if the given token is a closing square bracket token or not.
|
351
|
-
*
|
352
|
-
* @param {Token} token - The token to check.
|
339
|
+
* @param {Token} token The token to check.
|
353
340
|
* @returns {boolean} `true` if the token is a closing square bracket token.
|
354
341
|
*/
|
355
342
|
function isClosingBracketToken(token) {
|
@@ -358,8 +345,7 @@ function isClosingBracketToken(token) {
|
|
358
345
|
|
359
346
|
/**
|
360
347
|
* Checks if the given token is an opening brace token or not.
|
361
|
-
*
|
362
|
-
* @param {Token} token - The token to check.
|
348
|
+
* @param {Token} token The token to check.
|
363
349
|
* @returns {boolean} `true` if the token is an opening brace token.
|
364
350
|
*/
|
365
351
|
function isOpeningBraceToken(token) {
|
@@ -368,8 +354,7 @@ function isOpeningBraceToken(token) {
|
|
368
354
|
|
369
355
|
/**
|
370
356
|
* Checks if the given token is a closing brace token or not.
|
371
|
-
*
|
372
|
-
* @param {Token} token - The token to check.
|
357
|
+
* @param {Token} token The token to check.
|
373
358
|
* @returns {boolean} `true` if the token is a closing brace token.
|
374
359
|
*/
|
375
360
|
function isClosingBraceToken(token) {
|
@@ -378,8 +363,7 @@ function isClosingBraceToken(token) {
|
|
378
363
|
|
379
364
|
/**
|
380
365
|
* Checks if the given token is a comment token or not.
|
381
|
-
*
|
382
|
-
* @param {Token} token - The token to check.
|
366
|
+
* @param {Token} token The token to check.
|
383
367
|
* @returns {boolean} `true` if the token is a comment token.
|
384
368
|
*/
|
385
369
|
function isCommentToken(token) {
|
@@ -388,8 +372,7 @@ function isCommentToken(token) {
|
|
388
372
|
|
389
373
|
/**
|
390
374
|
* Checks if the given token is a keyword token or not.
|
391
|
-
*
|
392
|
-
* @param {Token} token - The token to check.
|
375
|
+
* @param {Token} token The token to check.
|
393
376
|
* @returns {boolean} `true` if the token is a keyword token.
|
394
377
|
*/
|
395
378
|
function isKeywordToken(token) {
|
@@ -398,9 +381,8 @@ function isKeywordToken(token) {
|
|
398
381
|
|
399
382
|
/**
|
400
383
|
* Gets the `(` token of the given function node.
|
401
|
-
*
|
402
|
-
* @param {
|
403
|
-
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
384
|
+
* @param {ASTNode} node The function node to get.
|
385
|
+
* @param {SourceCode} sourceCode The source code object to get tokens.
|
404
386
|
* @returns {Token} `(` token.
|
405
387
|
*/
|
406
388
|
function getOpeningParenOfParams(node, sourceCode) {
|
@@ -411,9 +393,9 @@ function getOpeningParenOfParams(node, sourceCode) {
|
|
411
393
|
|
412
394
|
/**
|
413
395
|
* Checks whether or not the tokens of two given nodes are same.
|
414
|
-
* @param {ASTNode} left
|
415
|
-
* @param {ASTNode} right
|
416
|
-
* @param {SourceCode} sourceCode
|
396
|
+
* @param {ASTNode} left A node 1 to compare.
|
397
|
+
* @param {ASTNode} right A node 2 to compare.
|
398
|
+
* @param {SourceCode} sourceCode The ESLint source code object.
|
417
399
|
* @returns {boolean} the source code for the given node.
|
418
400
|
*/
|
419
401
|
function equalTokens(left, right, sourceCode) {
|
@@ -447,8 +429,8 @@ module.exports = {
|
|
447
429
|
|
448
430
|
/**
|
449
431
|
* Determines whether two adjacent tokens are on the same line.
|
450
|
-
* @param {Object} left
|
451
|
-
* @param {Object} right
|
432
|
+
* @param {Object} left The left token object.
|
433
|
+
* @param {Object} right The right token object.
|
452
434
|
* @returns {boolean} Whether or not the tokens are on the same line.
|
453
435
|
* @public
|
454
436
|
*/
|
@@ -494,7 +476,7 @@ module.exports = {
|
|
494
476
|
|
495
477
|
/**
|
496
478
|
* Checks whether or not a given node is a string literal.
|
497
|
-
* @param {ASTNode} node
|
479
|
+
* @param {ASTNode} node A node to check.
|
498
480
|
* @returns {boolean} `true` if the node is a string literal.
|
499
481
|
*/
|
500
482
|
isStringLiteral(node) {
|
@@ -514,8 +496,7 @@ module.exports = {
|
|
514
496
|
* - ForStatement
|
515
497
|
* - SwitchStatement
|
516
498
|
* - WhileStatement
|
517
|
-
*
|
518
|
-
* @param {ASTNode} node - A node to check.
|
499
|
+
* @param {ASTNode} node A node to check.
|
519
500
|
* @returns {boolean} `true` if the node is breakable.
|
520
501
|
*/
|
521
502
|
isBreakableStatement(node) {
|
@@ -524,7 +505,7 @@ module.exports = {
|
|
524
505
|
|
525
506
|
/**
|
526
507
|
* Gets references which are non initializer and writable.
|
527
|
-
* @param {Reference[]} references
|
508
|
+
* @param {Reference[]} references An array of references.
|
528
509
|
* @returns {Reference[]} An array of only references which are non initializer and writable.
|
529
510
|
* @public
|
530
511
|
*/
|
@@ -568,7 +549,6 @@ module.exports = {
|
|
568
549
|
* consequent;
|
569
550
|
*
|
570
551
|
* When taking this `IfStatement`, returns `consequent;` statement.
|
571
|
-
*
|
572
552
|
* @param {ASTNode} A node to get.
|
573
553
|
* @returns {ASTNode|null} The trailing statement's node.
|
574
554
|
*/
|
@@ -576,9 +556,8 @@ module.exports = {
|
|
576
556
|
|
577
557
|
/**
|
578
558
|
* Finds the variable by a given name in a given scope and its upper scopes.
|
579
|
-
*
|
580
|
-
* @param {
|
581
|
-
* @param {string} name - A variable name to find.
|
559
|
+
* @param {eslint-scope.Scope} initScope A scope to start find.
|
560
|
+
* @param {string} name A variable name to find.
|
582
561
|
* @returns {eslint-scope.Variable|null} A found variable or `null`.
|
583
562
|
*/
|
584
563
|
getVariableByName(initScope, name) {
|
@@ -613,9 +592,8 @@ module.exports = {
|
|
613
592
|
* - The location is not on an ES2015 class.
|
614
593
|
* - Its `bind`/`call`/`apply` method is not called directly.
|
615
594
|
* - The function is not a callback of array methods (such as `.forEach()`) if `thisArg` is given.
|
616
|
-
*
|
617
|
-
* @param {
|
618
|
-
* @param {SourceCode} sourceCode - A SourceCode instance to get comments.
|
595
|
+
* @param {ASTNode} node A function node to check.
|
596
|
+
* @param {SourceCode} sourceCode A SourceCode instance to get comments.
|
619
597
|
* @returns {boolean} The function node is the default `this` binding.
|
620
598
|
*/
|
621
599
|
isDefaultThisBinding(node, sourceCode) {
|
@@ -861,8 +839,7 @@ module.exports = {
|
|
861
839
|
|
862
840
|
/**
|
863
841
|
* Checks whether the given node is an empty block node or not.
|
864
|
-
*
|
865
|
-
* @param {ASTNode|null} node - The node to check.
|
842
|
+
* @param {ASTNode|null} node The node to check.
|
866
843
|
* @returns {boolean} `true` if the node is an empty block.
|
867
844
|
*/
|
868
845
|
isEmptyBlock(node) {
|
@@ -871,8 +848,7 @@ module.exports = {
|
|
871
848
|
|
872
849
|
/**
|
873
850
|
* Checks whether the given node is an empty function node or not.
|
874
|
-
*
|
875
|
-
* @param {ASTNode|null} node - The node to check.
|
851
|
+
* @param {ASTNode|null} node The node to check.
|
876
852
|
* @returns {boolean} `true` if the node is an empty function.
|
877
853
|
*/
|
878
854
|
isEmptyFunction(node) {
|
@@ -906,8 +882,7 @@ module.exports = {
|
|
906
882
|
* let a = {["a" + "b"]: 1} // => null
|
907
883
|
* let a = {[tag`b`]: 1} // => null
|
908
884
|
* let a = {[`${b}`]: 1} // => null
|
909
|
-
*
|
910
|
-
* @param {ASTNode} node - The node to get.
|
885
|
+
* @param {ASTNode} node The node to get.
|
911
886
|
* @returns {string|null} The property name if static. Otherwise, null.
|
912
887
|
*/
|
913
888
|
getStaticPropertyName(node) {
|
@@ -950,7 +925,7 @@ module.exports = {
|
|
950
925
|
|
951
926
|
/**
|
952
927
|
* Get directives from directive prologue of a Program or Function node.
|
953
|
-
* @param {ASTNode} node
|
928
|
+
* @param {ASTNode} node The node to check.
|
954
929
|
* @returns {ASTNode[]} The directives found in the directive prologue.
|
955
930
|
*/
|
956
931
|
getDirectivePrologue(node) {
|
@@ -989,7 +964,7 @@ module.exports = {
|
|
989
964
|
/**
|
990
965
|
* Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added
|
991
966
|
* after the node will be parsed as a decimal point, rather than a property-access dot.
|
992
|
-
* @param {ASTNode} node
|
967
|
+
* @param {ASTNode} node The node to check.
|
993
968
|
* @returns {boolean} `true` if this node is a decimal integer.
|
994
969
|
* @example
|
995
970
|
*
|
@@ -1011,7 +986,7 @@ module.exports = {
|
|
1011
986
|
/**
|
1012
987
|
* Determines whether this token is a decimal integer numeric token.
|
1013
988
|
* This is similar to isDecimalInteger(), but for tokens.
|
1014
|
-
* @param {Token} token
|
989
|
+
* @param {Token} token The token to check.
|
1015
990
|
* @returns {boolean} `true` if this token is a decimal integer.
|
1016
991
|
*/
|
1017
992
|
isDecimalIntegerNumericToken(token) {
|
@@ -1063,8 +1038,7 @@ module.exports = {
|
|
1063
1038
|
* - `class A { static async foo() {} }` .... `static async method 'foo'`
|
1064
1039
|
* - `class A { static get foo() {} }` ...... `static getter 'foo'`
|
1065
1040
|
* - `class A { static set foo(a) {} }` ..... `static setter 'foo'`
|
1066
|
-
*
|
1067
|
-
* @param {ASTNode} node - The function node to get.
|
1041
|
+
* @param {ASTNode} node The function node to get.
|
1068
1042
|
* @returns {string} The name and kind of the function node.
|
1069
1043
|
*/
|
1070
1044
|
getFunctionNameWithKind(node) {
|
@@ -1198,9 +1172,8 @@ module.exports = {
|
|
1198
1172
|
* ^^^^^^^^^^^^^^
|
1199
1173
|
* - `class A { static set foo(a) {} }`
|
1200
1174
|
* ^^^^^^^^^^^^^^
|
1201
|
-
*
|
1202
|
-
* @param {
|
1203
|
-
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
1175
|
+
* @param {ASTNode} node The function node to get.
|
1176
|
+
* @param {SourceCode} sourceCode The source code object to get tokens.
|
1204
1177
|
* @returns {string} The location of the function node for reporting.
|
1205
1178
|
*/
|
1206
1179
|
getFunctionHeadLoc(node, sourceCode) {
|
@@ -1384,7 +1357,6 @@ module.exports = {
|
|
1384
1357
|
* "\00", "\01" ... "\09"
|
1385
1358
|
*
|
1386
1359
|
* "\0", when not followed by a digit, is not an octal escape sequence.
|
1387
|
-
*
|
1388
1360
|
* @param {string} rawString A string in its raw representation.
|
1389
1361
|
* @returns {boolean} `true` if the string contains at least one octal escape sequence.
|
1390
1362
|
*/
|
@@ -23,7 +23,6 @@ class FixTracker {
|
|
23
23
|
|
24
24
|
/**
|
25
25
|
* Create a new FixTracker.
|
26
|
-
*
|
27
26
|
* @param {ruleFixer} fixer A ruleFixer instance.
|
28
27
|
* @param {SourceCode} sourceCode A SourceCode object for the current code.
|
29
28
|
*/
|
@@ -36,7 +35,6 @@ class FixTracker {
|
|
36
35
|
/**
|
37
36
|
* Mark the given range as "retained", meaning that other fixes may not
|
38
37
|
* may not modify this region in the same pass.
|
39
|
-
*
|
40
38
|
* @param {int[]} range The range to retain.
|
41
39
|
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
42
40
|
*/
|
@@ -50,7 +48,6 @@ class FixTracker {
|
|
50
48
|
* mark it as retained, meaning that other fixes may not modify it in this
|
51
49
|
* pass. This is useful for avoiding conflicts in fixes that modify control
|
52
50
|
* flow.
|
53
|
-
*
|
54
51
|
* @param {ASTNode} node The node to use as a starting point.
|
55
52
|
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
56
53
|
*/
|
@@ -65,7 +62,6 @@ class FixTracker {
|
|
65
62
|
* range as retained, meaning that other fixes may not modify it in this
|
66
63
|
* pass. This is useful for avoiding conflicts in fixes that make a small
|
67
64
|
* change to the code where the AST should not be changed.
|
68
|
-
*
|
69
65
|
* @param {ASTNode|Token} nodeOrToken The node or token to use as a starting
|
70
66
|
* point. The token to the left and right are use in the range.
|
71
67
|
* @returns {FixTracker} The same RuleFixer, for chained calls.
|
@@ -80,7 +76,6 @@ class FixTracker {
|
|
80
76
|
/**
|
81
77
|
* Create a fix command that replaces the given range with the given text,
|
82
78
|
* accounting for any retained ranges.
|
83
|
-
*
|
84
79
|
* @param {int[]} range The range to remove in the fix.
|
85
80
|
* @param {string} text The text to insert in place of the range.
|
86
81
|
* @returns {Object} The fix command.
|
@@ -108,7 +103,6 @@ class FixTracker {
|
|
108
103
|
/**
|
109
104
|
* Create a fix command that removes the given node or token, accounting for
|
110
105
|
* any retained ranges.
|
111
|
-
*
|
112
106
|
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
113
107
|
* @returns {Object} The fix command.
|
114
108
|
*/
|