Skip to content

Commit

Permalink
docs: Improve flat config ignores docs (#17997)
Browse files Browse the repository at this point in the history
* docs: Improve flat config ignores docs

fixes #17822

* Fix links
  • Loading branch information
nzakas committed Jan 19, 2024
1 parent e3051be commit 1fedfd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
26 changes: 25 additions & 1 deletion docs/src/use/configure/ignore.md
Expand Up @@ -38,7 +38,31 @@ You can also ignore files on the command line using `--ignore-pattern`, such as:
npx eslint . --ignore-pattern ".config/*"
```

## Unignoring Files
## Ignoring Directories

Ignoring directories works the same way as ignoring files, by placing a pattern in the `ignores` key of a configuration object with no other keys. For example, the following ignores the `.config` directory as a whole (meaning file search will not traverse into it at all):

```js
// eslint.config.js
export default [
{
ignores: [".config/"]
}
];
```

Unlike `.gitignore`, an ignore pattern like `.config` will only ignore the `.config` directory in the same directory as the configuration file. If you want to recursively ignore all directories named `.config`, you need to use `**/.config/`, as in this example:

```js
// eslint.config.js
export default [
{
ignores: ["**/.config/"]
}
];
```

## Unignoring Files and Directories

You can also unignore files and directories that are ignored by previous patterns, including the default patterns. For example, this config unignores `node_modules/mylibrary`:

Expand Down
3 changes: 2 additions & 1 deletion docs/src/use/configure/index.md
Expand Up @@ -52,5 +52,6 @@ All of these options give you fine-grained control over how ESLint treats your c
[**Ignore Files**](ignore)

* [Ignoring Files](./ignore#ignoring-files)
* [Unignoring Files](./ignore#unignoring-files)
* [Ignoring Directories](./ignore#ignoring-directories)
* [Unignoring Files and Directories](./ignore#unignoring-files-and-directories)
* [Ignored File Warnings](./ignore#ignored-file-warnings)
10 changes: 7 additions & 3 deletions docs/src/use/configure/migration-guide.md
Expand Up @@ -524,7 +524,7 @@ config/*
# ...other ignored files
```
`ignorePatterns` example:
Here are the same patterns represented as `ignorePatterns` in a `.eslintrc.js` file:
```javascript
// .eslintrc.js
Expand All @@ -534,7 +534,7 @@ module.exports = {
};
```
Here are the same files ignore patterns in flat config:
The equivalent ignore patterns in flat config look like this:
```javascript
export default [
Expand All @@ -545,7 +545,11 @@ export default [
];
```
Also, with flat config, dotfiles (e.g. `.dotfile.js`) are no longer ignored by default. If you want to ignore dotfiles, add files ignore pattern `"**/.*"`.
In `.eslintignore`, `temp.js` ignores all files named `temp.js`, whereas in flat config, you need to specify this as `**/temp.js`. The pattern `temp.js` in flat config only ignores a file named `temp.js` in the same directory as the configuration file.
::: important
In flat config , dotfiles (e.g. `.dotfile.js`) are no longer ignored by default. If you want to ignore dotfiles, add an ignore pattern of `"**/.*"`.
:::
### Linter Options
Expand Down

0 comments on commit 1fedfd2

Please sign in to comment.