Content-Length: 394147 | pFad | https://github.com/eslint/eslint/commit/bd5def66d1a3f9bad7da3547b5dff6003e67d9d3

CD docs: Clean up configuration files docs (#19735) · eslint/eslint@bd5def6 · GitHub
Skip to content

Commit bd5def6

Browse files
nzakasmdjermanovic
andauthored
docs: Clean up configuration files docs (#19735)
* docs: Clean up configuration files docs * Update docs/src/use/configure/configuration-files.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent d71e37f commit bd5def6

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,40 @@ Each configuration object contains all of the information ESLint needs to execut
9090
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.
9191
:::
9292

93-
You can use a combination of `files` and `ignores` to determine which files the configuration object should apply to and which not. By default, ESLint lints files that match the patterns `**/*.js`, `**/*.cjs`, and `**/*.mjs`. Those files are always matched unless you explicitly exclude them using [global ignores](#globally-ignoring-files-with-ignores).
94-
Because config objects that don't specify `files` or `ignores` apply to all files that have been matched by any other configuration object, they will apply to all JavaScript files. For example:
93+
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:
9594

9695
```js
9796
// eslint.config.js
9897
import { defineConfig } from "eslint/config";
9998

10099
export default defineConfig([
100+
// matches all files ending with .js
101+
{
102+
files: ["**/*.js"],
103+
rules: {
104+
semi: "error",
105+
},
106+
},
107+
108+
// matches all files ending with .js except those in __tests
109+
{
110+
files: ["**/*.js"],
111+
ignores: ["__tests/**"],
112+
rules: {
113+
"no-console": "error",
114+
},
115+
},
116+
]);
117+
```
118+
119+
Configuration objects without `files` or `ignores` are automatically applied to any file that is matched by any other configuration object. For example:
120+
121+
```js
122+
// eslint.config.js
123+
import { defineConfig } from "eslint/config";
124+
125+
export default defineConfig([
126+
// matches all files because it doesn't specify the `files` or `ignores` key
101127
{
102128
rules: {
103129
semi: "error",
@@ -108,6 +134,10 @@ export default defineConfig([
108134

109135
With this configuration, the `semi` rule is enabled for all files that match the default files in ESLint. So if you pass `example.js` to ESLint, the `semi` rule is applied. If you pass a non-JavaScript file, like `example.txt`, the `semi` rule is not applied because there are no other configuration objects that match that filename. (ESLint outputs an error message letting you know that the file was ignored due to missing configuration.)
110136

137+
::: important
138+
By default, ESLint lints files that match the patterns `**/*.js`, `**/*.cjs`, and `**/*.mjs`. Those files are always matched unless you explicitly exclude them using [global ignores](#globally-ignoring-files-with-ignores).
139+
:::
140+
111141
#### Excluding files with `ignores`
112142

113143
You can limit which files a configuration object applies to by specifying a combination of `files` and `ignores` patterns. For example, you may want certain rules to apply only to files in your `src` directory:
@@ -129,6 +159,7 @@ export default defineConfig([
129159
Here, only the JavaScript files in the `src` directory have the `semi` rule applied. If you run ESLint on files in another directory, this configuration object is skipped. By adding `ignores`, you can also remove some of the files in `src` from this configuration object:
130160

131161
```js
162+
// eslint.config.js
132163
import { defineConfig } from "eslint/config";
133164

134165
export default defineConfig([
@@ -145,6 +176,7 @@ export default defineConfig([
145176
This configuration object matches all JavaScript files in the `src` directory except those that end with `.config.js`. You can also use negation patterns in `ignores` to exclude files from the ignore patterns, such as:
146177

147178
```js
179+
// eslint.config.js
148180
import { defineConfig } from "eslint/config";
149181

150182
export default defineConfig([
@@ -165,6 +197,7 @@ Non-global `ignores` patterns can only match file names. A pattern like `"dir-to
165197
If `ignores` is used without `files` and there are other keys (such as `rules`), then the configuration object applies to all linted files except the ones excluded by `ignores`, for example:
166198

167199
```js
200+
// eslint.config.js
168201
import { defineConfig } from "eslint/config";
169202

170203
export default defineConfig([

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/eslint/eslint/commit/bd5def66d1a3f9bad7da3547b5dff6003e67d9d3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy