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.
Files changed (40) hide show
  1. package/bin/eslint.js +2 -4
  2. package/conf/globals.js +6 -1
  3. package/lib/cli-engine/file-enumerator.js +4 -2
  4. package/lib/cli.js +123 -29
  5. package/lib/config/flat-config-array.js +53 -12
  6. package/lib/eslint/eslint-helpers.js +39 -16
  7. package/lib/eslint/flat-eslint.js +29 -17
  8. package/lib/linter/code-path-analysis/code-path-segment.js +2 -2
  9. package/lib/linter/code-path-analysis/code-path-state.js +7 -7
  10. package/lib/linter/code-path-analysis/debug-helpers.js +3 -3
  11. package/lib/linter/code-path-analysis/id-generator.js +2 -2
  12. package/lib/linter/config-comment-parser.js +1 -2
  13. package/lib/linter/timing.js +4 -4
  14. package/lib/options.js +290 -242
  15. package/lib/rule-tester/flat-rule-tester.js +1 -1
  16. package/lib/rule-tester/rule-tester.js +1 -1
  17. package/lib/rules/array-callback-return.js +1 -1
  18. package/lib/rules/global-require.js +2 -1
  19. package/lib/rules/indent-legacy.js +4 -4
  20. package/lib/rules/indent.js +23 -15
  21. package/lib/rules/new-cap.js +2 -2
  22. package/lib/rules/no-extra-boolean-cast.js +1 -1
  23. package/lib/rules/no-extra-parens.js +2 -2
  24. package/lib/rules/no-fallthrough.js +8 -3
  25. package/lib/rules/no-labels.js +1 -1
  26. package/lib/rules/no-lone-blocks.js +1 -1
  27. package/lib/rules/no-useless-computed-key.js +1 -1
  28. package/lib/rules/no-var.js +1 -1
  29. package/lib/rules/no-warning-comments.js +24 -5
  30. package/lib/rules/object-shorthand.js +15 -0
  31. package/lib/rules/padded-blocks.js +1 -1
  32. package/lib/rules/prefer-arrow-callback.js +2 -2
  33. package/lib/rules/prefer-const.js +13 -1
  34. package/lib/rules/prefer-rest-params.js +1 -1
  35. package/lib/rules/require-yield.js +0 -1
  36. package/lib/rules/utils/ast-utils.js +10 -4
  37. package/lib/shared/logging.js +1 -1
  38. package/lib/shared/types.js +1 -1
  39. package/lib/source-code/token-store/cursor.js +1 -1
  40. 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
- module.exports = optionator({
67
- prepend: "eslint [options] file.js [file.js] [dir]",
68
- defaults: {
69
- concatRepeatedArrays: true,
70
- mergeRepeatedObjects: true
71
- },
72
- options: [
73
- {
74
- heading: "Basic configuration"
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
- option: "config",
84
- alias: "c",
85
- type: "path::String",
86
- description: "Use this configuration, overriding .eslintrc.* config options if present"
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
- option: "global",
100
- type: "[String]",
101
- description: "Define global variables"
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
- heading: "Specifying rules and plugins"
120
- },
121
- {
122
- option: "plugin",
123
- type: "[String]",
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
- heading: "Fixing problems"
138
- },
139
- {
140
- option: "fix",
141
- type: "Boolean",
142
- default: false,
143
- description: "Automatically fix problems"
144
- },
145
- {
146
- option: "fix-dry-run",
147
- type: "Boolean",
148
- default: false,
149
- description: "Automatically fix problems without saving the changes to the file system"
150
- },
151
- {
152
- option: "fix-type",
153
- type: "Array",
154
- description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)"
155
- },
156
- {
157
- heading: "Ignoring files"
158
- },
159
- {
160
- option: "ignore-path",
161
- type: "path::String",
162
- description: "Specify path of ignore file"
163
- },
164
- {
165
- option: "ignore",
166
- type: "Boolean",
167
- default: "true",
168
- description: "Disable use of ignore files and patterns"
169
- },
170
- {
171
- option: "ignore-pattern",
172
- type: "[String]",
173
- description: "Pattern of files to ignore (in addition to those in .eslintignore)",
174
- concatRepeatedArrays: [true, {
175
- oneValuePerFlag: true
176
- }]
177
- },
178
- {
179
- heading: "Using stdin"
180
- },
181
- {
182
- option: "stdin",
183
- type: "Boolean",
184
- default: "false",
185
- description: "Lint code provided on <STDIN>"
186
- },
187
- {
188
- option: "stdin-filename",
189
- type: "String",
190
- description: "Specify filename to process STDIN as"
191
- },
192
- {
193
- heading: "Handling warnings"
194
- },
195
- {
196
- option: "quiet",
197
- type: "Boolean",
198
- default: "false",
199
- description: "Report errors only"
200
- },
201
- {
202
- option: "max-warnings",
203
- type: "Int",
204
- default: "-1",
205
- description: "Number of warnings to trigger nonzero exit code"
206
- },
207
- {
208
- heading: "Output"
209
- },
210
- {
211
- option: "output-file",
212
- alias: "o",
213
- type: "path::String",
214
- description: "Specify file to write report to"
215
- },
216
- {
217
- option: "format",
218
- alias: "f",
219
- type: "String",
220
- default: "stylish",
221
- description: "Use a specific output format"
222
- },
223
- {
224
- option: "color",
225
- type: "Boolean",
226
- alias: "no-color",
227
- description: "Force enabling/disabling of color"
228
- },
229
- {
230
- heading: "Inline configuration comments"
231
- },
232
- {
233
- option: "inline-config",
234
- type: "Boolean",
235
- default: "true",
236
- description: "Prevent comments from changing config or rules"
237
- },
238
- {
239
- option: "report-unused-disable-directives",
240
- type: "Boolean",
241
- default: void 0,
242
- description: "Adds reported errors for unused eslint-disable directives"
243
- },
244
- {
245
- heading: "Caching"
246
- },
247
- {
248
- option: "cache",
249
- type: "Boolean",
250
- default: "false",
251
- description: "Only check changed files"
252
- },
253
- {
254
- option: "cache-file",
255
- type: "path::String",
256
- default: ".eslintcache",
257
- description: "Path to the cache file. Deprecated: use --cache-location"
258
- },
259
- {
260
- option: "cache-location",
261
- type: "path::String",
262
- description: "Path to the cache file or directory"
263
- },
264
- {
265
- option: "cache-strategy",
266
- dependsOn: ["cache"],
267
- type: "String",
268
- default: "metadata",
269
- enum: ["metadata", "content"],
270
- description: "Strategy to use for detecting changed files in the cache"
271
- },
272
- {
273
- heading: "Miscellaneous"
274
- },
275
- {
276
- option: "init",
277
- type: "Boolean",
278
- default: "false",
279
- description: "Run config initialization wizard"
280
- },
281
- {
282
- option: "env-info",
283
- type: "Boolean",
284
- default: "false",
285
- description: "Output execution environment information"
286
- },
287
- {
288
- option: "error-on-unmatched-pattern",
289
- type: "Boolean",
290
- default: "true",
291
- description: "Prevent errors when pattern is unmatched"
292
- },
293
- {
294
- option: "exit-on-fatal-error",
295
- type: "Boolean",
296
- default: "false",
297
- description: "Exit with exit code 2 in case of fatal error"
298
- },
299
- {
300
- option: "debug",
301
- type: "Boolean",
302
- default: false,
303
- description: "Output debugging information"
304
- },
305
- {
306
- option: "help",
307
- alias: "h",
308
- type: "Boolean",
309
- description: "Show help"
310
- },
311
- {
312
- option: "version",
313
- alias: "v",
314
- type: "Boolean",
315
- description: "Output the version number"
316
- },
317
- {
318
- option: "print-config",
319
- type: "path::String",
320
- description: "Print the configuration for the given file"
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
+ };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- /* eslint-env mocha -- Mocha/Jest wrapper */
7
+ /* globals describe, it -- Mocha globals */
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Requirements
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- /* eslint-env mocha -- Mocha wrapper */
7
+ /* globals describe, it -- Mocha globals */
8
8
 
9
9
  /*
10
10
  * This is a wrapper around mocha to allow for DRY unittests for eslint
@@ -125,7 +125,7 @@ function getArrayMethodName(node) {
125
125
  }
126
126
  }
127
127
 
128
- /* istanbul ignore next: unreachable */
128
+ /* c8 ignore next */
129
129
  return null;
130
130
  }
131
131
 
@@ -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
- /* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */
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 /* istanbul ignore else : this will be caught by options validation */ if (typeof context.options[0] === "number") {
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];