Bug: [new config system] `.eslintignore` doesn't work like `.gitignore`
See original GitHub issueEnvironment
Node version: v16.14.0 npm version: v8.3.1 Local ESLint version: v8.23.0 (Currently used) Global ESLint version: Not found Operating System: win32 10.0.19044
What parser are you using?
Default (Espree)
What did you do?
# .eslintignore
foo/
!bar.js
// eslint.config.js
module.exports = [{
rules: {
semi: "error"
}
}];
// foo/bar.js
a
npx eslint foo/bar.js
What did you expect to happen?
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
Per the .gitignore specification, foo/bar.js
should be ignored because it is not possible to re-include a file if a parent directory of that file is excluded. With an equivalent .eslintrc.js
config file in place of the eslint.config.js
config file, foo/bar.js
would be ignored.
What actually happened?
1:2 error Missing semicolon semi
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
Participation
- I am willing to submit a pull request for this issue.
Additional comments
There may be other differences between the .gitignore spec and our custom interpretation of the patterns, so it might be better to keep using the ignore
library (assuming that .eslintignore
should still behave like .gitignore
).
Issue Analytics
- State:
- Created a year ago
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Ignoring Code - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >git - Gitignore not working - Stack Overflow
There is one simple reason why sometimes the .gitignore doesn`t work like it is supposed to. It is due to the EOL conversion...
Read more >eslint-plugin-import - npm
Start using eslint-plugin-import in your project by running `npm i ... when .eslintignore will be updated to work more like a .gitignore ......
Read more >Configure Prettier and ESLint with Angular | by Enea Jahollari
In this section, I will explain how to install ESLint in an Angular project and also configure it to better align with the...
Read more >eslint | Yarn - Package Manager
Make sure your plugins (and ESLint) are both in your project's package.json as devDependencies (or dependencies, if your project uses ESLint at runtime)....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know this is already closed out, but just wanted to add my thoughts.
Almost every project that uses ESLint also uses
git
(ESLint sort of acknowledges this by ignoring.git/**
by default) and almost everygit
project has a.gitignore
file.There’s virtually no scenario where someone running ESLint on a project with a
.gitignore
wants ESLint to run over the ignored files. The developer will always want ESLint to ignore those files. So it seems that by removing this functionality, almost every project using ESLint will have to duplicate its ignore rules between.gitignore
and the ESLint config. This is unfortunate because the two configs could easily become out of sync. People won’t like that so inevitably they will try to come up with ways to generate the ESLint ignore patterns from their.gitignore
files.If that’s where we’d likely end up, then I wonder why not bake this functionality into ESLint to avoid N different userland solutions for the problem? I get that it’s a complex issue, but it seems like scoping it out of ESLint would just push the problem into userland, which doesn’t seem desirable.
I’ve been looking more deeply into this, and here’s what I think is the best path forward:
baseConfig
andoverrideConfig
should both be relative to thebasePath
in the config array. I think it would be too confusing to try to make both of those relative tocwd
. Because these are both API options (baseConfig
isn’t used through the CLI at all), I think it’s fair to just explain in the docs thatbaseConfig
andoverrideConfig
are essentially inserted into the array returned fromeslint.config.js
.ignorePatterns
as an option toFlatESLint
so that--ignore-pattern
can be added outside ofoverrideConfig
. I do agree that--ignore-pattern
would be expected to be relative tocwd
.What do you think?