eslint 8.20.0 → 8.23.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/bin/eslint.js +2 -4
- package/conf/globals.js +6 -1
- package/lib/cli.js +123 -29
- package/lib/config/default-config.js +16 -7
- package/lib/config/flat-config-array.js +94 -14
- package/lib/config/flat-config-helpers.js +9 -1
- package/lib/eslint/eslint-helpers.js +622 -0
- package/lib/eslint/flat-eslint.js +1176 -0
- package/lib/eslint/index.js +3 -1
- package/lib/linter/config-comment-parser.js +1 -2
- package/lib/linter/linter.js +18 -1
- package/lib/options.js +290 -242
- package/lib/rule-tester/flat-rule-tester.js +40 -37
- package/lib/rule-tester/rule-tester.js +43 -1
- package/lib/rules/key-spacing.js +4 -1
- package/lib/rules/lines-around-comment.js +11 -4
- package/lib/rules/no-fallthrough.js +8 -3
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-warning-comments.js +24 -5
- package/lib/rules/object-shorthand.js +15 -0
- package/lib/rules/sort-keys.js +43 -0
- package/lib/rules/utils/ast-utils.js +9 -3
- package/lib/shared/types.js +1 -1
- package/lib/unsupported-api.js +4 -0
- package/package.json +14 -9
package/lib/eslint/index.js
CHANGED
@@ -131,8 +131,7 @@ module.exports = class ConfigCommentParser {
|
|
131
131
|
|
132
132
|
const items = {};
|
133
133
|
|
134
|
-
|
135
|
-
string.replace(/\s*,\s*/gu, ",").split(/,+/u).forEach(name => {
|
134
|
+
string.split(",").forEach(name => {
|
136
135
|
const trimmedName = name.trim();
|
137
136
|
|
138
137
|
if (trimmedName) {
|
package/lib/linter/linter.js
CHANGED
@@ -1608,6 +1608,11 @@ class Linter {
|
|
1608
1608
|
...languageOptions.globals
|
1609
1609
|
};
|
1610
1610
|
|
1611
|
+
// double check that there is a parser to avoid mysterious error messages
|
1612
|
+
if (!languageOptions.parser) {
|
1613
|
+
throw new TypeError(`No parser specified for ${options.filename}`);
|
1614
|
+
}
|
1615
|
+
|
1611
1616
|
// Espree expects this information to be passed in
|
1612
1617
|
if (isEspree(languageOptions.parser)) {
|
1613
1618
|
const parserOptions = languageOptions.parserOptions;
|
@@ -1770,12 +1775,24 @@ class Linter {
|
|
1770
1775
|
debug("With flat config: %s", options.filename);
|
1771
1776
|
|
1772
1777
|
// we need a filename to match configs against
|
1773
|
-
const filename = options.filename || "
|
1778
|
+
const filename = options.filename || "__placeholder__.js";
|
1774
1779
|
|
1775
1780
|
// Store the config array in order to get plugin envs and rules later.
|
1776
1781
|
internalSlotsMap.get(this).lastConfigArray = configArray;
|
1777
1782
|
const config = configArray.getConfig(filename);
|
1778
1783
|
|
1784
|
+
if (!config) {
|
1785
|
+
return [
|
1786
|
+
{
|
1787
|
+
ruleId: null,
|
1788
|
+
severity: 1,
|
1789
|
+
message: `No matching configuration found for ${filename}.`,
|
1790
|
+
line: 0,
|
1791
|
+
column: 0
|
1792
|
+
}
|
1793
|
+
];
|
1794
|
+
}
|
1795
|
+
|
1779
1796
|
// Verify.
|
1780
1797
|
if (config.processor) {
|
1781
1798
|
debug("Apply the processor: %o", config.processor);
|
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
|
+
};
|