eslint 6.5.1 → 6.7.2
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 +118 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +65 -34
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- 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/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- 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/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- 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 +12 -9
- 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 +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -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-comment-style.js +237 -106
- 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-cond-assign.js +14 -4
- 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-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- 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-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- 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-octal-escape.js +1 -1
- 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-setter-return.js +227 -0
- 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-underscore-dangle.js +23 -4
- package/lib/rules/no-unexpected-multiline.js +8 -0
- 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-computed-key.js +60 -33
- 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 +29 -8
- 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 +21 -22
- 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 +33 -3
- 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 +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- 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 +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- 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 +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- 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 +84 -85
- 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/shared/types.js +9 -0
- package/lib/source-code/source-code.js +94 -17
- 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 +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -28,9 +28,8 @@ const INDEX_MAP = Symbol("indexMap");
|
|
28
28
|
*
|
29
29
|
* The first/last location of tokens is mapped to the index of the token.
|
30
30
|
* The first/last location of comments is mapped to the index of the next token of each comment.
|
31
|
-
*
|
32
|
-
* @param {
|
33
|
-
* @param {Comment[]} comments - The array of comments.
|
31
|
+
* @param {Token[]} tokens The array of tokens.
|
32
|
+
* @param {Comment[]} comments The array of comments.
|
34
33
|
* @returns {Object} The map from locations to indices in `tokens`.
|
35
34
|
* @private
|
36
35
|
*/
|
@@ -62,17 +61,16 @@ function createIndexMap(tokens, comments) {
|
|
62
61
|
|
63
62
|
/**
|
64
63
|
* Creates the cursor iterates tokens with options.
|
65
|
-
*
|
66
|
-
* @param {
|
67
|
-
* @param {
|
68
|
-
* @param {
|
69
|
-
* @param {
|
70
|
-
* @param {number}
|
71
|
-
* @param {number}
|
72
|
-
* @param {
|
73
|
-
* @param {
|
74
|
-
* @param {
|
75
|
-
* @param {number} [opts.skip=0] - The count of tokens the cursor skips.
|
64
|
+
* @param {CursorFactory} factory The cursor factory to initialize cursor.
|
65
|
+
* @param {Token[]} tokens The array of tokens.
|
66
|
+
* @param {Comment[]} comments The array of comments.
|
67
|
+
* @param {Object} indexMap The map from locations to indices in `tokens`.
|
68
|
+
* @param {number} startLoc The start location of the iteration range.
|
69
|
+
* @param {number} endLoc The end location of the iteration range.
|
70
|
+
* @param {number|Function|Object} [opts=0] The option object. If this is a number then it's `opts.skip`. If this is a function then it's `opts.filter`.
|
71
|
+
* @param {boolean} [opts.includeComments=false] The flag to iterate comments as well.
|
72
|
+
* @param {Function|null} [opts.filter=null] The predicate function to choose tokens.
|
73
|
+
* @param {number} [opts.skip=0] The count of tokens the cursor skips.
|
76
74
|
* @returns {Cursor} The created cursor.
|
77
75
|
* @private
|
78
76
|
*/
|
@@ -98,17 +96,16 @@ function createCursorWithSkip(factory, tokens, comments, indexMap, startLoc, end
|
|
98
96
|
|
99
97
|
/**
|
100
98
|
* Creates the cursor iterates tokens with options.
|
101
|
-
*
|
102
|
-
* @param {
|
103
|
-
* @param {
|
104
|
-
* @param {
|
105
|
-
* @param {
|
106
|
-
* @param {number}
|
107
|
-
* @param {number}
|
108
|
-
* @param {
|
109
|
-
* @param {
|
110
|
-
* @param {
|
111
|
-
* @param {number} [opts.count=0] - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
|
99
|
+
* @param {CursorFactory} factory The cursor factory to initialize cursor.
|
100
|
+
* @param {Token[]} tokens The array of tokens.
|
101
|
+
* @param {Comment[]} comments The array of comments.
|
102
|
+
* @param {Object} indexMap The map from locations to indices in `tokens`.
|
103
|
+
* @param {number} startLoc The start location of the iteration range.
|
104
|
+
* @param {number} endLoc The end location of the iteration range.
|
105
|
+
* @param {number|Function|Object} [opts=0] The option object. If this is a number then it's `opts.count`. If this is a function then it's `opts.filter`.
|
106
|
+
* @param {boolean} [opts.includeComments] The flag to iterate comments as well.
|
107
|
+
* @param {Function|null} [opts.filter=null] The predicate function to choose tokens.
|
108
|
+
* @param {number} [opts.count=0] The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
|
112
109
|
* @returns {Cursor} The created cursor.
|
113
110
|
* @private
|
114
111
|
*/
|
@@ -138,29 +135,27 @@ function createCursorWithCount(factory, tokens, comments, indexMap, startLoc, en
|
|
138
135
|
/**
|
139
136
|
* Creates the cursor iterates tokens with options.
|
140
137
|
* This is overload function of the below.
|
141
|
-
*
|
142
|
-
* @param {
|
143
|
-
* @param {
|
144
|
-
* @param {
|
145
|
-
* @param {number}
|
146
|
-
* @param {
|
147
|
-
* @param {
|
148
|
-
* @param {
|
149
|
-
* @param {
|
150
|
-
* @param {number} [opts.count=0] - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
|
138
|
+
* @param {Token[]} tokens The array of tokens.
|
139
|
+
* @param {Comment[]} comments The array of comments.
|
140
|
+
* @param {Object} indexMap The map from locations to indices in `tokens`.
|
141
|
+
* @param {number} startLoc The start location of the iteration range.
|
142
|
+
* @param {number} endLoc The end location of the iteration range.
|
143
|
+
* @param {Function|Object} opts The option object. If this is a function then it's `opts.filter`.
|
144
|
+
* @param {boolean} [opts.includeComments] The flag to iterate comments as well.
|
145
|
+
* @param {Function|null} [opts.filter=null] The predicate function to choose tokens.
|
146
|
+
* @param {number} [opts.count=0] The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
|
151
147
|
* @returns {Cursor} The created cursor.
|
152
148
|
* @private
|
153
149
|
*/
|
154
150
|
/**
|
155
151
|
* Creates the cursor iterates tokens with options.
|
156
|
-
*
|
157
|
-
* @param {
|
158
|
-
* @param {
|
159
|
-
* @param {
|
160
|
-
* @param {number}
|
161
|
-
* @param {number}
|
162
|
-
* @param {
|
163
|
-
* @param {boolean} [afterCount=0] - The number of tokens after the node to retrieve.
|
152
|
+
* @param {Token[]} tokens The array of tokens.
|
153
|
+
* @param {Comment[]} comments The array of comments.
|
154
|
+
* @param {Object} indexMap The map from locations to indices in `tokens`.
|
155
|
+
* @param {number} startLoc The start location of the iteration range.
|
156
|
+
* @param {number} endLoc The end location of the iteration range.
|
157
|
+
* @param {number} [beforeCount=0] The number of tokens before the node to retrieve.
|
158
|
+
* @param {boolean} [afterCount=0] The number of tokens after the node to retrieve.
|
164
159
|
* @returns {Cursor} The created cursor.
|
165
160
|
* @private
|
166
161
|
*/
|
@@ -176,7 +171,7 @@ function createCursorWithPadding(tokens, comments, indexMap, startLoc, endLoc, b
|
|
176
171
|
|
177
172
|
/**
|
178
173
|
* Gets comment tokens that are adjacent to the current cursor position.
|
179
|
-
* @param {Cursor} cursor
|
174
|
+
* @param {Cursor} cursor A cursor instance.
|
180
175
|
* @returns {Array} An array of comment tokens adjacent to the current cursor position.
|
181
176
|
* @private
|
182
177
|
*/
|
@@ -211,8 +206,8 @@ module.exports = class TokenStore {
|
|
211
206
|
|
212
207
|
/**
|
213
208
|
* Initializes this token store.
|
214
|
-
* @param {Token[]} tokens
|
215
|
-
* @param {Comment[]} comments
|
209
|
+
* @param {Token[]} tokens The array of tokens.
|
210
|
+
* @param {Comment[]} comments The array of comments.
|
216
211
|
*/
|
217
212
|
constructor(tokens, comments) {
|
218
213
|
this[TOKENS] = tokens;
|
@@ -226,9 +221,9 @@ module.exports = class TokenStore {
|
|
226
221
|
|
227
222
|
/**
|
228
223
|
* Gets the token starting at the specified index.
|
229
|
-
* @param {number} offset
|
230
|
-
* @param {Object} [options=0]
|
231
|
-
* @param {boolean} [options.includeComments=false]
|
224
|
+
* @param {number} offset Index of the start of the token's range.
|
225
|
+
* @param {Object} [options=0] The option object.
|
226
|
+
* @param {boolean} [options.includeComments=false] The flag to iterate comments as well.
|
232
227
|
* @returns {Token|null} The token starting at index, or null if no such token.
|
233
228
|
*/
|
234
229
|
getTokenByRangeStart(offset, options) {
|
@@ -250,11 +245,11 @@ module.exports = class TokenStore {
|
|
250
245
|
|
251
246
|
/**
|
252
247
|
* Gets the first token of the given node.
|
253
|
-
* @param {ASTNode} node
|
254
|
-
* @param {number|Function|Object} [options=0]
|
255
|
-
* @param {boolean} [options.includeComments=false]
|
256
|
-
* @param {Function|null} [options.filter=null]
|
257
|
-
* @param {number} [options.skip=0]
|
248
|
+
* @param {ASTNode} node The AST node.
|
249
|
+
* @param {number|Function|Object} [options=0] The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.
|
250
|
+
* @param {boolean} [options.includeComments=false] The flag to iterate comments as well.
|
251
|
+
* @param {Function|null} [options.filter=null] The predicate function to choose tokens.
|
252
|
+
* @param {number} [options.skip=0] The count of tokens the cursor skips.
|
258
253
|
* @returns {Token|null} An object representing the token.
|
259
254
|
*/
|
260
255
|
getFirstToken(node, options) {
|
@@ -271,8 +266,8 @@ module.exports = class TokenStore {
|
|
271
266
|
|
272
267
|
/**
|
273
268
|
* Gets the last token of the given node.
|
274
|
-
* @param {ASTNode} node
|
275
|
-
* @param {number|Function|Object} [options=0]
|
269
|
+
* @param {ASTNode} node The AST node.
|
270
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstToken()
|
276
271
|
* @returns {Token|null} An object representing the token.
|
277
272
|
*/
|
278
273
|
getLastToken(node, options) {
|
@@ -289,8 +284,8 @@ module.exports = class TokenStore {
|
|
289
284
|
|
290
285
|
/**
|
291
286
|
* Gets the token that precedes a given node or token.
|
292
|
-
* @param {ASTNode|Token|Comment} node
|
293
|
-
* @param {number|Function|Object} [options=0]
|
287
|
+
* @param {ASTNode|Token|Comment} node The AST node or token.
|
288
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstToken()
|
294
289
|
* @returns {Token|null} An object representing the token.
|
295
290
|
*/
|
296
291
|
getTokenBefore(node, options) {
|
@@ -307,8 +302,8 @@ module.exports = class TokenStore {
|
|
307
302
|
|
308
303
|
/**
|
309
304
|
* Gets the token that follows a given node or token.
|
310
|
-
* @param {ASTNode|Token|Comment} node
|
311
|
-
* @param {number|Function|Object} [options=0]
|
305
|
+
* @param {ASTNode|Token|Comment} node The AST node or token.
|
306
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstToken()
|
312
307
|
* @returns {Token|null} An object representing the token.
|
313
308
|
*/
|
314
309
|
getTokenAfter(node, options) {
|
@@ -325,9 +320,9 @@ module.exports = class TokenStore {
|
|
325
320
|
|
326
321
|
/**
|
327
322
|
* Gets the first token between two non-overlapping nodes.
|
328
|
-
* @param {ASTNode|Token|Comment} left
|
329
|
-
* @param {ASTNode|Token|Comment} right
|
330
|
-
* @param {number|Function|Object} [options=0]
|
323
|
+
* @param {ASTNode|Token|Comment} left Node before the desired token range.
|
324
|
+
* @param {ASTNode|Token|Comment} right Node after the desired token range.
|
325
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstToken()
|
331
326
|
* @returns {Token|null} An object representing the token.
|
332
327
|
*/
|
333
328
|
getFirstTokenBetween(left, right, options) {
|
@@ -346,7 +341,7 @@ module.exports = class TokenStore {
|
|
346
341
|
* Gets the last token between two non-overlapping nodes.
|
347
342
|
* @param {ASTNode|Token|Comment} left Node before the desired token range.
|
348
343
|
* @param {ASTNode|Token|Comment} right Node after the desired token range.
|
349
|
-
* @param {number|Function|Object} [options=0]
|
344
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstToken()
|
350
345
|
* @returns {Token|null} An object representing the token.
|
351
346
|
*/
|
352
347
|
getLastTokenBetween(left, right, options) {
|
@@ -393,11 +388,11 @@ module.exports = class TokenStore {
|
|
393
388
|
|
394
389
|
/**
|
395
390
|
* Gets the first `count` tokens of the given node.
|
396
|
-
* @param {ASTNode} node
|
397
|
-
* @param {number|Function|Object} [options=0]
|
398
|
-
* @param {boolean} [options.includeComments=false]
|
399
|
-
* @param {Function|null} [options.filter=null]
|
400
|
-
* @param {number} [options.count=0]
|
391
|
+
* @param {ASTNode} node The AST node.
|
392
|
+
* @param {number|Function|Object} [options=0] The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
|
393
|
+
* @param {boolean} [options.includeComments=false] The flag to iterate comments as well.
|
394
|
+
* @param {Function|null} [options.filter=null] The predicate function to choose tokens.
|
395
|
+
* @param {number} [options.count=0] The maximum count of tokens the cursor iterates.
|
401
396
|
* @returns {Token[]} Tokens.
|
402
397
|
*/
|
403
398
|
getFirstTokens(node, options) {
|
@@ -414,8 +409,8 @@ module.exports = class TokenStore {
|
|
414
409
|
|
415
410
|
/**
|
416
411
|
* Gets the last `count` tokens of the given node.
|
417
|
-
* @param {ASTNode} node
|
418
|
-
* @param {number|Function|Object} [options=0]
|
412
|
+
* @param {ASTNode} node The AST node.
|
413
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstTokens()
|
419
414
|
* @returns {Token[]} Tokens.
|
420
415
|
*/
|
421
416
|
getLastTokens(node, options) {
|
@@ -432,8 +427,8 @@ module.exports = class TokenStore {
|
|
432
427
|
|
433
428
|
/**
|
434
429
|
* Gets the `count` tokens that precedes a given node or token.
|
435
|
-
* @param {ASTNode|Token|Comment} node
|
436
|
-
* @param {number|Function|Object} [options=0]
|
430
|
+
* @param {ASTNode|Token|Comment} node The AST node or token.
|
431
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstTokens()
|
437
432
|
* @returns {Token[]} Tokens.
|
438
433
|
*/
|
439
434
|
getTokensBefore(node, options) {
|
@@ -450,8 +445,8 @@ module.exports = class TokenStore {
|
|
450
445
|
|
451
446
|
/**
|
452
447
|
* Gets the `count` tokens that follows a given node or token.
|
453
|
-
* @param {ASTNode|Token|Comment} node
|
454
|
-
* @param {number|Function|Object} [options=0]
|
448
|
+
* @param {ASTNode|Token|Comment} node The AST node or token.
|
449
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstTokens()
|
455
450
|
* @returns {Token[]} Tokens.
|
456
451
|
*/
|
457
452
|
getTokensAfter(node, options) {
|
@@ -468,9 +463,9 @@ module.exports = class TokenStore {
|
|
468
463
|
|
469
464
|
/**
|
470
465
|
* Gets the first `count` tokens between two non-overlapping nodes.
|
471
|
-
* @param {ASTNode|Token|Comment} left
|
472
|
-
* @param {ASTNode|Token|Comment} right
|
473
|
-
* @param {number|Function|Object} [options=0]
|
466
|
+
* @param {ASTNode|Token|Comment} left Node before the desired token range.
|
467
|
+
* @param {ASTNode|Token|Comment} right Node after the desired token range.
|
468
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstTokens()
|
474
469
|
* @returns {Token[]} Tokens between left and right.
|
475
470
|
*/
|
476
471
|
getFirstTokensBetween(left, right, options) {
|
@@ -489,7 +484,7 @@ module.exports = class TokenStore {
|
|
489
484
|
* Gets the last `count` tokens between two non-overlapping nodes.
|
490
485
|
* @param {ASTNode|Token|Comment} left Node before the desired token range.
|
491
486
|
* @param {ASTNode|Token|Comment} right Node after the desired token range.
|
492
|
-
* @param {number|Function|Object} [options=0]
|
487
|
+
* @param {number|Function|Object} [options=0] The option object. Same options as getFirstTokens()
|
493
488
|
* @returns {Token[]} Tokens between left and right.
|
494
489
|
*/
|
495
490
|
getLastTokensBetween(left, right, options) {
|
@@ -506,18 +501,18 @@ module.exports = class TokenStore {
|
|
506
501
|
|
507
502
|
/**
|
508
503
|
* Gets all tokens that are related to the given node.
|
509
|
-
* @param {ASTNode} node
|
504
|
+
* @param {ASTNode} node The AST node.
|
510
505
|
* @param {Function|Object} options The option object. If this is a function then it's `options.filter`.
|
511
|
-
* @param {boolean} [options.includeComments=false]
|
512
|
-
* @param {Function|null} [options.filter=null]
|
513
|
-
* @param {number} [options.count=0]
|
506
|
+
* @param {boolean} [options.includeComments=false] The flag to iterate comments as well.
|
507
|
+
* @param {Function|null} [options.filter=null] The predicate function to choose tokens.
|
508
|
+
* @param {number} [options.count=0] The maximum count of tokens the cursor iterates.
|
514
509
|
* @returns {Token[]} Array of objects representing tokens.
|
515
510
|
*/
|
516
511
|
/**
|
517
512
|
* Gets all tokens that are related to the given node.
|
518
|
-
* @param {ASTNode} node
|
519
|
-
* @param {int} [beforeCount=0]
|
520
|
-
* @param {int} [afterCount=0]
|
513
|
+
* @param {ASTNode} node The AST node.
|
514
|
+
* @param {int} [beforeCount=0] The number of tokens before the node to retrieve.
|
515
|
+
* @param {int} [afterCount=0] The number of tokens after the node to retrieve.
|
521
516
|
* @returns {Token[]} Array of objects representing tokens.
|
522
517
|
*/
|
523
518
|
getTokens(node, beforeCount, afterCount) {
|
@@ -537,9 +532,9 @@ module.exports = class TokenStore {
|
|
537
532
|
* @param {ASTNode|Token|Comment} left Node before the desired token range.
|
538
533
|
* @param {ASTNode|Token|Comment} right Node after the desired token range.
|
539
534
|
* @param {Function|Object} options The option object. If this is a function then it's `options.filter`.
|
540
|
-
* @param {boolean} [options.includeComments=false]
|
541
|
-
* @param {Function|null} [options.filter=null]
|
542
|
-
* @param {number} [options.count=0]
|
535
|
+
* @param {boolean} [options.includeComments=false] The flag to iterate comments as well.
|
536
|
+
* @param {Function|null} [options.filter=null] The predicate function to choose tokens.
|
537
|
+
* @param {number} [options.count=0] The maximum count of tokens the cursor iterates.
|
543
538
|
* @returns {Token[]} Tokens between left and right.
|
544
539
|
*/
|
545
540
|
/**
|
@@ -567,9 +562,8 @@ module.exports = class TokenStore {
|
|
567
562
|
|
568
563
|
/**
|
569
564
|
* Checks whether any comments exist or not between the given 2 nodes.
|
570
|
-
*
|
571
|
-
* @param {ASTNode}
|
572
|
-
* @param {ASTNode} right - The node to check.
|
565
|
+
* @param {ASTNode} left The node to check.
|
566
|
+
* @param {ASTNode} right The node to check.
|
573
567
|
* @returns {boolean} `true` if one or more comments exist.
|
574
568
|
*/
|
575
569
|
commentsExistBetween(left, right) {
|
@@ -21,8 +21,8 @@ module.exports = class LimitCursor extends DecorativeCursor {
|
|
21
21
|
|
22
22
|
/**
|
23
23
|
* Initializes this cursor.
|
24
|
-
* @param {Cursor} cursor
|
25
|
-
* @param {number} count
|
24
|
+
* @param {Cursor} cursor The cursor to be decorated.
|
25
|
+
* @param {number} count The count of tokens this cursor iterates.
|
26
26
|
*/
|
27
27
|
constructor(cursor, count) {
|
28
28
|
super(cursor);
|
@@ -22,13 +22,13 @@ module.exports = class PaddedTokenCursor extends ForwardTokenCursor {
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* Initializes this cursor.
|
25
|
-
* @param {Token[]} tokens
|
26
|
-
* @param {Comment[]} comments
|
27
|
-
* @param {Object} indexMap
|
28
|
-
* @param {number} startLoc
|
29
|
-
* @param {number} endLoc
|
30
|
-
* @param {number} beforeCount
|
31
|
-
* @param {number} afterCount
|
25
|
+
* @param {Token[]} tokens The array of tokens.
|
26
|
+
* @param {Comment[]} comments The array of comments.
|
27
|
+
* @param {Object} indexMap The map from locations to indices in `tokens`.
|
28
|
+
* @param {number} startLoc The start location of the iteration range.
|
29
|
+
* @param {number} endLoc The end location of the iteration range.
|
30
|
+
* @param {number} beforeCount The number of tokens this cursor iterates before start.
|
31
|
+
* @param {number} afterCount The number of tokens this cursor iterates after end.
|
32
32
|
*/
|
33
33
|
constructor(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
|
34
34
|
super(tokens, comments, indexMap, startLoc, endLoc);
|
@@ -21,8 +21,8 @@ module.exports = class SkipCursor extends DecorativeCursor {
|
|
21
21
|
|
22
22
|
/**
|
23
23
|
* Initializes this cursor.
|
24
|
-
* @param {Cursor} cursor
|
25
|
-
* @param {number} count
|
24
|
+
* @param {Cursor} cursor The cursor to be decorated.
|
25
|
+
* @param {number} count The count of tokens this cursor skips.
|
26
26
|
*/
|
27
27
|
constructor(cursor, count) {
|
28
28
|
super(cursor);
|
@@ -16,8 +16,7 @@ const lodash = require("lodash");
|
|
16
16
|
|
17
17
|
/**
|
18
18
|
* Gets `token.range[0]` from the given token.
|
19
|
-
*
|
20
|
-
* @param {Node|Token|Comment} token - The token to get.
|
19
|
+
* @param {Node|Token|Comment} token The token to get.
|
21
20
|
* @returns {number} The start location.
|
22
21
|
* @private
|
23
22
|
*/
|
@@ -32,9 +31,8 @@ function getStartLocation(token) {
|
|
32
31
|
/**
|
33
32
|
* Binary-searches the index of the first token which is after the given location.
|
34
33
|
* If it was not found, this returns `tokens.length`.
|
35
|
-
*
|
36
|
-
* @param {
|
37
|
-
* @param {number} location - The location to search.
|
34
|
+
* @param {(Token|Comment)[]} tokens It searches the token in this list.
|
35
|
+
* @param {number} location The location to search.
|
38
36
|
* @returns {number} The found index or `tokens.length`.
|
39
37
|
*/
|
40
38
|
exports.search = function search(tokens, location) {
|
@@ -48,10 +46,9 @@ exports.search = function search(tokens, location) {
|
|
48
46
|
/**
|
49
47
|
* Gets the index of the `startLoc` in `tokens`.
|
50
48
|
* `startLoc` can be the value of `node.range[1]`, so this checks about `startLoc - 1` as well.
|
51
|
-
*
|
52
|
-
* @param {
|
53
|
-
* @param {
|
54
|
-
* @param {number} startLoc - The location to get an index.
|
49
|
+
* @param {(Token|Comment)[]} tokens The tokens to find an index.
|
50
|
+
* @param {Object} indexMap The map from locations to indices.
|
51
|
+
* @param {number} startLoc The location to get an index.
|
55
52
|
* @returns {number} The index.
|
56
53
|
*/
|
57
54
|
exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
@@ -77,10 +74,9 @@ exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
|
77
74
|
/**
|
78
75
|
* Gets the index of the `endLoc` in `tokens`.
|
79
76
|
* The information of end locations are recorded at `endLoc - 1` in `indexMap`, so this checks about `endLoc - 1` as well.
|
80
|
-
*
|
81
|
-
* @param {
|
82
|
-
* @param {
|
83
|
-
* @param {number} endLoc - The location to get an index.
|
77
|
+
* @param {(Token|Comment)[]} tokens The tokens to find an index.
|
78
|
+
* @param {Object} indexMap The map from locations to indices.
|
79
|
+
* @param {number} endLoc The location to get an index.
|
84
80
|
* @returns {number} The index.
|
85
81
|
*/
|
86
82
|
exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.7.2",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -9,6 +9,7 @@
|
|
9
9
|
"main": "./lib/api.js",
|
10
10
|
"scripts": {
|
11
11
|
"test": "node Makefile.js test",
|
12
|
+
"test:cli": "mocha",
|
12
13
|
"lint": "node Makefile.js lint",
|
13
14
|
"fix": "node Makefile.js lint -- fix",
|
14
15
|
"fuzz": "node Makefile.js fuzz",
|
@@ -41,6 +42,7 @@
|
|
41
42
|
"messages"
|
42
43
|
],
|
43
44
|
"repository": "eslint/eslint",
|
45
|
+
"funding": "https://opencollective.com/eslint",
|
44
46
|
"homepage": "https://eslint.org",
|
45
47
|
"bugs": "https://github.com/eslint/eslint/issues/",
|
46
48
|
"dependencies": {
|
@@ -51,19 +53,19 @@
|
|
51
53
|
"debug": "^4.0.1",
|
52
54
|
"doctrine": "^3.0.0",
|
53
55
|
"eslint-scope": "^5.0.0",
|
54
|
-
"eslint-utils": "^1.4.
|
56
|
+
"eslint-utils": "^1.4.3",
|
55
57
|
"eslint-visitor-keys": "^1.1.0",
|
56
|
-
"espree": "^6.1.
|
58
|
+
"espree": "^6.1.2",
|
57
59
|
"esquery": "^1.0.1",
|
58
60
|
"esutils": "^2.0.2",
|
59
61
|
"file-entry-cache": "^5.0.1",
|
60
62
|
"functional-red-black-tree": "^1.0.1",
|
61
63
|
"glob-parent": "^5.0.0",
|
62
|
-
"globals": "^
|
64
|
+
"globals": "^12.1.0",
|
63
65
|
"ignore": "^4.0.6",
|
64
66
|
"import-fresh": "^3.0.0",
|
65
67
|
"imurmurhash": "^0.1.4",
|
66
|
-
"inquirer": "^
|
68
|
+
"inquirer": "^7.0.0",
|
67
69
|
"is-glob": "^4.0.0",
|
68
70
|
"js-yaml": "^3.13.1",
|
69
71
|
"json-stable-stringify-without-jsonify": "^1.0.1",
|
@@ -72,7 +74,7 @@
|
|
72
74
|
"minimatch": "^3.0.4",
|
73
75
|
"mkdirp": "^0.5.1",
|
74
76
|
"natural-compare": "^1.4.0",
|
75
|
-
"optionator": "^0.8.
|
77
|
+
"optionator": "^0.8.3",
|
76
78
|
"progress": "^2.0.0",
|
77
79
|
"regexpp": "^2.0.1",
|
78
80
|
"semver": "^6.1.2",
|
@@ -85,7 +87,7 @@
|
|
85
87
|
"devDependencies": {
|
86
88
|
"@babel/core": "^7.4.3",
|
87
89
|
"@babel/preset-env": "^7.4.3",
|
88
|
-
"acorn": "^7.
|
90
|
+
"acorn": "^7.1.0",
|
89
91
|
"babel-loader": "^8.0.5",
|
90
92
|
"chai": "^4.0.1",
|
91
93
|
"cheerio": "^0.22.0",
|