eslint 9.8.0 → 9.9.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/README.md CHANGED
@@ -21,25 +21,26 @@
21
21
 
22
22
  ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
23
23
 
24
- * ESLint uses [Espree](https://github.com/eslint/espree) for JavaScript parsing.
24
+ * ESLint uses [Espree](https://github.com/eslint/js/tree/main/packages/espree) for JavaScript parsing.
25
25
  * ESLint uses an AST to evaluate patterns in code.
26
26
  * ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
27
27
 
28
28
  ## Table of Contents
29
29
 
30
30
  1. [Installation and Usage](#installation-and-usage)
31
- 2. [Configuration](#configuration)
32
- 3. [Code of Conduct](#code-of-conduct)
33
- 4. [Filing Issues](#filing-issues)
34
- 5. [Frequently Asked Questions](#frequently-asked-questions)
35
- 6. [Releases](#releases)
36
- 7. [Security Policy](#security-policy)
37
- 8. [Semantic Versioning Policy](#semantic-versioning-policy)
38
- 9. [Stylistic Rule Updates](#stylistic-rule-updates)
39
- 10. [License](#license)
40
- 11. [Team](#team)
41
- 12. [Sponsors](#sponsors)
42
- 13. [Technology Sponsors](#technology-sponsors) <!-- markdownlint-disable-line MD051 -->
31
+ 1. [Configuration](#configuration)
32
+ 1. [Version Support](#version-support)
33
+ 1. [Code of Conduct](#code-of-conduct)
34
+ 1. [Filing Issues](#filing-issues)
35
+ 1. [Frequently Asked Questions](#frequently-asked-questions)
36
+ 1. [Releases](#releases)
37
+ 1. [Security Policy](#security-policy)
38
+ 1. [Semantic Versioning Policy](#semantic-versioning-policy)
39
+ 1. [Stylistic Rule Updates](#stylistic-rule-updates)
40
+ 1. [License](#license)
41
+ 1. [Team](#team)
42
+ 1. [Sponsors](#sponsors)
43
+ 1. [Technology Sponsors](#technology-sponsors) <!-- markdownlint-disable-line MD051 -->
43
44
 
44
45
  ## Installation and Usage
45
46
 
@@ -54,19 +55,26 @@ npm init @eslint/config@latest
54
55
  After that, you can run ESLint on any file or directory like this:
55
56
 
56
57
  ```shell
57
- ./node_modules/.bin/eslint yourfile.js
58
+ npx eslint yourfile.js
58
59
  ```
59
60
 
60
61
  ## Configuration
61
62
 
62
- After running `npm init @eslint/config`, you'll have an `eslint.config.js` (or `eslint.config.mjs`) file in your directory. In it, you'll see some rules configured like this:
63
+ You can configure rules in your `eslint.config.js` files as in this example:
63
64
 
64
65
  ```js
65
- import pluginJs from "@eslint/js";
66
- export default [ pluginJs.configs.recommended, ];
66
+ export default [
67
+ {
68
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
69
+ rules: {
70
+ "prefer-const": "warn",
71
+ "no-constant-binary-expression": "error"
72
+ }
73
+ }
74
+ ];
67
75
  ```
68
76
 
69
- The names `"semi"` and `"quotes"` are the names of [rules](https://eslint.org/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
77
+ The names `"prefer-const"` and `"no-constant-binary-expression"` are the names of [rules](https://eslint.org/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
70
78
 
71
79
  * `"off"` or `0` - turn the rule off
72
80
  * `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
@@ -74,9 +82,17 @@ The names `"semi"` and `"quotes"` are the names of [rules](https://eslint.org/do
74
82
 
75
83
  The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](https://eslint.org/docs/latest/use/configure)).
76
84
 
85
+ ## Version Support
86
+
87
+ The ESLint team provides ongoing support for the current version and six months of limited support for the previous version. Limited support includes critical bug fixes, security issues, and compatibility issues only.
88
+
89
+ ESLint offers commercial support for both current and previous versions through our partners, [Tidelift][tidelift] and [HeroDevs][herodevs].
90
+
91
+ See [Version Support](https://eslint.org/version-support) for more details.
92
+
77
93
  ## Code of Conduct
78
94
 
79
- ESLint adheres to the [JS Foundation Code of Conduct](https://eslint.org/conduct).
95
+ ESLint adheres to the [OpenJS Foundation Code of Conduct](https://eslint.org/conduct).
80
96
 
81
97
  ## Filing Issues
82
98
 
@@ -89,28 +105,14 @@ Before filing an issue, please be sure to read the guidelines for what you're re
89
105
 
90
106
  ## Frequently Asked Questions
91
107
 
92
- ### I'm using JSCS, should I migrate to ESLint?
93
-
94
- Yes. [JSCS has reached end of life](https://eslint.org/blog/2016/07/jscs-end-of-life) and is no longer supported.
95
-
96
- We have prepared a [migration guide](https://eslint.org/docs/latest/use/migrating-from-jscs) to help you convert your JSCS settings to an ESLint configuration.
108
+ ### Does ESLint support JSX?
97
109
 
98
- We are now at or near 100% compatibility with JSCS. If you try ESLint and believe we are not yet compatible with a JSCS rule/configuration, please create an issue (mentioning that it is a JSCS compatibility issue) and we will evaluate it as per our normal process.
110
+ Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/latest/use/configure)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
99
111
 
100
112
  ### Does Prettier replace ESLint?
101
113
 
102
114
  No, ESLint and Prettier have different jobs: ESLint is a linter (looking for problematic patterns) and Prettier is a code formatter. Using both tools is common, refer to [Prettier's documentation](https://prettier.io/docs/en/install#eslint-and-other-linters) to learn how to configure them to work well with each other.
103
115
 
104
- ### Why can't ESLint find my plugins?
105
-
106
- * Make sure your plugins (and ESLint) are both in your project's `package.json` as devDependencies (or dependencies, if your project uses ESLint at runtime).
107
- * Make sure you have run `npm install` and all your dependencies are installed.
108
- * Make sure your plugins' peerDependencies have been installed as well. You can use `npm view eslint-plugin-myplugin peerDependencies` to see what peer dependencies `eslint-plugin-myplugin` has.
109
-
110
- ### Does ESLint support JSX?
111
-
112
- Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/latest/use/configure)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
113
-
114
116
  ### What ECMAScript versions does ESLint support?
115
117
 
116
118
  ESLint has full support for ECMAScript 3, 5, and every year from 2015 up until the most recent stage 4 specification (the default). You can set your desired ECMAScript syntax and other settings (like global variables) through [configuration](https://eslint.org/docs/latest/use/configure).
@@ -295,7 +297,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
295
297
  <!--sponsorsstart-->
296
298
  <h3>Platinum Sponsors</h3>
297
299
  <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>
300
+ <p><a href="#"><img src="https://images.opencollective.com/guest-bf377e88/avatar.png" alt="Eli Schleifer" height="96"></a> <a href="https://opensource.siemens.com"><img src="https://avatars.githubusercontent.com/u/624020?v=4" alt="Siemens" height="96"></a></p><h3>Silver Sponsors</h3>
299
301
  <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
302
  <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
303
  <!--sponsorsend-->
@@ -303,4 +305,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
303
305
  <!--techsponsorsstart-->
304
306
  <h2>Technology Sponsors</h2>
305
307
  <p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
306
- <!--techsponsorsend-->
308
+ <!--techsponsorsend-->
309
+
310
+ [tidelift]: https://tidelift.com/funding/github/npm/eslint
311
+ [herodevs]: https://www.herodevs.com/support/eslint-nes?utm_source=ESLintWebsite&utm_medium=ESLintWebsite&utm_campaign=ESLintNES&utm_id=ESLintNES
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);
@@ -570,6 +646,23 @@ function createExtraneousResultsError() {
570
646
  return new TypeError("Results object was not created from this ESLint instance.");
571
647
  }
572
648
 
649
+ /**
650
+ * Creates a fixer function based on the provided fix, fixTypesSet, and config.
651
+ * @param {Function|boolean} fix The original fix option.
652
+ * @param {Set<string>} fixTypesSet A set of fix types to filter messages for fixing.
653
+ * @param {FlatConfig} config The config for the file that generated the message.
654
+ * @returns {Function|boolean} The fixer function or the original fix value.
655
+ */
656
+ function getFixerForFixTypes(fix, fixTypesSet, config) {
657
+ if (!fix || !fixTypesSet) {
658
+ return fix;
659
+ }
660
+
661
+ const originalFix = (typeof fix === "function") ? fix : () => true;
662
+
663
+ return message => shouldMessageBeFixed(message, config, fixTypesSet) && originalFix(message);
664
+ }
665
+
573
666
  //-----------------------------------------------------------------------------
574
667
  // Main API
575
668
  //-----------------------------------------------------------------------------
@@ -918,16 +1011,7 @@ class ESLint {
918
1011
 
919
1012
 
920
1013
  // set up fixer for fixTypes if necessary
921
- let fixer = fix;
922
-
923
- if (fix && fixTypesSet) {
924
-
925
- // save original value of options.fix in case it's a function
926
- const originalFix = (typeof fix === "function")
927
- ? fix : () => true;
928
-
929
- fixer = message => shouldMessageBeFixed(message, config, fixTypesSet) && originalFix(message);
930
- }
1014
+ const fixer = getFixerForFixTypes(fix, fixTypesSet, config);
931
1015
 
932
1016
  return retrier.retry(() => fs.readFile(filePath, { encoding: "utf8", signal: controller.signal })
933
1017
  .then(text => {
@@ -1032,13 +1116,18 @@ class ESLint {
1032
1116
  allowInlineConfig,
1033
1117
  cwd,
1034
1118
  fix,
1119
+ fixTypes,
1035
1120
  warnIgnored: constructorWarnIgnored,
1036
1121
  ruleFilter,
1037
1122
  stats
1038
1123
  } = eslintOptions;
1039
1124
  const results = [];
1040
1125
  const startTime = Date.now();
1126
+ const fixTypesSet = fixTypes ? new Set(fixTypes) : null;
1041
1127
  const resolvedFilename = path.resolve(cwd, filePath || "__placeholder__.js");
1128
+ const config = configs.getConfig(resolvedFilename);
1129
+
1130
+ const fixer = getFixerForFixTypes(fix, fixTypesSet, config);
1042
1131
 
1043
1132
  // Clear the last used config arrays.
1044
1133
  if (resolvedFilename && await this.isPathIgnored(resolvedFilename)) {
@@ -1057,7 +1146,7 @@ class ESLint {
1057
1146
  filePath: resolvedFilename.endsWith("__placeholder__.js") ? "<text>" : resolvedFilename,
1058
1147
  configs,
1059
1148
  cwd,
1060
- fix,
1149
+ fix: fixer,
1061
1150
  allowInlineConfig,
1062
1151
  ruleFilter,
1063
1152
  stats,
@@ -1144,7 +1233,7 @@ class ESLint {
1144
1233
 
1145
1234
  /**
1146
1235
  * The main formatter method.
1147
- * @param {LintResults[]} results The lint results to format.
1236
+ * @param {LintResult[]} results The lint results to format.
1148
1237
  * @param {ResultsMeta} resultsMeta Warning count and max threshold.
1149
1238
  * @returns {string} The formatted lint results.
1150
1239
  */
@@ -1190,12 +1279,12 @@ class ESLint {
1190
1279
  /**
1191
1280
  * Finds the config file being used by this instance based on the options
1192
1281
  * passed to the constructor.
1193
- * @returns {string|undefined} The path to the config file being used or
1282
+ * @returns {Promise<string|undefined>} The path to the config file being used or
1194
1283
  * `undefined` if no config file is being used.
1195
1284
  */
1196
1285
  async findConfigFile() {
1197
1286
  const options = privateMembers.get(this).options;
1198
- const { configFilePath } = await locateConfigFileToUse(options);
1287
+ const { configFilePath } = await locateConfigFileToUse(options, this.hasFlag("unstable_ts_config"));
1199
1288
 
1200
1289
  return configFilePath;
1201
1290
  }
@@ -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
  */
@@ -55,6 +55,7 @@ const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, colum
55
55
  const parserSymbol = Symbol.for("eslint.RuleTester.parser");
56
56
  const { LATEST_ECMA_VERSION } = require("../../conf/ecma-version");
57
57
  const { VFile } = require("./vfile");
58
+ const { ParserService } = require("../services/parser-service");
58
59
  const STEP_KIND_VISIT = 1;
59
60
  const STEP_KIND_CALL = 2;
60
61
 
@@ -922,43 +923,6 @@ function analyzeScope(ast, languageOptions, visitorKeys) {
922
923
  });
923
924
  }
924
925
 
925
- /**
926
- * Parses file into an AST. Moved out here because the try-catch prevents
927
- * optimization of functions, so it's best to keep the try-catch as isolated
928
- * as possible
929
- * @param {VFile} file The file to parse.
930
- * @param {Language} language The language to use.
931
- * @param {LanguageOptions} languageOptions Options to pass to the parser
932
- * @returns {{success: false, error: LintMessage}|{success: true, sourceCode: SourceCode}}
933
- * An object containing the AST and parser services if parsing was successful, or the error if parsing failed
934
- * @private
935
- */
936
- function parse(file, language, languageOptions) {
937
-
938
- const result = language.parse(file, { languageOptions });
939
-
940
- if (result.ok) {
941
- return {
942
- success: true,
943
- sourceCode: language.createSourceCode(file, result, { languageOptions })
944
- };
945
- }
946
-
947
- // if we made it to here there was an error
948
- return {
949
- success: false,
950
- errors: result.errors.map(error => ({
951
- ruleId: null,
952
- nodeType: null,
953
- fatal: true,
954
- severity: 2,
955
- message: `Parsing error: ${error.message}`,
956
- line: error.line,
957
- column: error.column
958
- }))
959
- };
960
- }
961
-
962
926
  /**
963
927
  * Runs a rule, and gets its listeners
964
928
  * @param {Rule} rule A rule object
@@ -1407,10 +1371,13 @@ class Linter {
1407
1371
  t = startTime();
1408
1372
  }
1409
1373
 
1410
- const parseResult = parse(
1374
+ const parserService = new ParserService();
1375
+ const parseResult = parserService.parseSync(
1411
1376
  file,
1412
- jslang,
1413
- languageOptions
1377
+ {
1378
+ language: jslang,
1379
+ languageOptions
1380
+ }
1414
1381
  );
1415
1382
 
1416
1383
  if (options.stats) {
@@ -1420,7 +1387,7 @@ class Linter {
1420
1387
  storeTime(time, timeOpts, slots);
1421
1388
  }
1422
1389
 
1423
- if (!parseResult.success) {
1390
+ if (!parseResult.ok) {
1424
1391
  return parseResult.errors;
1425
1392
  }
1426
1393
 
@@ -1712,10 +1679,10 @@ class Linter {
1712
1679
  t = startTime();
1713
1680
  }
1714
1681
 
1715
- const parseResult = parse(
1682
+ const parserService = new ParserService();
1683
+ const parseResult = parserService.parseSync(
1716
1684
  file,
1717
- config.language,
1718
- languageOptions
1685
+ config
1719
1686
  );
1720
1687
 
1721
1688
  if (options.stats) {
@@ -1724,7 +1691,7 @@ class Linter {
1724
1691
  storeTime(time, { type: "parse" }, slots);
1725
1692
  }
1726
1693
 
1727
- if (!parseResult.success) {
1694
+ if (!parseResult.ok) {
1728
1695
  return parseResult.errors;
1729
1696
  }
1730
1697
 
@@ -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
  );
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview ESLint Parser
3
+ * @author Nicholas C. Zakas
4
+ */
5
+ /* eslint class-methods-use-this: off -- Anticipate future constructor arguments. */
6
+
7
+ "use strict";
8
+
9
+ //-----------------------------------------------------------------------------
10
+ // Types
11
+ //-----------------------------------------------------------------------------
12
+
13
+ /** @typedef {import("../linter/vfile.js").VFile} VFile */
14
+ /** @typedef {import("@eslint/core").Language} Language */
15
+ /** @typedef {import("@eslint/core").LanguageOptions} LanguageOptions */
16
+
17
+ //-----------------------------------------------------------------------------
18
+ // Exports
19
+ //-----------------------------------------------------------------------------
20
+
21
+ /**
22
+ * The parser for ESLint.
23
+ */
24
+ class ParserService {
25
+
26
+ /**
27
+ * Parses the given file synchronously.
28
+ * @param {VFile} file The file to parse.
29
+ * @param {{language:Language,languageOptions:LanguageOptions}} config The configuration to use.
30
+ * @returns {Object} An object with the parsed source code or errors.
31
+ * @throws {Error} If the parser returns a promise.
32
+ */
33
+ parseSync(file, config) {
34
+
35
+ const { language, languageOptions } = config;
36
+ const result = language.parse(file, { languageOptions });
37
+
38
+ if (typeof result.then === "function") {
39
+ throw new Error("Unsupported: Language parser returned a promise.");
40
+ }
41
+
42
+ if (result.ok) {
43
+ return {
44
+ ok: true,
45
+ sourceCode: language.createSourceCode(file, result, { languageOptions })
46
+ };
47
+ }
48
+
49
+ // if we made it to here there was an error
50
+ return {
51
+ ok: false,
52
+ errors: result.errors.map(error => ({
53
+ ruleId: null,
54
+ nodeType: null,
55
+ fatal: true,
56
+ severity: 2,
57
+ message: `Parsing error: ${error.message}`,
58
+ line: error.line,
59
+ column: error.column
60
+ }))
61
+ };
62
+ }
63
+ }
64
+
65
+ module.exports = { ParserService };
@@ -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.1",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -18,12 +18,12 @@
18
18
  "build:webpack": "node Makefile.js webpack",
19
19
  "build:readme": "node tools/update-readme.js",
20
20
  "build:rules-index": "node Makefile.js generateRuleIndexPage",
21
- "lint": "node Makefile.js lint",
22
- "lint:docs:js": "node Makefile.js lintDocsJS",
21
+ "lint": "trunk check --no-fix --ignore=docs/**/*.js -a --filter=eslint && trunk check --no-fix --ignore=docs/**/*.js",
22
+ "lint:docs:js": "trunk check --no-fix --ignore=** --ignore=!docs/**/*.js -a --filter=eslint && trunk check --no-fix --ignore=** --ignore=!docs/**/*.js",
23
23
  "lint:docs:rule-examples": "node Makefile.js checkRuleExamples",
24
- "lint:fix": "node Makefile.js lint -- fix",
25
- "lint:fix:docs:js": "node Makefile.js lintDocsJS -- fix",
26
24
  "lint:unused": "knip",
25
+ "lint:fix": "trunk check -y --ignore=docs/**/*.js -a --filter=eslint && trunk check -y --ignore=docs/**/*.js",
26
+ "lint:fix:docs:js": "trunk check -y --ignore=** --ignore=!docs/**/*.js -a --flter=eslint && trunk check -y --ignore=** --ignore=!docs/**/*.js",
27
27
  "release:generate:alpha": "node Makefile.js generatePrerelease -- alpha",
28
28
  "release:generate:beta": "node Makefile.js generatePrerelease -- beta",
29
29
  "release:generate:latest": "node Makefile.js generateRelease",
@@ -40,8 +40,8 @@
40
40
  "pre-commit": "lint-staged"
41
41
  },
42
42
  "lint-staged": {
43
- "*.js": "eslint --fix",
44
- "*.md": "markdownlint --fix",
43
+ "*.js": "trunk check --fix --filter=eslint",
44
+ "*.md": "trunk check --fix --filter=markdownlint",
45
45
  "lib/rules/*.js": [
46
46
  "node tools/update-eslint-all.js",
47
47
  "git add packages/js/src/configs/eslint-all.js"
@@ -51,7 +51,7 @@
51
51
  "node tools/fetch-docs-links.js",
52
52
  "git add docs/src/_data/further_reading_links.json"
53
53
  ],
54
- "docs/**/*.svg": "npx -y svgo -r --multipass"
54
+ "docs/**/*.svg": "trunk check --fix --filter=svgo"
55
55
  },
56
56
  "files": [
57
57
  "LICENSE",
@@ -68,9 +68,9 @@
68
68
  "dependencies": {
69
69
  "@eslint-community/eslint-utils": "^4.2.0",
70
70
  "@eslint-community/regexpp": "^4.11.0",
71
- "@eslint/config-array": "^0.17.1",
71
+ "@eslint/config-array": "^0.18.0",
72
72
  "@eslint/eslintrc": "^3.1.0",
73
- "@eslint/js": "9.8.0",
73
+ "@eslint/js": "9.9.1",
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,15 @@
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.4.0",
108
+ "@eslint/json": "^0.3.0",
109
+ "@trunkio/launcher": "^1.3.0",
109
110
  "@types/estree": "^1.0.5",
110
111
  "@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",
112
+ "@wdio/browser-runner": "^9.0.5",
113
+ "@wdio/cli": "^9.0.5",
114
+ "@wdio/concise-reporter": "^9.0.4",
115
+ "@wdio/mocha-framework": "^9.0.5",
115
116
  "babel-loader": "^8.0.5",
116
117
  "c8": "^7.12.0",
117
118
  "chai": "^4.0.1",
@@ -122,6 +123,7 @@
122
123
  "eslint": "file:.",
123
124
  "eslint-config-eslint": "file:packages/eslint-config-eslint",
124
125
  "eslint-plugin-eslint-plugin": "^6.0.0",
126
+ "eslint-plugin-yml": "^1.14.0",
125
127
  "eslint-release": "^3.2.2",
126
128
  "eslint-rule-composer": "^0.3.0",
127
129
  "eslump": "^3.0.0",
@@ -132,14 +134,12 @@
132
134
  "globals": "^15.0.0",
133
135
  "got": "^11.8.3",
134
136
  "gray-matter": "^4.0.3",
135
- "js-yaml": "^4.1.0",
137
+ "jiti": "^1.21.6",
136
138
  "knip": "^5.21.0",
137
139
  "lint-staged": "^11.0.0",
138
140
  "load-perf": "^0.2.0",
139
141
  "markdown-it": "^12.2.0",
140
142
  "markdown-it-container": "^3.0.0",
141
- "markdownlint": "^0.34.0",
142
- "markdownlint-cli": "^0.41.0",
143
143
  "marked": "^4.0.8",
144
144
  "metascraper": "^5.25.7",
145
145
  "metascraper-description": "^5.25.7",
@@ -165,6 +165,14 @@
165
165
  "webpack-cli": "^4.5.0",
166
166
  "yorkie": "^2.0.0"
167
167
  },
168
+ "peerDependencies": {
169
+ "jiti": "*"
170
+ },
171
+ "peerDependenciesMeta": {
172
+ "jiti": {
173
+ "optional": true
174
+ }
175
+ },
168
176
  "keywords": [
169
177
  "ast",
170
178
  "lint",