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
Copy file name to clipboardExpand all lines: docs/src/use/configure/configuration-files.md
+78-3Lines changed: 78 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,7 @@ module.exports = defineConfig([
66
66
Each configuration object contains all of the information ESLint needs to execute on a set of files. Each configuration object is made up of these properties:
67
67
68
68
-`name` - A name for the configuration object. This is used in error messages and [config inspector](https://github.com/eslint/config-inspector) to help identify which configuration object is being used. ([Naming Convention](#configuration-naming-conventions))
69
+
-`basePath` - A string specifying the path to a subdirectory to which the configuration object should apply to. It can be a relative or an absolute path.
69
70
-`files` - An array of glob patterns indicating the files that the configuration object should apply to. If not specified, the configuration object applies to all files matched by any other configuration object.
70
71
-`ignores` - An array of glob patterns indicating the files that the configuration object should not apply to. If not specified, the configuration object applies to all files matched by `files`. If `ignores` is used without any other keys in the configuration object, then the patterns act as [global ignores](#globally-ignoring-files-with-ignores) and it gets applied to every configuration object.
71
72
-`extends` - An array of strings, configuration objects, or configuration arrays that contain additional configuration to apply.
@@ -87,7 +88,7 @@ Each configuration object contains all of the information ESLint needs to execut
87
88
### Specifying `files` and `ignores`
88
89
89
90
::: tip
90
-
Patterns specified in `files` and `ignores` use [`minimatch`](https://www.npmjs.com/package/minimatch) syntax and are evaluated relative to the location of the `eslint.config.js` file. If using an alternate config file via the `--config` command line option, then all patterns are evaluated relative to the current working directory.
91
+
Patterns specified in `files` and `ignores` use [`minimatch`](https://www.npmjs.com/package/minimatch) syntax and are evaluated relative to the location of the `eslint.config.js` file. If using an alternate config file via the `--config` command line option, then all patterns are evaluated relative to the current working directory. In case the configuration object has the `basePath` property with a relative path, the subdirectory it specifies is evaluated relative to the location of the `eslint.config.js` file (or relative to the current working directory if using an alternate config file via the `--config` command line option). In configuration objects with the `basePath` property, patterns specified in `files` and `ignores` are evaluated relative to the subdirectory represented by the `basePath`.
91
92
:::
92
93
93
94
You can use a combination of `files` and `ignores` to determine which files the configuration object should apply to and which not. Here's an example:
For more information and examples on configuring rules regarding `ignores`, see [Ignore Files](ignore).
348
349
350
+
#### Specifying base path
351
+
352
+
You can optionally specify `basePath` to apply the configuration object to a specific subdirectory (including its subdirectories).
353
+
354
+
```js
355
+
// eslint.config.js
356
+
import { defineConfig } from"eslint/config";
357
+
358
+
exportdefaultdefineConfig([
359
+
// matches all files in tests and its subdirectories
360
+
{
361
+
basePath:"tests",
362
+
rules: {
363
+
"no-undef":"error",
364
+
},
365
+
},
366
+
367
+
// matches all files ending with spec.js in tests and its subdirectories
368
+
{
369
+
basePath:"tests",
370
+
files: ["**/*.spec.js"],
371
+
languageOptions: {
372
+
globals: {
373
+
it:"readonly",
374
+
describe:"readonly",
375
+
},
376
+
},
377
+
},
378
+
379
+
// globally ignores tests/fixtures directory
380
+
{
381
+
basePath:"tests",
382
+
ignores: ["fixtures/"],
383
+
},
384
+
]);
385
+
```
386
+
387
+
In combination with [`extends`](#extending-configurations), multiple configuration objects can be applied to the same subdirectory by specifying `basePath` only once, like this:
388
+
389
+
```js
390
+
// eslint.config.js
391
+
import { defineConfig } from"eslint/config";
392
+
393
+
exportdefaultdefineConfig([
394
+
{
395
+
basePath:"tests",
396
+
extends: [
397
+
// matches all files in tests and its subdirectories
398
+
{
399
+
rules: {
400
+
"no-undef":"error",
401
+
},
402
+
},
403
+
404
+
// matches all files ending with spec.js in tests and its subdirectories
405
+
{
406
+
files: ["**/*.spec.js"],
407
+
languageOptions: {
408
+
globals: {
409
+
it:"readonly",
410
+
describe:"readonly",
411
+
},
412
+
},
413
+
},
414
+
415
+
// globally ignores tests/fixtures directory
416
+
{
417
+
ignores: ["fixtures/"],
418
+
},
419
+
],
420
+
},
421
+
]);
422
+
```
423
+
349
424
#### Cascading Configuration Objects
350
425
351
426
When more than one configuration object matches a given filename, the configuration objects are merged with later objects overriding previous objects when there is a conflict. For example:
@@ -698,12 +773,12 @@ In this case, ESLint does not search for `eslint.config.js` and instead uses `so
698
773
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.
699
774
:::
700
775
701
-
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.
776
+
You can use the `v10_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.
702
777
703
778
To use this feature on the command line, use the `--flag` flag:
0 commit comments