Skip to content

Commit 3e66387

Browse files
bpmutternzakasamareshsm
authored
docs: add intro and edit ignoring files page (#16510)
* docs: add intro and edit ignoring files page Partial fix of #16473 * copy edit * Apply suggestions from the code review Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Amaresh S M <amareshsm13@gmail.com> Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Amaresh S M <amareshsm13@gmail.com>
1 parent 436f712 commit 3e66387

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

docs/src/user-guide/configuring/ignoring-code.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ eleventyNavigation:
88

99
---
1010

11+
You can configure ESLint to ignore certain files and directories while linting by specifying one or more glob patterns.
12+
You can ignore files in the following ways:
13+
14+
* Add `ignorePatterns` to a configuration file.
15+
* Create a dedicated file that contains the ignore patterns (`.eslintignore` by default).
16+
1117
## `ignorePatterns` in Config Files
1218

1319
You can tell ESLint to ignore specific files and directories using `ignorePatterns` in your config files. `ignorePatterns` patterns follow the same rules as `.eslintignore`. Please see the [`.eslintignore` file documentation](./ignoring-code#the-eslintignore-file) to learn more.
@@ -31,13 +37,13 @@ If a config is provided via the `--config` CLI option, the ignore patterns that
3137

3238
## The `.eslintignore` File
3339

34-
You can tell ESLint to ignore specific files and directories by creating an `.eslintignore` file in your project's root directory. The `.eslintignore` file is a plain text file where each line is a glob pattern indicating which paths should be omitted from linting. For example, the following will omit all JavaScript files:
40+
You can tell ESLint to ignore specific files and directories by creating a `.eslintignore` file in your project's root directory. The `.eslintignore` file is a plain text file where each line is a glob pattern indicating which paths should be omitted from linting. For example, the following omits all JavaScript files:
3541

3642
```text
3743
**/*.js
3844
```
3945

40-
When ESLint is run, it looks in the current working directory to find an `.eslintignore` file before determining which files to lint. If this file is found, then those preferences are applied when traversing directories. Only one `.eslintignore` file can be used at a time, so `.eslintignore` files other than the one in the current working directory will not be used.
46+
When ESLint is run, it looks in the current working directory to find a `.eslintignore` file before determining which files to lint. If this file is found, then those preferences are applied when traversing directories. Only one `.eslintignore` file can be used at a time, so `.eslintignore` files other than the one in the current working directory are not used.
4147

4248
Globs are matched using [node-ignore](https://github.com/kaelzhang/node-ignore), so a number of features are available:
4349

@@ -61,17 +67,17 @@ Please see [`.gitignore`](https://git-scm.com/docs/gitignore)'s specification fo
6167
In addition to any patterns in the `.eslintignore` file, ESLint always follows a couple of implicit ignore rules even if the `--no-ignore` flag is passed. The implicit rules are as follows:
6268

6369
* `node_modules/` is ignored.
64-
* dot-files (except for `.eslintrc.*`), as well as dot-folders and their contents, are ignored.
70+
* dot-files (except for `.eslintrc.*`) as well as dot-folders and their contents are ignored.
6571

6672
There are also some exceptions to these rules:
6773

68-
* If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders will be linted. This includes dot-files and dot-folders that are buried deeper in the directory structure.
74+
* If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders are linted. This includes dot-files and dot-folders that are buried deeper in the directory structure.
6975

70-
For example, `eslint .config/` will lint all dot-folders and dot-files in the `.config` directory, including immediate children as well as children that are deeper in the directory structure.
76+
For example, `eslint .config/` would lint all dot-folders and dot-files in the `.config` directory, including immediate children as well as children that are deeper in the directory structure.
7177

72-
* If the path to lint is a specific file path and the `--no-ignore` flag has been passed, ESLint will lint the file regardless of the implicit ignore rules.
78+
* If the path to lint is a specific file path and the `--no-ignore` flag has been passed, ESLint would lint the file regardless of the implicit ignore rules.
7379

74-
For example, `eslint .config/my-config-file.js --no-ignore` will cause `my-config-file.js` to be linted. It should be noted that the same command without the `--no-ignore` line will not lint the `my-config-file.js` file.
80+
For example, `eslint .config/my-config-file.js --no-ignore` would cause `my-config-file.js` to be linted. It should be noted that the same command without the `--no-ignore` line would not lint the `my-config-file.js` file.
7581

7682
* Allowlist and denylist rules specified via `--ignore-pattern` or `.eslintignore` are prioritized above implicit ignore rules.
7783

@@ -105,11 +111,11 @@ You can also use your `.gitignore` file:
105111
eslint --ignore-path .gitignore file.js
106112
```
107113

108-
Any file that follows the standard ignore file format can be used. Keep in mind that specifying `--ignore-path` means that any existing `.eslintignore` file will not be used. Note that globbing rules in `.eslintignore` follow those of `.gitignore`.
114+
Any file that follows the standard ignore file format can be used. Keep in mind that specifying `--ignore-path` means that the existing `.eslintignore` file is not used. Note that globbing rules in `.eslintignore` follow those of `.gitignore`.
109115

110116
## Using eslintIgnore in package.json
111117

112-
If an `.eslintignore` file is not found and an alternate file is not specified, ESLint will look in package.json for an `eslintIgnore` key to check for files to ignore.
118+
If an `.eslintignore` file is not found and an alternate file is not specified, ESLint looks in `package.json` for the `eslintIgnore` key to check for files to ignore.
113119

114120
```json
115121
{
@@ -127,7 +133,7 @@ If an `.eslintignore` file is not found and an alternate file is not specified,
127133

128134
## Ignored File Warnings
129135

130-
When you pass directories to ESLint, files and directories are silently ignored. If you pass a specific file to ESLint, then you will see a warning indicating that the file was skipped. For example, suppose you have an `.eslintignore` file that looks like this:
136+
When you pass directories to ESLint, files and directories are silently ignored. If you pass a specific file to ESLint, then ESLint creates a warning that the file was skipped. For example, suppose you have an `.eslintignore` file that looks like this:
131137

132138
```text
133139
foo.js
@@ -150,7 +156,7 @@ foo.js
150156

151157
This message occurs because ESLint is unsure if you wanted to actually lint the file or not. As the message indicates, you can use `--no-ignore` to omit using the ignore rules.
152158

153-
Consider another scenario where you may want to run ESLint on a specific dot-file or dot-folder, but have forgotten to specifically allow those files in your `.eslintignore` file. You would run something like this:
159+
Consider another scenario where you want to run ESLint on a specific dot-file or dot-folder, but have forgotten to specifically allow those files in your `.eslintignore` file. You would run something like this:
154160

155161
```shell
156162
eslint .config/foo.js
@@ -165,4 +171,4 @@ You would see this warning:
165171
✖ 1 problem (0 errors, 1 warning)
166172
```
167173

168-
This message occurs because, normally, this file would be ignored by ESLint's implicit ignore rules (as mentioned above). A negated ignore rule in your `.eslintignore` file would override the implicit rule and reinclude this file for linting. Additionally, in this specific case, `--no-ignore` could be used to lint the file as well.
174+
This message occurs because, normally, this file would be ignored by ESLint's implicit ignore rules (as mentioned above). A negated ignore rule in your `.eslintignore` file would override the implicit rule and reinclude this file for linting. Additionally, in this case, `--no-ignore` could be used to lint the file as well.

0 commit comments

Comments
 (0)