Skip to content

Commit 3ec2082

Browse files
nzakaslumirlumir
andauthored
docs: Nested arrays in files config entry (#19799)
* docs: Nested arrays in files config entry fixes #18966 * Update docs/src/use/configure/configuration-files.md Co-authored-by: 루밀LuMir <rpfos@naver.com> --------- Co-authored-by: 루밀LuMir <rpfos@naver.com>
1 parent 89a65b0 commit 3ec2082

File tree

1 file changed

+56
-38
lines changed

1 file changed

+56
-38
lines changed

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

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,62 @@ With this configuration, the `semi` rule is enabled for all files that match the
138138
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).
139139
:::
140140

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+
export default defineConfig([
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+
export default defineConfig([
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+
export default defineConfig([
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+
141197
#### Excluding files with `ignores`
142198

143199
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
219275
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.
220276
:::
221277

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-
export default defineConfig([
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-
export default defineConfig([
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-
260278
#### Globally ignoring files with `ignores`
261279

262280
Depending on how the `ignores` property is used, it can behave as non-global `ignores` or as global `ignores`.

0 commit comments

Comments
 (0)