Skip to content

Commit 2ff0e51

Browse files
nzakasaladdin-addfasttimemdjermanovic
authored
feat: Implement alternate config lookup (#18742)
* feat: Look up config file from file being linted fixes #18385 * Fix ESLint class flag lookup * Fix up tests for config lookup * Add documentation for new config lookup flag * Clean up directory searching behavior * Read config files from starting from parent * Cover edge cases * Fix failing test * Fix test and linting errors * Remove .only from tests * Fix failing test * Incorporate TypeScript config files * Fix lint errors * Fix docs link * Fix broken link * Fix conflicts * Update lib/config/config-loader.js Co-authored-by: 唯然 <weiran.zsd@outlook.com> * Update lib/config/config-loader.js Co-authored-by: 唯然 <weiran.zsd@outlook.com> * Update docs/src/use/configure/configuration-files.md Co-authored-by: Francesco Trotta <github@fasttime.org> * Add comment about CLI overrideConfig * Remove duplicate code * Fix error * add test with a deep subdir * Remove immediate child check * Fix edge cases * Clean up logic * Ensure foo*/*.js doesn't traverse directory foo when ignored * Ensure order of glob patterns doesn't matter * Fix edge cases * Don't normalize absolute path to posix * add tests with overrideConfig and no config file * Fix config override behavior * Fix lint issues * Update docs/src/use/configure/configuration-files.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update docs/src/use/configure/configuration-files.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/config-loader.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/config-loader.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/config-loader.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/config-loader.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update directory search to group by glob parent * Simplify lookup * Remove unused package --------- Co-authored-by: 唯然 <weiran.zsd@outlook.com> Co-authored-by: Francesco Trotta <github@fasttime.org> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 2d17453 commit 2ff0e51

25 files changed

Lines changed: 8825 additions & 7453 deletions

File tree

docs/src/use/configure/configuration-files.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,22 @@ npx eslint --config some-other-file.js **/*.js
499499

500500
In this case, ESLint does not search for `eslint.config.js` and instead uses `some-other-file.js`.
501501

502+
### Experimental Configuration File Resolution
503+
504+
::: warning
505+
This feature is experimental and its details may change before being finalized. This behavior will be the new lookup behavior starting in v10.0.0, but you can try it today using a feature flag.
506+
:::
507+
508+
You can use the `unstable_config_lookup_from_file` flag to change the way ESLint searches for configuration files. Instead of searching from the current working directory, ESLint will search for a configuration file by first starting in the directory of the file being linted and then searching up its ancestor directories until it finds a `eslint.config.js` file (or any other extension of configuration file). This behavior is better for monorepos, where each subdirectory may have its own configuration file.
509+
510+
To use this feature on the command line, use the `--flag` flag:
511+
512+
```shell
513+
npx eslint --flag unstable_config_lookup_from_file .
514+
```
515+
516+
For more information about using feature flags, see [Feature Flags](../../flags/).
517+
502518
## TypeScript Configuration Files
503519

504520
::: warning
@@ -511,6 +527,8 @@ You need to enable this feature through the `unstable_ts_config` feature flag:
511527
npx eslint --flag unstable_ts_config
512528
```
513529

530+
For more information about using feature flags, see [Feature Flags](../../flags/).
531+
514532
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):
515533

516534
```bash
@@ -560,7 +578,7 @@ ESLint does not perform type checking on your configuration file and does not ap
560578
:::
561579

562580
::: 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)
581+
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)
564582
:::
565583

566584
### Configuration File Precedence

lib/cli.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,9 @@ const cli = {
348348
// find the config file
349349
const {
350350
configFilePath,
351-
basePath,
352-
error
351+
basePath
353352
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile }, hasUnstableTSConfigFlag);
354353

355-
if (error) {
356-
throw error;
357-
}
358-
359354
return ["--config", configFilePath, "--basePath", basePath];
360355
},
361356

0 commit comments

Comments
 (0)