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
+56-38Lines changed: 56 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,62 @@ With this configuration, the `semi` rule is enabled for all files that match the
138
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
139
:::
140
140
141
+
#### Specifying files with arbitrary extensions
142
+
143
+
To lint files with extensions other than the default `.js`, `.cjs` and `.mjs`, include them in `files` with a pattern in the format of `"**/*.extension"`. Any pattern will work except if it is `*` or if it ends with `/*` or `/**`.
144
+
For example, to lint TypeScript files with `.ts`, `.cts` and `.mts` extensions, you would specify a configuration object like this:
145
+
146
+
```js
147
+
// eslint.config.js
148
+
import { defineConfig } from"eslint/config";
149
+
150
+
exportdefaultdefineConfig([
151
+
{
152
+
files: ["**/*.ts", "**/*.cts", "**.*.mts"],
153
+
},
154
+
// ...other config
155
+
]);
156
+
```
157
+
158
+
#### Specifying files without extension
159
+
160
+
Files without an extension can be matched with the pattern `!(*.*)`. For example:
161
+
162
+
```js
163
+
// eslint.config.js
164
+
import { defineConfig } from"eslint/config";
165
+
166
+
exportdefaultdefineConfig([
167
+
{
168
+
files: ["**/!(*.*)"],
169
+
},
170
+
// ...other config
171
+
]);
172
+
```
173
+
174
+
The above config lints files without extension besides the default `.js`, `.cjs` and `.mjs` extensions in all directories.
175
+
::: tip
176
+
Filenames starting with a dot, such as `.gitignore`, are considered to have only an extension without a base name. In the case of `.gitignore`, the extension is `gitignore`, so the file matches the pattern `"**/.gitignore"` but not `"**/*.gitignore"`.
177
+
:::
178
+
179
+
#### Specifying files with an AND operation
180
+
181
+
Multiple patterns can be matched against the same file by using an array of strings inside of the `files` array. For example:
182
+
183
+
```js
184
+
// eslint.config.js
185
+
import { defineConfig } from"eslint/config";
186
+
187
+
exportdefaultdefineConfig([
188
+
{
189
+
files: [["src/*", "**/.js"]],
190
+
},
191
+
// ...other config
192
+
]);
193
+
```
194
+
195
+
The pattern `["src/*", "**/.js"]` matches when a file is both inside of the `src` directory and also ends with `.js`. This approach can be helpful when you're dynamically calculating the value of the `files` array and want to avoid potential errors by trying to combine multiple glob patterns into a single string.
196
+
141
197
#### Excluding files with `ignores`
142
198
143
199
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:
@@ -219,44 +275,6 @@ ESLint only lints files that are matched either by default or by a `files` patte
219
275
Use the [config inspector](https://github.com/eslint/config-inspector) (`--inspect-config` in the CLI) to test which config objects apply to a specific file.
220
276
:::
221
277
222
-
#### Specifying files with arbitrary extensions
223
-
224
-
To lint files with extensions other than the default `.js`, `.cjs` and `.mjs`, include them in `files` with a pattern in the format of `"**/*.extension"`. Any pattern will work except if it is `*` or if it ends with `/*` or `/**`.
225
-
For example, to lint TypeScript files with `.ts`, `.cts` and `.mts` extensions, you would specify a configuration object like this:
226
-
227
-
```js
228
-
// eslint.config.js
229
-
import { defineConfig } from"eslint/config";
230
-
231
-
exportdefaultdefineConfig([
232
-
{
233
-
files: ["**/*.ts", "**/*.cts", "**.*.mts"],
234
-
},
235
-
// ...other config
236
-
]);
237
-
```
238
-
239
-
#### Specifying files without extension
240
-
241
-
Files without an extension can be matched with the pattern `!(*.*)`. For example:
242
-
243
-
```js
244
-
// eslint.config.js
245
-
import { defineConfig } from"eslint/config";
246
-
247
-
exportdefaultdefineConfig([
248
-
{
249
-
files: ["**/!(*.*)"],
250
-
},
251
-
// ...other config
252
-
]);
253
-
```
254
-
255
-
The above config lints files without extension besides the default `.js`, `.cjs` and `.mjs` extensions in all directories.
256
-
::: tip
257
-
Filenames starting with a dot, such as `.gitignore`, are considered to have only an extension without a base name. In the case of `.gitignore`, the extension is `gitignore`, so the file matches the pattern `"**/.gitignore"` but not `"**/*.gitignore"`.
258
-
:::
259
-
260
278
#### Globally ignoring files with `ignores`
261
279
262
280
Depending on how the `ignores` property is used, it can behave as non-global `ignores` or as global `ignores`.
0 commit comments