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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  const { ESLint } = require("./eslint");
4
+ const { FlatESLint } = require("./flat-eslint");
4
5
 
5
6
  module.exports = {
6
- ESLint
7
+ ESLint,
8
+ FlatESLint
7
9
  };
@@ -131,8 +131,7 @@ module.exports = class ConfigCommentParser {
131
131
 
132
132
  const items = {};
133
133
 
134
- // Collapse whitespace around commas
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) {
@@ -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 || "<input>";
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
- 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
+ };