eslint 9.8.0 → 9.9.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/README.md CHANGED
@@ -295,7 +295,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
295
295
  <!--sponsorsstart-->
296
296
  <h3>Platinum Sponsors</h3>
297
297
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
298
- <p><a href="#"><img src="https://images.opencollective.com/guest-bf377e88/avatar.png" alt="Eli Schleifer" height="96"></a> <a href="https://engineering.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a></p><h3>Silver Sponsors</h3>
298
+ <p><a href="#"><img src="https://images.opencollective.com/guest-bf377e88/avatar.png" alt="Eli Schleifer" height="96"></a></p><h3>Silver Sponsors</h3>
299
299
  <p><a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="64"></a> <a href="https://www.workleap.com"><img src="https://avatars.githubusercontent.com/u/53535748?u=d1e55d7661d724bf2281c1bfd33cb8f99fe2465f&v=4" alt="Workleap" height="64"></a></p><h3>Bronze Sponsors</h3>
300
300
  <p><a href="https://www.notion.so"><img src="https://images.opencollective.com/notion/bf3b117/logo.png" alt="notion" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a> <a href="https://usenextbase.com"><img src="https://avatars.githubusercontent.com/u/145838380?v=4" alt="Nextbase Starter Kit" height="32"></a></p>
301
301
  <!--sponsorsend-->
package/lib/cli.js CHANGED
@@ -340,16 +340,17 @@ const cli = {
340
340
  /**
341
341
  * Calculates the command string for the --inspect-config operation.
342
342
  * @param {string} configFile The path to the config file to inspect.
343
+ * @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
343
344
  * @returns {Promise<string>} The command string to execute.
344
345
  */
345
- async calculateInspectConfigFlags(configFile) {
346
+ async calculateInspectConfigFlags(configFile, hasUnstableTSConfigFlag) {
346
347
 
347
348
  // find the config file
348
349
  const {
349
350
  configFilePath,
350
351
  basePath,
351
352
  error
352
- } = await locateConfigFileToUse({ cwd: process.cwd(), configFile });
353
+ } = await locateConfigFileToUse({ cwd: process.cwd(), configFile }, hasUnstableTSConfigFlag);
353
354
 
354
355
  if (error) {
355
356
  throw error;
@@ -454,7 +455,7 @@ const cli = {
454
455
  try {
455
456
  const flatOptions = await translateOptions(options, "flat");
456
457
  const spawn = require("cross-spawn");
457
- const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile);
458
+ const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile, flatOptions.flags ? flatOptions.flags.includes("unstable_ts_config") : false);
458
459
 
459
460
  spawn.sync("npx", ["@eslint/config-inspector@latest", ...flags], { encoding: "utf8", stdio: "inherit" });
460
461
  } catch (error) {
@@ -63,6 +63,8 @@ const { Retrier } = require("@humanwhocodes/retry");
63
63
  /** @typedef {import("../shared/types").RuleConf} RuleConf */
64
64
  /** @typedef {import("../shared/types").Rule} Rule */
65
65
  /** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */
66
+ /** @typedef {import('../cli-engine/cli-engine').CLIEngine} CLIEngine */
67
+ /** @typedef {import('./legacy-eslint').CLIEngineLintReport} CLIEngineLintReport */
66
68
 
67
69
  /**
68
70
  * The options with which to configure the ESLint instance.
@@ -86,7 +88,7 @@ const { Retrier } = require("@humanwhocodes/retry");
86
88
  * when a string.
87
89
  * @property {Record<string,Plugin>} [plugins] An array of plugin implementations.
88
90
  * @property {boolean} [stats] True enables added statistics on lint results.
89
- * @property {boolean} warnIgnored Show warnings when the file list includes ignored files
91
+ * @property {boolean} [warnIgnored] Show warnings when the file list includes ignored files
90
92
  * @property {boolean} [passOnNoPatterns=false] When set to true, missing patterns cause
91
93
  * the linting operation to short circuit and not report any failures.
92
94
  */
@@ -100,8 +102,18 @@ const FLAT_CONFIG_FILENAMES = [
100
102
  "eslint.config.mjs",
101
103
  "eslint.config.cjs"
102
104
  ];
105
+ const FLAT_CONFIG_FILENAMES_WITH_TS = [
106
+ ...FLAT_CONFIG_FILENAMES,
107
+ "eslint.config.ts",
108
+ "eslint.config.mts",
109
+ "eslint.config.cts"
110
+ ];
103
111
  const debug = require("debug")("eslint:eslint");
104
112
  const privateMembers = new WeakMap();
113
+
114
+ /**
115
+ * @type {Map<string, string>}
116
+ */
105
117
  const importedConfigFileModificationTime = new Map();
106
118
  const removedFormatters = new Set([
107
119
  "checkstyle",
@@ -262,28 +274,59 @@ function compareResultsByFilePath(a, b) {
262
274
  * Searches from the current working directory up until finding the
263
275
  * given flat config filename.
264
276
  * @param {string} cwd The current working directory to search from.
277
+ * @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
265
278
  * @returns {Promise<string|undefined>} The filename if found or `undefined` if not.
266
279
  */
267
- function findFlatConfigFile(cwd) {
280
+ function findFlatConfigFile(cwd, hasUnstableTSConfigFlag) {
281
+ const filenames = hasUnstableTSConfigFlag ? FLAT_CONFIG_FILENAMES_WITH_TS : FLAT_CONFIG_FILENAMES;
282
+
268
283
  return findUp(
269
- FLAT_CONFIG_FILENAMES,
284
+ filenames,
270
285
  { cwd }
271
286
  );
272
287
  }
273
288
 
289
+ /**
290
+ * Check if the file is a TypeScript file.
291
+ * @param {string} filePath The file path to check.
292
+ * @returns {boolean} `true` if the file is a TypeScript file, `false` if it's not.
293
+ */
294
+ function isFileTS(filePath) {
295
+ const fileExtension = path.extname(filePath);
296
+
297
+ return /^\.[mc]?ts$/u.test(fileExtension);
298
+ }
299
+
300
+ /**
301
+ * Check if ESLint is running in Bun.
302
+ * @returns {boolean} `true` if the ESLint is running Bun, `false` if it's not.
303
+ */
304
+ function isRunningInBun() {
305
+ return !!globalThis.Bun;
306
+ }
307
+
308
+ /**
309
+ * Check if ESLint is running in Deno.
310
+ * @returns {boolean} `true` if the ESLint is running in Deno, `false` if it's not.
311
+ */
312
+ function isRunningInDeno() {
313
+ return !!globalThis.Deno;
314
+ }
315
+
274
316
  /**
275
317
  * Load the config array from the given filename.
276
318
  * @param {string} filePath The filename to load from.
319
+ * @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
277
320
  * @returns {Promise<any>} The config loaded from the config file.
278
321
  */
279
- async function loadFlatConfigFile(filePath) {
322
+ async function loadFlatConfigFile(filePath, hasUnstableTSConfigFlag) {
280
323
  debug(`Loading config from ${filePath}`);
281
324
 
282
325
  const fileURL = pathToFileURL(filePath);
283
326
 
284
327
  debug(`Config file URL is ${fileURL}`);
285
328
 
286
- const mtime = (await fs.stat(filePath)).mtime.getTime();
329
+ const mtime = (await fs.stat(filePath)).mtime.getTime().toString();
287
330
 
288
331
  /*
289
332
  * Append a query with the config file's modification time (`mtime`) in order
@@ -314,7 +357,37 @@ async function loadFlatConfigFile(filePath) {
314
357
  delete require.cache[filePath];
315
358
  }
316
359
 
317
- const config = (await import(fileURL)).default;
360
+ const isTS = isFileTS(filePath) && hasUnstableTSConfigFlag;
361
+
362
+ const isBun = isRunningInBun();
363
+
364
+ const isDeno = isRunningInDeno();
365
+
366
+ if (isTS && !isDeno && !isBun) {
367
+
368
+ const createJiti = await import("jiti").then(jitiModule => jitiModule.default, () => {
369
+ throw new Error("The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.");
370
+ });
371
+
372
+ /*
373
+ * Disabling `moduleCache` allows us to reload a
374
+ * config file when the last modified timestamp changes.
375
+ */
376
+
377
+ const jiti = createJiti(__filename, { moduleCache: false });
378
+
379
+ if (typeof jiti?.import !== "function") {
380
+ throw new Error("You are using an outdated version of the 'jiti' library. Please update to the latest version of 'jiti' to ensure compatibility and access to the latest features.");
381
+ }
382
+
383
+ const config = await jiti.import(fileURL.href);
384
+
385
+ importedConfigFileModificationTime.set(filePath, mtime);
386
+
387
+ return config?.default ?? config;
388
+ }
389
+
390
+ const config = (await import(fileURL.href)).default;
318
391
 
319
392
  importedConfigFileModificationTime.set(filePath, mtime);
320
393
 
@@ -326,11 +399,12 @@ async function loadFlatConfigFile(filePath) {
326
399
  * override config file was passed, and if so, using it; otherwise, as long
327
400
  * as override config file is not explicitly set to `false`, it will search
328
401
  * upwards from the cwd for a file named `eslint.config.js`.
329
- * @param {import("./eslint").ESLintOptions} options The ESLint instance options.
330
- * @returns {{configFilePath:string|undefined,basePath:string,error:Error|null}} Location information for
402
+ * @param {ESLintOptions} options The ESLint instance options.
403
+ * @param {boolean} hasUnstableTSConfigFlag `true` if the `unstable_ts_config` flag is enabled, `false` if it's not.
404
+ * @returns {Promise<{configFilePath:string|undefined;basePath:string;error:Error|null}>} Location information for
331
405
  * the config file.
332
406
  */
333
- async function locateConfigFileToUse({ configFile, cwd }) {
407
+ async function locateConfigFileToUse({ configFile, cwd }, hasUnstableTSConfigFlag) {
334
408
 
335
409
  // determine where to load config file from
336
410
  let configFilePath;
@@ -342,7 +416,7 @@ async function locateConfigFileToUse({ configFile, cwd }) {
342
416
  configFilePath = path.resolve(cwd, configFile);
343
417
  } else if (configFile !== false) {
344
418
  debug("Searching for eslint.config.js");
345
- configFilePath = await findFlatConfigFile(cwd);
419
+ configFilePath = await findFlatConfigFile(cwd, hasUnstableTSConfigFlag);
346
420
 
347
421
  if (configFilePath) {
348
422
  basePath = path.resolve(path.dirname(configFilePath));
@@ -364,8 +438,8 @@ async function locateConfigFileToUse({ configFile, cwd }) {
364
438
  /**
365
439
  * Calculates the config array for this run based on inputs.
366
440
  * @param {ESLint} eslint The instance to create the config array for.
367
- * @param {import("./eslint").ESLintOptions} options The ESLint instance options.
368
- * @returns {FlatConfigArray} The config array for `eslint``.
441
+ * @param {ESLintOptions} options The ESLint instance options.
442
+ * @returns {Promise<typeof FlatConfigArray>} The config array for `eslint``.
369
443
  */
370
444
  async function calculateConfigArray(eslint, {
371
445
  cwd,
@@ -383,7 +457,9 @@ async function calculateConfigArray(eslint, {
383
457
  return slots.configs;
384
458
  }
385
459
 
386
- const { configFilePath, basePath, error } = await locateConfigFileToUse({ configFile, cwd });
460
+ const hasUnstableTSConfigFlag = eslint.hasFlag("unstable_ts_config");
461
+
462
+ const { configFilePath, basePath, error } = await locateConfigFileToUse({ configFile, cwd }, hasUnstableTSConfigFlag);
387
463
 
388
464
  // config file is required to calculate config
389
465
  if (error) {
@@ -394,7 +470,7 @@ async function calculateConfigArray(eslint, {
394
470
 
395
471
  // load config file
396
472
  if (configFilePath) {
397
- const fileConfig = await loadFlatConfigFile(configFilePath);
473
+ const fileConfig = await loadFlatConfigFile(configFilePath, hasUnstableTSConfigFlag);
398
474
 
399
475
  if (Array.isArray(fileConfig)) {
400
476
  configs.push(...fileConfig);
@@ -1144,7 +1220,7 @@ class ESLint {
1144
1220
 
1145
1221
  /**
1146
1222
  * The main formatter method.
1147
- * @param {LintResults[]} results The lint results to format.
1223
+ * @param {LintResult[]} results The lint results to format.
1148
1224
  * @param {ResultsMeta} resultsMeta Warning count and max threshold.
1149
1225
  * @returns {string} The formatted lint results.
1150
1226
  */
@@ -1190,12 +1266,12 @@ class ESLint {
1190
1266
  /**
1191
1267
  * Finds the config file being used by this instance based on the options
1192
1268
  * passed to the constructor.
1193
- * @returns {string|undefined} The path to the config file being used or
1269
+ * @returns {Promise<string|undefined>} The path to the config file being used or
1194
1270
  * `undefined` if no config file is being used.
1195
1271
  */
1196
1272
  async findConfigFile() {
1197
1273
  const options = privateMembers.get(this).options;
1198
- const { configFilePath } = await locateConfigFileToUse(options);
1274
+ const { configFilePath } = await locateConfigFileToUse(options, this.hasFlag("unstable_ts_config"));
1199
1275
 
1200
1276
  return configFilePath;
1201
1277
  }
@@ -918,7 +918,7 @@ class SourceCode extends TokenStore {
918
918
  }
919
919
 
920
920
  /**
921
- * Returns the locatin of the given node or token.
921
+ * Returns the location of the given node or token.
922
922
  * @param {ASTNode|Token} nodeOrToken The node or token to get the location of.
923
923
  * @returns {SourceLocation} The location of the node or token.
924
924
  */
@@ -42,8 +42,11 @@ module.exports = {
42
42
  schema: [],
43
43
 
44
44
  messages: {
45
- missingAwait: "{{name}} has no 'await' expression."
46
- }
45
+ missingAwait: "{{name}} has no 'await' expression.",
46
+ removeAsync: "Remove 'async'."
47
+ },
48
+
49
+ hasSuggestions: true
47
50
  },
48
51
 
49
52
  create(context) {
@@ -69,6 +72,33 @@ module.exports = {
69
72
  */
70
73
  function exitFunction(node) {
71
74
  if (!node.generator && node.async && !scopeInfo.hasAwait && !astUtils.isEmptyFunction(node)) {
75
+
76
+ /*
77
+ * If the function belongs to a method definition or
78
+ * property, then the function's range may not include the
79
+ * `async` keyword and we should look at the parent instead.
80
+ */
81
+ const nodeWithAsyncKeyword =
82
+ (node.parent.type === "MethodDefinition" && node.parent.value === node) ||
83
+ (node.parent.type === "Property" && node.parent.method && node.parent.value === node)
84
+ ? node.parent
85
+ : node;
86
+
87
+ const asyncToken = sourceCode.getFirstToken(nodeWithAsyncKeyword, token => token.value === "async");
88
+ const asyncRange = [asyncToken.range[0], sourceCode.getTokenAfter(asyncToken, { includeComments: true }).range[0]];
89
+
90
+ /*
91
+ * Removing the `async` keyword can cause parsing errors if the current
92
+ * statement is relying on automatic semicolon insertion. If ASI is currently
93
+ * being used, then we should replace the `async` keyword with a semicolon.
94
+ */
95
+ const nextToken = sourceCode.getTokenAfter(asyncToken);
96
+ const addSemiColon =
97
+ nextToken.type === "Punctuator" &&
98
+ (nextToken.value === "[" || nextToken.value === "(") &&
99
+ (nodeWithAsyncKeyword.type === "MethodDefinition" || astUtils.isStartOfExpressionStatement(nodeWithAsyncKeyword)) &&
100
+ astUtils.needsPrecedingSemicolon(sourceCode, nodeWithAsyncKeyword);
101
+
72
102
  context.report({
73
103
  node,
74
104
  loc: astUtils.getFunctionHeadLoc(node, sourceCode),
@@ -77,7 +107,11 @@ module.exports = {
77
107
  name: capitalizeFirstLetter(
78
108
  astUtils.getFunctionNameWithKind(node)
79
109
  )
80
- }
110
+ },
111
+ suggest: [{
112
+ messageId: "removeAsync",
113
+ fix: fixer => fixer.replaceTextRange(asyncRange, addSemiColon ? ";" : "")
114
+ }]
81
115
  });
82
116
  }
83
117
 
@@ -1042,11 +1042,12 @@ function isStartOfExpressionStatement(node) {
1042
1042
 
1043
1043
  /**
1044
1044
  * Determines whether an opening parenthesis `(`, bracket `[` or backtick ``` ` ``` needs to be preceded by a semicolon.
1045
- * This opening parenthesis or bracket should be at the start of an `ExpressionStatement` or at the start of the body of an `ArrowFunctionExpression`.
1045
+ * This opening parenthesis or bracket should be at the start of an `ExpressionStatement`, a `MethodDefinition` or at
1046
+ * the start of the body of an `ArrowFunctionExpression`.
1046
1047
  * @type {(sourceCode: SourceCode, node: ASTNode) => boolean}
1047
1048
  * @param {SourceCode} sourceCode The source code object.
1048
1049
  * @param {ASTNode} node A node at the position where an opening parenthesis or bracket will be inserted.
1049
- * @returns {boolean} Whether a semicolon is required before the opening parenthesis or braket.
1050
+ * @returns {boolean} Whether a semicolon is required before the opening parenthesis or bracket.
1050
1051
  */
1051
1052
  let needsPrecedingSemicolon;
1052
1053
 
@@ -1106,7 +1107,7 @@ let needsPrecedingSemicolon;
1106
1107
 
1107
1108
  if (isClosingBraceToken(prevToken)) {
1108
1109
  return (
1109
- prevNode.type === "BlockStatement" && prevNode.parent.type === "FunctionExpression" ||
1110
+ prevNode.type === "BlockStatement" && prevNode.parent.type === "FunctionExpression" && prevNode.parent.parent.type !== "MethodDefinition" ||
1110
1111
  prevNode.type === "ClassBody" && prevNode.parent.type === "ClassExpression" ||
1111
1112
  prevNode.type === "ObjectExpression"
1112
1113
  );
@@ -9,7 +9,8 @@
9
9
  * @type {Map<string, string>}
10
10
  */
11
11
  const activeFlags = new Map([
12
- ["test_only", "Used only for testing."]
12
+ ["test_only", "Used only for testing."],
13
+ ["unstable_ts_config", "Enable TypeScript configuration files."]
13
14
  ]);
14
15
 
15
16
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "9.8.0",
3
+ "version": "9.9.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -70,7 +70,7 @@
70
70
  "@eslint-community/regexpp": "^4.11.0",
71
71
  "@eslint/config-array": "^0.17.1",
72
72
  "@eslint/eslintrc": "^3.1.0",
73
- "@eslint/js": "9.8.0",
73
+ "@eslint/js": "9.9.0",
74
74
  "@humanwhocodes/module-importer": "^1.0.1",
75
75
  "@humanwhocodes/retry": "^0.3.0",
76
76
  "@nodelib/fs.walk": "^1.2.8",
@@ -104,14 +104,14 @@
104
104
  "devDependencies": {
105
105
  "@babel/core": "^7.4.3",
106
106
  "@babel/preset-env": "^7.4.3",
107
- "@eslint/core": "^0.2.0",
108
- "@eslint/json": "^0.2.0",
107
+ "@eslint/core": "^0.3.0",
108
+ "@eslint/json": "^0.3.0",
109
109
  "@types/estree": "^1.0.5",
110
110
  "@types/node": "^20.11.5",
111
- "@wdio/browser-runner": "^8.38.3",
112
- "@wdio/cli": "^8.38.2",
113
- "@wdio/concise-reporter": "^8.38.2",
114
- "@wdio/mocha-framework": "^8.38.2",
111
+ "@wdio/browser-runner": "^8.40.1",
112
+ "@wdio/cli": "^8.40.0",
113
+ "@wdio/concise-reporter": "^8.39.0",
114
+ "@wdio/mocha-framework": "^8.40.0",
115
115
  "babel-loader": "^8.0.5",
116
116
  "c8": "^7.12.0",
117
117
  "chai": "^4.0.1",
@@ -132,6 +132,7 @@
132
132
  "globals": "^15.0.0",
133
133
  "got": "^11.8.3",
134
134
  "gray-matter": "^4.0.3",
135
+ "jiti": "^1.21.6",
135
136
  "js-yaml": "^4.1.0",
136
137
  "knip": "^5.21.0",
137
138
  "lint-staged": "^11.0.0",
@@ -165,6 +166,14 @@
165
166
  "webpack-cli": "^4.5.0",
166
167
  "yorkie": "^2.0.0"
167
168
  },
169
+ "peerDependencies": {
170
+ "jiti": "*"
171
+ },
172
+ "peerDependenciesMeta": {
173
+ "jiti": {
174
+ "optional": true
175
+ }
176
+ },
168
177
  "keywords": [
169
178
  "ast",
170
179
  "lint",