Skip to content

Commit 0ef25e8

Browse files
docs: simplify Ignoring Files From .eslintignore. (#1013)
The README advised ESLint >= 7 users to install node-filter-async. Replace this suggestion with a simpler implementation requiring the same number of lines of code but no dependencies. Rename the variable eslintCli to eslint since it is an instance of the ESLint Node.js API as distinct from the ESLint CLI. Avoid instantiating the API when the files staged don't necessitate invocation of ESLint.
1 parent ad4316c commit 0ef25e8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,21 +700,19 @@ module.exports = {
700700
701701
In versions of ESLint > 7, [isPathIgnored](https://eslint.org/docs/developer-guide/nodejs-api#-eslintispathignoredfilepath) is an async function and now returns a promise. The code below can be used to reinstate the above functionality.
702702
703-
This particular code uses a tiny package, [node-filter-async](https://www.npmjs.com/package/node-filter-async), to filter the files array with an async function. If you prefer to not have an extra dependency, it is quite simple to write a similar function.
704-
705703
Since [10.5.3](https://github.com/okonet/lint-staged/releases), any errors due to a bad ESLint config will come through to the console.
706704
707705
```js
708706
const { ESLint } = require('eslint')
709-
const filterAsync = require('node-filter-async').default
710-
711-
const eslintCli = new ESLint()
712707
713708
const removeIgnoredFiles = async (files) => {
714-
const filteredFiles = await filterAsync(files, async (file) => {
715-
const isIgnored = await eslintCli.isPathIgnored(file)
716-
return !isIgnored
717-
})
709+
const eslint = new ESLint()
710+
const isIgnored = await Promise.all(
711+
files.map((file) => {
712+
return eslint.isPathIgnored(file)
713+
})
714+
)
715+
const filteredFiles = files.filter((_, i) => !isIgnored[i])
718716
return filteredFiles.join(' ')
719717
}
720718

0 commit comments

Comments
 (0)