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
+35-2Lines changed: 35 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -90,14 +90,40 @@ Each configuration object contains all of the information ESLint needs to execut
90
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
91
:::
92
92
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:
95
94
96
95
```js
97
96
// eslint.config.js
98
97
import { defineConfig } from"eslint/config";
99
98
100
99
exportdefaultdefineConfig([
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
+
exportdefaultdefineConfig([
126
+
// matches all files because it doesn't specify the `files` or `ignores` key
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.)
110
136
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
+
111
141
#### Excluding files with `ignores`
112
142
113
143
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([
129
159
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:
130
160
131
161
```js
162
+
// eslint.config.js
132
163
import { defineConfig } from"eslint/config";
133
164
134
165
exportdefaultdefineConfig([
@@ -145,6 +176,7 @@ export default defineConfig([
145
176
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:
146
177
147
178
```js
179
+
// eslint.config.js
148
180
import { defineConfig } from"eslint/config";
149
181
150
182
exportdefaultdefineConfig([
@@ -165,6 +197,7 @@ Non-global `ignores` patterns can only match file names. A pattern like `"dir-to
165
197
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:
0 commit comments