You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Initial working implementation of TS config files
* Simplify implementation
* Use typescript's `transpile()` instead of `tsx` to avoid side effects
* Remove unnecessary nullish coalescing
* Use `jiti` instead of TypeScript
* Add missing section related to `importedConfigFileModificationTime`
* Enable `esmResolve` for `jiti`
* Make `jiti` an optional peer dependency
* Throw an error if `jiti` is not installed
* Add `jiti` to `ignoreDependencies` in `knip.jsonc`
* Fix broken unit tests caused by stubbed `process.version`
Co-authored-by: Anthony Fu <[email protected]>
* Prioritize JavaScript config files over TypeScript config files
* Add some basic tests for loading TS config files
* Fix minor type issues in JSDocs
* Partially Inline the `FlatConfig` type from `@types/eslint` to reuse
- This is not only done to reduce some potential redundancy down the line, but to ensure that TS config files are able to handle `type` imports as that is something most people are likely going to do.
* Stringify `mtime`
* Check if ESLint is running in Deno or Bun
Note: `isRunningInBun` and `isRunningInDeno` are functions to make treeshaking for consuming libraries easier.
* Try a different approach for loading TS config files
- This is done for mainly 2 reasons:
1. We don't know how many runtime environments are going to support loading TS files natively in the future, so this saves us having to check for every single one.
2. This also ensures that we give the user the option of passing their own TS loader of choice through `NODE_OPTIONS` in CLI for example: `NODE_OPTIONS=--import=tsx/esm`, without ESLint getting in the way and potentially causing conflicts between multiple loaders.
* Add tests for `lintFiles` with TS config files
* Revert "Try a different approach for loading TS config files"
This reverts commit 209c791.
* Convert `Severity` type to a `const enum`
* Add tests for TS config files containing `const enum`s
* Add `ESLintNameSpace` local `namespace`
* Add tests for TS config files containing importing a local `namespace`
* Fix minor type issues in JSDocs
* Add tests for passing TS config files to `overrideConfigFile`
* Bump `jiti` to version 1.21.1
* Bump `jiti` to version 1.21.6
* Add basic docs for loading TypeScript configuration files
* Fix lint issues
* Bump `jiti` to version 2.0.0-beta.1
* Remove `esmResolve` as it has been removed in v2 of `jiti`
* Fix types for `createCustomTeardown`
* Remove `interopDefault: true`
- `interopDefault: true` does not work well with `jiti.import()`.
* Fix type of `eslint` in test file
* Fix lint issues in test file
* Add more tests
- Added tests for top-level `await`, interoperability, and mixed ESM/CJS syntax.
* Defer to v10 in docs
* Bump `jiti` to version 2.0.0-beta.3
* Fix import of `jiti`
* Fix `jiti` link in docs
* Fix `jiti` link in docs
* Add `unstable_ts_config` to `activeFlags`
* Fix issues in `configuration-files.md`
* Fix `LintResults` in `eslint.js`
* Change `LintResults` to `LintResult` in `eslint.js`
* Remove warning regarding top-level `await`
* Explicitly check for `.ts`, `.mts` or `.cts` extensions
* Check if `"unstable_ts_config"` flag is enabled
* Fix import and export assignment tests
* Fix remaining issues in `configuration-files.md`
* Fix test title
* De-duplicate test
* Revert "Fix broken unit tests caused by stubbed `process.version`"
This reverts commit f339591.
* Remove unnecessary checks for `"unstable_ts_config"` flag
* Fix type of `findConfigFile`
* Make sure tests fail when the correct config file is not loaded
* Add a test for `"unstable_ts_config"`
- Added a test to check that the TS config file is not loaded when the `"unstable_ts_config"` flag is not set.
* Remove fallback to `default` when loading `jiti.createJiti`
* Update `configuration-files.md`
* Update description of `"unstable_ts_config"` flag
* Add comment explaining purpose of `helper.ts`
* Disable `moduleCache`
* Add test to check reloading logic for TS config files
* Add comment for disabling `moduleCache`
* Rework `hasUnstableTSConfigFlag` logic
* Fix unit tests
* Fallback to `default` when loading `jiti`
* Rework logic for loading TS config files
- Rework the logic to ensure `overrideConfigFile` does not load TS config files unless the `unstable_ts_config` flag is set.
* Remove default value for `hasUnstableTSConfigFlag` parameter
* Remove type assertion
* Remove unnecessary `process?.versions?.bun` check
* Remove unnecessary `LintResults` type
* Fix parameter type of `eslintWithPlugins`
- We avoid potential repetition by using the new [`@import JSDoc tags`](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag) released in TypeScript 5.5.
* Add tests for loading TypeScript config files that export a promise
* Update `jiti` peer dependency to allow any version
* Warn about using an outdated version of `jiti`
* Fix minor issue in `configuration-files.md`
* Add section about `--flag` in `configuration-files.md`
* Reapply "Fix broken unit tests caused by stubbed `process.version`"
This reverts commit f369145.
* Switch to `jiti` v1 until `jiti` v2 becomes stable
* Add commented-out unit tests for `jiti` v2
* Throw a `TypeError` if `jiti.import` is not a function
* Change `TypeError` to `Error`
---------
Co-authored-by: Anthony Fu <[email protected]>
In this case, ESLint does not search for `eslint.config.js` and instead uses `some-other-file.js`.
501
+
502
+
## TypeScript Configuration Files
503
+
504
+
::: warning
505
+
This feature is currently experimental and may change in future versions.
506
+
:::
507
+
508
+
You need to enable this feature through the `unstable_ts_config` feature flag:
509
+
510
+
```bash
511
+
npx eslint --flag unstable_ts_config
512
+
```
513
+
514
+
For Deno and Bun, TypeScript configuration files are natively supported; for Node.js, you must install the optional dev dependency [`jiti`](https://github.com/unjs/jiti) in your project (this dependency is not automatically installed by ESLint):
515
+
516
+
```bash
517
+
npm install -D jiti
518
+
# or
519
+
yarn add --dev jiti
520
+
# or
521
+
pnpm add -D jiti
522
+
```
523
+
524
+
You can then create a configuration file with a `.ts`, `.mts`, or `.cts` extension, and export an array of [configuration objects](#configuration-objects). Here's an example in ESM format:
525
+
526
+
```ts
527
+
importjsfrom"@eslint/js";
528
+
importtype { Linter } from"eslint";
529
+
530
+
exportdefault [
531
+
js.configs.recommended,
532
+
{
533
+
rules: {
534
+
"no-console": [0],
535
+
},
536
+
},
537
+
] satisfiesLinter.FlatConfig[];
538
+
```
539
+
540
+
Here's an example in CommonJS format:
541
+
542
+
```ts
543
+
importtype { Linter } from"eslint";
544
+
const eslint =require("@eslint/js");
545
+
546
+
const config:Linter.FlatConfig[] = [
547
+
eslint.configs.recommended,
548
+
{
549
+
rules: {
550
+
"no-console": [0],
551
+
},
552
+
},
553
+
];
554
+
555
+
module.exports=config;
556
+
```
557
+
558
+
::: important
559
+
ESLint does not perform type checking on your configuration file and does not apply any settings from `tsconfig.json`.
560
+
:::
561
+
562
+
::: warning
563
+
As of now, [`jiti`](https://github.com/unjs/jiti) does not support [Top-level `await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await)
564
+
:::
565
+
566
+
### Configuration File Precedence
567
+
568
+
If you have multiple ESLint configuration files, ESLint prioritizes JavaScript files over TypeScript files. The order of precedence is as follows:
569
+
570
+
1.`eslint.config.js`
571
+
2.`eslint.config.mjs`
572
+
3.`eslint.config.cjs`
573
+
4.`eslint.config.ts`
574
+
5.`eslint.config.mts`
575
+
6.`eslint.config.cts`
576
+
577
+
To override this behavior, use the `--config` or `-c` command line option to specify a different configuration file:
thrownewError("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.");
0 commit comments