eslint: Files to be ignored depend on working directory

I’ve created a minimal reproduction repo here: https://github.com/paleite/eslintignore-bug

Tell us about your environment

Node version: v14.16.1 npm version: v7.12.1 Local ESLint version: v7.30.0 (Currently used) Global ESLint version: Not found Operating System: darwin 20.5.0

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

default

Please show your full configuration:

Configuration
console.log(`Loaded .eslintrc from the root folder. CWD is ${process.cwd()}`);

module.exports = {
  env: { es6: true, jest: true, node: true },
  extends: "eslint:recommended",
  root: true,
};

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

When running eslint with the same ignore-file from different paths, I expected the ignorefile to behave the same way, but got different results. I used 2 commands:

eslint --config $(git rev-parse --show-toplevel)/.eslintrc.js --ignore-path $(git rev-parse --show-toplevel)/.list-of-ignored-files package-a/

and

cd package-a/ && eslint --config $(git rev-parse --show-toplevel)/.eslintrc.js --ignore-path $(git rev-parse --show-toplevel)/.list-of-ignored-files .

What did you expect to happen?

I expected both commands to have the same result

What actually happened? Please copy-paste the actual, raw output from ESLint.

I got different results

Steps to reproduce this issue:

I’ve created a minimal reproduction repo here: https://github.com/paleite/eslintignore-bug The steps (as detailed in the README.md in that repo) are as follows:

npm install           # Install modules
npm run lint-absolute # Starts ESLint from the git root folder and uses the ignore-file from the git root folder
npm run lint-relative # Starts ESLint from a subfolder and uses the ignore-file from the git root folder

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

Yes.

Hopefully this is a good candidate for a new contributor.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (13 by maintainers)

Most upvoted comments

Thanks for all the research and the repo case. Given that we wanted to fix this earlier, it seems like a good idea to revisit.

I think we once again need to decide if this is a breaking change or not. Given how long the behavior has been this way, I’m leaning towards it being a breaking change but I’d like to hear what others think.

Given the tie-in with eslintrc, it seems like a good idea to wait until eslintrc is removed before considering making a change here.

I haven’t been involved in core ESLint dev for a while, but I did check out your repo @paleite, and as far as I can tell, the behavior changed / broke in 7.0.0. I didn’t dig too deeply, but if I had to guess, I’d say it is probably related to https://github.com/eslint/eslint/pull/12887, from the release notes:

Starting in ESLint v7, configuration files and ignore files passed to ESLint using the --config path/to/a-config and --ignore-path path/to/a-ignore CLI flags, respectively, will resolve from the current working directory rather than the file location. This allows for users to utilize shared plugins without having to install them directly in their project.