eslint not ignoring node_modules and getting error when try to lint

5.5k Views Asked by At

I'm trying to implement eslint in a Next.js project.The file structure look like below

.eslintignore
.eslintrc.js
.next
.prettierrc
.stylelintrc.js
components
forms
modals
modules
node_modules

And I have node_modules/* in my .eslintignore file. When I try to lint these by eslint --fix /sources/**/*.js I am getting below error

You are linting "/sources/node_modules/ally.js", but all of the files matching the glob pattern "/sources/node_modules/ally.js" are ignored.

Anyone can help me to solve this? Thanks

3

There are 3 best solutions below

1
On

If .eslintignore located in the same directory as node_modules you can specify it as node_modules.

# .eslintignore
node_modules
**/.next/**
**/_next/**
**/dist/**

.eslintignore follows .gitignore syntax. See .gitignore specs for more details.

0
On

linters dosnt work same with diffrent node versions

in this case updating node to v16.x from v14.x worked for me.


if ignorefile config dosnt work for you. check your node version.

0
On

The issue might come from your command line.

If you forget the single quotes, your terminal is going to evaluate the glob (**/*), not eslint. So this will skip all eslint ignore settings.

If you enable eslint's debug logs with --debug, you will see it in action:

  • Without single quotes:
$ eslint **/*.ts --debug 2>&1 | grep "CLI args"

eslint:cli CLI args: [ 'a.ts', 'b.ts', 'node_modules/package/a.ts', 'node_modules/package/b.ts', '--debug' ]
  • With single quotes:
$ eslint '**/*.ts' --debug 2>&1 | grep "CLI args"

eslint:cli CLI args: [ '**/*.ts', '--debug' ]