eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.88k stars 4.5k forks source link

Bug : .eslintrc in node_modules directories are not ignored #13896

Closed pom421 closed 3 years ago

pom421 commented 3 years ago

Tell us about your environment

I am on Mac OS. Node version: v12.19.0 npm version: v6.14.8 ESLint : 7.14.0 (with the CLI, it returns vundefined (Currently used) by the --env-info helper ??)

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

babel-eslint : 10.1.0

Please show your full configuration:

Configuration ```js package.json { "name": "conferences", "version": "1.0.0", "description": "Conférences audio et vidéo pour les fonctionnaires de l'Etat", "main": "index.js", "directories": { "test": "test" }, "scripts": { "checkHTML": "site-validator --verbose --url", "checkHTMLLocal": "site-validator --verbose --local --url http://localhost:8080", "dev": "nodemon index.js", "lint": "eslint *.js */**/*.js", "fix": "eslint *.js lib/** controllers/** --fix", "migrate": "knex migrate:latest", "makeMigration": "knex migrate:make", "rollback": "knex migrate:rollback", "listMigrations": "knex migrate:list", "start": "node index.js", "test": "mocha --recursive --exit --require ./test/setup.js" }, "repository": { "type": "git", "url": "git+https://github.com/betagouv/conferences.git" }, "author": "", "license": "MIT", "bugs": { "url": "https://github.com/betagouv/conferences/issues" }, "homepage": "https://github.com/betagouv/conferences#readme", "dependencies": { "@gouvfr/design-system": "^0.2.0", "chart.js": "^2.9.4", "connect-flash": "^0.1.1", "connect-session-knex": "^2.0.0", "cron": "^1.8.2", "dotenv": "^8.2.0", "ejs": "^3.1.5", "express": "^4.17.1", "express-session": "^1.17.1", "intl": "^1.2.5", "knex": "^0.21.6", "nodemailer": "^6.4.14", "ovh": "^2.0.3", "pg": "^8.4.2" }, "devDependencies": { "chai": "^4.2.0", "chai-http": "^4.3.0", "mocha": "^8.2.0", "nodemon": "^2.0.5", "eslint": "^7.14.0", "eslint-config-node": "^4.1.0", "eslint-config-prettier": "^6.15.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.1.4", "prettier": "^2.2.0", "sinon": "^9.2.0", "site-validator-cli": "^1.3.5" } } .eslintrc.json { "extends": ["prettier", "plugin:node/recommended"], "plugins": ["prettier"], "rules": { "prettier/prettier": "error", "no-unused-vars": "warn", "no-console": "off", "func-names": "off", "no-process-exit": "off", "object-shorthand": "off" }, "ignorePatterns": ["node_modules/", "dist", ".next/"] } .eslintignore controllers/** lib/** node_modules/* **/.eslintrc node_modules/**/.eslintrc node_modules/**/.eslintrc.js node_modules/**/.eslintrc.json ```

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

# in the terminal
npm run lint 
# or
npx eslint *.js */**/*.js

What did you expect to happen?

To see the ESLint report.

What actually happened? Please include the actual, raw output from ESLint.

An error is throwed.

Oops! Something went wrong! :(

ESLint: 7.14.0

ESLint couldn't find the config "@ljharb" to extend from. Please check that the name of the config is correct.

The config "@ljharb" was referenced from the config file in "/Users/pom/workspace/conferences/node_modules/array-includes/.eslintrc".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

=> obviously, the node_modules is not ignored. It should be, because of the rules of ESLint. I even try to add it in .eslintignore (see above) but with no effect. It seems that the files like .eslintrc in node_modules (and event package.json with ESLint config in it) are detected and analysed.

It is really problematic when your project doesn't have a src directory, which prevent to have .js files at the same level than the node_modules directory.

Are you willing to submit a pull request to fix this bug?

No.

mdjermanovic commented 3 years ago

Hi @pom421, thanks for the issue!

It could be that your shell is expanding patterns, so ESLint actually gets a list of all .js files in all sub dirs, and then resolves configs for each of them starting from the subdir where the file is located.

Can you try with quotes, e.g.: npx eslint "*.js" "*/**/*.js"

pom421 commented 3 years ago

Can you try with quotes, e.g.: npx eslint "*.js" "*/**/*.js"

You're right! :) With quotes like that, it works :

npx eslint "**/*.js"

Thanks @mdjermanovic !