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
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>
Copy file name to clipboardExpand all lines: docs/src/user-guide/configuring/ignoring-code.md
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,12 @@ eleventyNavigation:
8
8
9
9
---
10
10
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
+
11
17
## `ignorePatterns` in Config Files
12
18
13
19
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
31
37
32
38
## The `.eslintignore` File
33
39
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:
35
41
36
42
```text
37
43
**/*.js
38
44
```
39
45
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.
41
47
42
48
Globs are matched using [node-ignore](https://github.com/kaelzhang/node-ignore), so a number of features are available:
43
49
@@ -61,17 +67,17 @@ Please see [`.gitignore`](https://git-scm.com/docs/gitignore)'s specification fo
61
67
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:
62
68
63
69
*`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.
65
71
66
72
There are also some exceptions to these rules:
67
73
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.
69
75
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.
71
77
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.
73
79
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.
75
81
76
82
* Allowlist and denylist rules specified via `--ignore-pattern` or `.eslintignore` are prioritized above implicit ignore rules.
77
83
@@ -105,11 +111,11 @@ You can also use your `.gitignore` file:
105
111
eslint --ignore-path .gitignore file.js
106
112
```
107
113
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`.
109
115
110
116
## Using eslintIgnore in package.json
111
117
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.
113
119
114
120
```json
115
121
{
@@ -127,7 +133,7 @@ If an `.eslintignore` file is not found and an alternate file is not specified,
127
133
128
134
## Ignored File Warnings
129
135
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:
131
137
132
138
```text
133
139
foo.js
@@ -150,7 +156,7 @@ foo.js
150
156
151
157
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.
152
158
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:
154
160
155
161
```shell
156
162
eslint .config/foo.js
@@ -165,4 +171,4 @@ You would see this warning:
165
171
✖ 1 problem (0 errors, 1 warning)
166
172
```
167
173
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