eslint 8.21.0 → 8.23.1
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/bin/eslint.js +2 -4
- package/conf/globals.js +6 -1
- package/lib/cli-engine/file-enumerator.js +4 -2
- package/lib/cli.js +123 -29
- package/lib/config/flat-config-array.js +53 -12
- package/lib/eslint/eslint-helpers.js +39 -16
- package/lib/eslint/flat-eslint.js +29 -17
- package/lib/linter/code-path-analysis/code-path-segment.js +2 -2
- package/lib/linter/code-path-analysis/code-path-state.js +7 -7
- package/lib/linter/code-path-analysis/debug-helpers.js +3 -3
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/config-comment-parser.js +1 -2
- package/lib/linter/timing.js +4 -4
- package/lib/options.js +290 -242
- package/lib/rule-tester/flat-rule-tester.js +1 -1
- package/lib/rule-tester/rule-tester.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/global-require.js +2 -1
- package/lib/rules/indent-legacy.js +4 -4
- package/lib/rules/indent.js +23 -15
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-parens.js +2 -2
- package/lib/rules/no-fallthrough.js +8 -3
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +24 -5
- package/lib/rules/object-shorthand.js +15 -0
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/prefer-arrow-callback.js +2 -2
- package/lib/rules/prefer-const.js +13 -1
- package/lib/rules/prefer-rest-params.js +1 -1
- package/lib/rules/require-yield.js +0 -1
- package/lib/rules/utils/ast-utils.js +10 -4
- package/lib/shared/logging.js +1 -1
- package/lib/shared/types.js +1 -1
- package/lib/source-code/token-store/cursor.js +1 -1
- package/package.json +9 -8
package/lib/options.js
CHANGED
@@ -63,261 +63,309 @@ const optionator = require("optionator");
|
|
63
63
|
//------------------------------------------------------------------------------
|
64
64
|
|
65
65
|
// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Creates the CLI options for ESLint.
|
69
|
+
* @param {boolean} usingFlatConfig Indicates if flat config is being used.
|
70
|
+
* @returns {Object} The opinionator instance.
|
71
|
+
*/
|
72
|
+
module.exports = function(usingFlatConfig) {
|
73
|
+
|
74
|
+
let lookupFlag;
|
75
|
+
|
76
|
+
if (usingFlatConfig) {
|
77
|
+
lookupFlag = {
|
78
|
+
option: "config-lookup",
|
79
|
+
type: "Boolean",
|
80
|
+
default: "true",
|
81
|
+
description: "Disable look up for eslint.config.js"
|
82
|
+
};
|
83
|
+
} else {
|
84
|
+
lookupFlag = {
|
77
85
|
option: "eslintrc",
|
78
86
|
type: "Boolean",
|
79
87
|
default: "true",
|
80
88
|
description: "Disable use of configuration from .eslintrc.*"
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
{
|
89
|
+
};
|
90
|
+
}
|
91
|
+
|
92
|
+
let envFlag;
|
93
|
+
|
94
|
+
if (!usingFlatConfig) {
|
95
|
+
envFlag = {
|
89
96
|
option: "env",
|
90
97
|
type: "[String]",
|
91
98
|
description: "Specify environments"
|
92
|
-
}
|
93
|
-
|
99
|
+
};
|
100
|
+
}
|
101
|
+
|
102
|
+
let extFlag;
|
103
|
+
|
104
|
+
if (!usingFlatConfig) {
|
105
|
+
extFlag = {
|
94
106
|
option: "ext",
|
95
107
|
type: "[String]",
|
96
108
|
description: "Specify JavaScript file extensions"
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
{
|
104
|
-
option: "parser",
|
105
|
-
type: "String",
|
106
|
-
description: "Specify the parser to be used"
|
107
|
-
},
|
108
|
-
{
|
109
|
-
option: "parser-options",
|
110
|
-
type: "Object",
|
111
|
-
description: "Specify parser options"
|
112
|
-
},
|
113
|
-
{
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
112
|
+
let resolvePluginsFlag;
|
113
|
+
|
114
|
+
if (!usingFlatConfig) {
|
115
|
+
resolvePluginsFlag = {
|
114
116
|
option: "resolve-plugins-relative-to",
|
115
117
|
type: "path::String",
|
116
118
|
description: "A folder where plugins should be resolved from, CWD by default"
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
description: "Specify plugins"
|
125
|
-
},
|
126
|
-
{
|
127
|
-
option: "rule",
|
128
|
-
type: "Object",
|
129
|
-
description: "Specify rules"
|
130
|
-
},
|
131
|
-
{
|
119
|
+
};
|
120
|
+
}
|
121
|
+
|
122
|
+
let rulesDirFlag;
|
123
|
+
|
124
|
+
if (!usingFlatConfig) {
|
125
|
+
rulesDirFlag = {
|
132
126
|
option: "rulesdir",
|
133
127
|
type: "[path::String]",
|
134
128
|
description: "Load additional rules from this directory. Deprecated: Use rules from plugins"
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
129
|
+
};
|
130
|
+
}
|
131
|
+
|
132
|
+
return optionator({
|
133
|
+
prepend: "eslint [options] file.js [file.js] [dir]",
|
134
|
+
defaults: {
|
135
|
+
concatRepeatedArrays: true,
|
136
|
+
mergeRepeatedObjects: true
|
137
|
+
},
|
138
|
+
options: [
|
139
|
+
{
|
140
|
+
heading: "Basic configuration"
|
141
|
+
},
|
142
|
+
lookupFlag,
|
143
|
+
{
|
144
|
+
option: "config",
|
145
|
+
alias: "c",
|
146
|
+
type: "path::String",
|
147
|
+
description: usingFlatConfig
|
148
|
+
? "Use this configuration instead of eslint.config.js"
|
149
|
+
: "Use this configuration, overriding .eslintrc.* config options if present"
|
150
|
+
},
|
151
|
+
envFlag,
|
152
|
+
extFlag,
|
153
|
+
{
|
154
|
+
option: "global",
|
155
|
+
type: "[String]",
|
156
|
+
description: "Define global variables"
|
157
|
+
},
|
158
|
+
{
|
159
|
+
option: "parser",
|
160
|
+
type: "String",
|
161
|
+
description: "Specify the parser to be used"
|
162
|
+
},
|
163
|
+
{
|
164
|
+
option: "parser-options",
|
165
|
+
type: "Object",
|
166
|
+
description: "Specify parser options"
|
167
|
+
},
|
168
|
+
resolvePluginsFlag,
|
169
|
+
{
|
170
|
+
heading: "Specifying rules and plugins"
|
171
|
+
},
|
172
|
+
{
|
173
|
+
option: "plugin",
|
174
|
+
type: "[String]",
|
175
|
+
description: "Specify plugins"
|
176
|
+
},
|
177
|
+
{
|
178
|
+
option: "rule",
|
179
|
+
type: "Object",
|
180
|
+
description: "Specify rules"
|
181
|
+
},
|
182
|
+
rulesDirFlag,
|
183
|
+
{
|
184
|
+
heading: "Fixing problems"
|
185
|
+
},
|
186
|
+
{
|
187
|
+
option: "fix",
|
188
|
+
type: "Boolean",
|
189
|
+
default: false,
|
190
|
+
description: "Automatically fix problems"
|
191
|
+
},
|
192
|
+
{
|
193
|
+
option: "fix-dry-run",
|
194
|
+
type: "Boolean",
|
195
|
+
default: false,
|
196
|
+
description: "Automatically fix problems without saving the changes to the file system"
|
197
|
+
},
|
198
|
+
{
|
199
|
+
option: "fix-type",
|
200
|
+
type: "Array",
|
201
|
+
description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)"
|
202
|
+
},
|
203
|
+
{
|
204
|
+
heading: "Ignoring files"
|
205
|
+
},
|
206
|
+
{
|
207
|
+
option: "ignore-path",
|
208
|
+
type: "path::String",
|
209
|
+
description: "Specify path of ignore file"
|
210
|
+
},
|
211
|
+
{
|
212
|
+
option: "ignore",
|
213
|
+
type: "Boolean",
|
214
|
+
default: "true",
|
215
|
+
description: "Disable use of ignore files and patterns"
|
216
|
+
},
|
217
|
+
{
|
218
|
+
option: "ignore-pattern",
|
219
|
+
type: "[String]",
|
220
|
+
description: "Pattern of files to ignore (in addition to those in .eslintignore)",
|
221
|
+
concatRepeatedArrays: [true, {
|
222
|
+
oneValuePerFlag: true
|
223
|
+
}]
|
224
|
+
},
|
225
|
+
{
|
226
|
+
heading: "Using stdin"
|
227
|
+
},
|
228
|
+
{
|
229
|
+
option: "stdin",
|
230
|
+
type: "Boolean",
|
231
|
+
default: "false",
|
232
|
+
description: "Lint code provided on <STDIN>"
|
233
|
+
},
|
234
|
+
{
|
235
|
+
option: "stdin-filename",
|
236
|
+
type: "String",
|
237
|
+
description: "Specify filename to process STDIN as"
|
238
|
+
},
|
239
|
+
{
|
240
|
+
heading: "Handling warnings"
|
241
|
+
},
|
242
|
+
{
|
243
|
+
option: "quiet",
|
244
|
+
type: "Boolean",
|
245
|
+
default: "false",
|
246
|
+
description: "Report errors only"
|
247
|
+
},
|
248
|
+
{
|
249
|
+
option: "max-warnings",
|
250
|
+
type: "Int",
|
251
|
+
default: "-1",
|
252
|
+
description: "Number of warnings to trigger nonzero exit code"
|
253
|
+
},
|
254
|
+
{
|
255
|
+
heading: "Output"
|
256
|
+
},
|
257
|
+
{
|
258
|
+
option: "output-file",
|
259
|
+
alias: "o",
|
260
|
+
type: "path::String",
|
261
|
+
description: "Specify file to write report to"
|
262
|
+
},
|
263
|
+
{
|
264
|
+
option: "format",
|
265
|
+
alias: "f",
|
266
|
+
type: "String",
|
267
|
+
default: "stylish",
|
268
|
+
description: "Use a specific output format"
|
269
|
+
},
|
270
|
+
{
|
271
|
+
option: "color",
|
272
|
+
type: "Boolean",
|
273
|
+
alias: "no-color",
|
274
|
+
description: "Force enabling/disabling of color"
|
275
|
+
},
|
276
|
+
{
|
277
|
+
heading: "Inline configuration comments"
|
278
|
+
},
|
279
|
+
{
|
280
|
+
option: "inline-config",
|
281
|
+
type: "Boolean",
|
282
|
+
default: "true",
|
283
|
+
description: "Prevent comments from changing config or rules"
|
284
|
+
},
|
285
|
+
{
|
286
|
+
option: "report-unused-disable-directives",
|
287
|
+
type: "Boolean",
|
288
|
+
default: void 0,
|
289
|
+
description: "Adds reported errors for unused eslint-disable directives"
|
290
|
+
},
|
291
|
+
{
|
292
|
+
heading: "Caching"
|
293
|
+
},
|
294
|
+
{
|
295
|
+
option: "cache",
|
296
|
+
type: "Boolean",
|
297
|
+
default: "false",
|
298
|
+
description: "Only check changed files"
|
299
|
+
},
|
300
|
+
{
|
301
|
+
option: "cache-file",
|
302
|
+
type: "path::String",
|
303
|
+
default: ".eslintcache",
|
304
|
+
description: "Path to the cache file. Deprecated: use --cache-location"
|
305
|
+
},
|
306
|
+
{
|
307
|
+
option: "cache-location",
|
308
|
+
type: "path::String",
|
309
|
+
description: "Path to the cache file or directory"
|
310
|
+
},
|
311
|
+
{
|
312
|
+
option: "cache-strategy",
|
313
|
+
dependsOn: ["cache"],
|
314
|
+
type: "String",
|
315
|
+
default: "metadata",
|
316
|
+
enum: ["metadata", "content"],
|
317
|
+
description: "Strategy to use for detecting changed files in the cache"
|
318
|
+
},
|
319
|
+
{
|
320
|
+
heading: "Miscellaneous"
|
321
|
+
},
|
322
|
+
{
|
323
|
+
option: "init",
|
324
|
+
type: "Boolean",
|
325
|
+
default: "false",
|
326
|
+
description: "Run config initialization wizard"
|
327
|
+
},
|
328
|
+
{
|
329
|
+
option: "env-info",
|
330
|
+
type: "Boolean",
|
331
|
+
default: "false",
|
332
|
+
description: "Output execution environment information"
|
333
|
+
},
|
334
|
+
{
|
335
|
+
option: "error-on-unmatched-pattern",
|
336
|
+
type: "Boolean",
|
337
|
+
default: "true",
|
338
|
+
description: "Prevent errors when pattern is unmatched"
|
339
|
+
},
|
340
|
+
{
|
341
|
+
option: "exit-on-fatal-error",
|
342
|
+
type: "Boolean",
|
343
|
+
default: "false",
|
344
|
+
description: "Exit with exit code 2 in case of fatal error"
|
345
|
+
},
|
346
|
+
{
|
347
|
+
option: "debug",
|
348
|
+
type: "Boolean",
|
349
|
+
default: false,
|
350
|
+
description: "Output debugging information"
|
351
|
+
},
|
352
|
+
{
|
353
|
+
option: "help",
|
354
|
+
alias: "h",
|
355
|
+
type: "Boolean",
|
356
|
+
description: "Show help"
|
357
|
+
},
|
358
|
+
{
|
359
|
+
option: "version",
|
360
|
+
alias: "v",
|
361
|
+
type: "Boolean",
|
362
|
+
description: "Output the version number"
|
363
|
+
},
|
364
|
+
{
|
365
|
+
option: "print-config",
|
366
|
+
type: "path::String",
|
367
|
+
description: "Print the configuration for the given file"
|
368
|
+
}
|
369
|
+
].filter(value => !!value)
|
370
|
+
});
|
371
|
+
};
|
@@ -28,10 +28,11 @@ function findReference(scope, node) {
|
|
28
28
|
const references = scope.references.filter(reference => reference.identifier.range[0] === node.range[0] &&
|
29
29
|
reference.identifier.range[1] === node.range[1]);
|
30
30
|
|
31
|
-
/* istanbul ignore else: correctly returns null */
|
32
31
|
if (references.length === 1) {
|
33
32
|
return references[0];
|
34
33
|
}
|
34
|
+
|
35
|
+
/* c8 ignore next */
|
35
36
|
return null;
|
36
37
|
|
37
38
|
}
|
@@ -18,8 +18,8 @@ const astUtils = require("./utils/ast-utils");
|
|
18
18
|
//------------------------------------------------------------------------------
|
19
19
|
// Rule Definition
|
20
20
|
//------------------------------------------------------------------------------
|
21
|
-
|
22
|
-
/*
|
21
|
+
// this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway.
|
22
|
+
/* c8 ignore next */
|
23
23
|
/** @type {import('../shared/types').Rule} */
|
24
24
|
module.exports = {
|
25
25
|
meta: {
|
@@ -212,10 +212,10 @@ module.exports = {
|
|
212
212
|
if (context.options[0] === "tab") {
|
213
213
|
indentSize = 1;
|
214
214
|
indentType = "tab";
|
215
|
-
} else /*
|
215
|
+
} else /* c8 ignore start */ if (typeof context.options[0] === "number") {
|
216
216
|
indentSize = context.options[0];
|
217
217
|
indentType = "space";
|
218
|
-
}
|
218
|
+
}/* c8 ignore stop */
|
219
219
|
|
220
220
|
if (context.options[1]) {
|
221
221
|
const opts = context.options[1];
|