8000 docs: add section about including `.gitignore` files (#18590) · eslint/eslint@455f7fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 455f7fd

Browse files
authored
docs: add section about including .gitignore files (#18590)
* docs: add section about including `.gitignore` files * fix indentation
1 parent e9f4ccd commit 455f7fd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

docs/src/use/command-line-interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ npx eslint --fix --fix-type suggestion,layout .
405405
* **Multiple Arguments**: No
406406
* **Default Value**: By default, ESLint looks for `.eslintignore` in the current working directory.
407407

408-
**Note:** `--ignore-path` is only supported when using [deprecated configuration](./configure/configuration-files-deprecated).
408+
**Note:** `--ignore-path` is only supported when using [deprecated configuration](./configure/configuration-files-deprecated). If you want to include patterns from a `.gitignore` file in your `eslint.config.js` file, please see [including `.gitignore` files](./configure/ignore#including-gitignore-files).
409409

410410
##### `--ignore-path` example
411411

docs/src/use/configure/ignore.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,27 @@ foo.js
157157
```
158158

159159
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.
160+
161+
## Including `.gitignore` Files
162+
163+
If you want to include patterns from a `.gitignore` file or any other file with gitignore-style patterns, you can use [`includeIgnoreFile`](https://github.com/eslint/rewrite/tree/main/packages/compat#including-ignore-files) utility from the [`@eslint/compat`](https://www.npmjs.com/package/@eslint/compat) package.
164+
165+
```js
166+
// eslint.config.js
167+
import { includeIgnoreFile } from "@eslint/compat";
168+
import path from "node:path";
169+
import { fileURLToPath } from "node:url";
170+
171+
const __filename = fileURLToPath(import.meta.url);
172+
const __dirname = path.dirname(__filename);
173+
const gitignorePath = path.resolve(__dirname, ".gitignore");
174+
175+
export default [
176+
includeIgnoreFile(gitignorePath),
177+
{
178+
// your overrides
179+
}
180+
];
181+
```
182+
183+
This automatically loads the specified file and translates gitignore-style patterns into `ignores` glob patterns.

0 commit comments

Comments
 (0)
0