Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: can't escape ] in .eslintignore #15642

Closed
1 task
beltekylevi opened this issue Feb 25, 2022 · 5 comments · Fixed by eslint/eslintrc#72 or #15666
Closed
1 task

Bug: can't escape ] in .eslintignore #15642

beltekylevi opened this issue Feb 25, 2022 · 5 comments · Fixed by eslint/eslintrc#72 or #15666
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features repro:yes
Projects

Comments

@beltekylevi
Copy link

Environment

Node version: v14.17.0
npm version: v8.3.0
Local ESLint version: v8.9.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 21.2.0

What parser are you using?

Default (Espree)

What did you do?

Configuration
module.exports = {
  rules: {
    "no-console": "error",
  },
};

I've set up minimal example repository to reproduce the issue but I'll describe the issue here as well.

I have a few files and some of them contain special characters like [.

➜  eslint-eslintignore-glob-pattern-issue git:(main) ✗ find src
src
src/index].js
src/[index].js
src/index.js
src/[index.js

I'd like to ignore all of them so I have them listed in an .eslintignore using \ to escape the special characters.

➜  eslint-eslintignore-glob-pattern-issue git:(main) ✗ cat .eslintignore 
src/index.js
src/\[index.js
src/index\].js
src/\[index\].js

What did you expect to happen?

All files listed in .eslintignore to be ignored, zero errors.

What actually happened?

Two of the files won't be ignored when I lint them using ESLint.

➜  eslint-eslintignore-glob-pattern-issue git:(main) ✗ npm run lint

> eslint-eslintignore-glob-pattern-issue@1.0.0 lint
> eslint '**/*.js' --ignore-path .eslintignore


[removed]/eslint-eslintignore-glob-pattern-issue/src/[index].js
  1:1  error  Unexpected console statement  no-console

[removed]/eslint-eslintignore-glob-pattern-issue/src/index].js
  1:1  error  Unexpected console statement  no-console

✖ 2 problems (2 errors, 0 warnings)

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

The same glob patterns work in .gitignore.

➜  eslint-eslintignore-glob-pattern-issue git:(main) cat .gitignore
node_modules/
src/\[app\].js
src/app\].js
➜  eslint-eslintignore-glob-pattern-issue git:(main) git status --ignored
On branch main
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)
        node_modules/
        src/[app].js
        src/app].js

nothing to commit, working tree clean
@beltekylevi beltekylevi added bug ESLint is working incorrectly repro:needed labels Feb 25, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Feb 25, 2022
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Feb 25, 2022
@mdjermanovic
Copy link
Member

Hi @beltekylevi, thanks for the issue!

This seems to be a bug in ignore v4.0.6:

const ignore = require("ignore");

// logs `false` with ignore v4.0.6, `true` with ignore v5.2.0
console.log(
    ignore().add("src/\\[index\\].js").ignores("src/[index].js")
);

The bug was fixed in v5.1.5 ("fixes escaping for square brackets"), but @eslint/eslintrc still uses v4.0.6.

We could update the dependency in @eslint/eslintrc to "ignore": "^5.2.0" and this issue would most likely be fixed (we would certainly add tests to confirm). Since ignore v5 has a breaking change, we should probably use it with { allowRelativePaths: true } option to get the v4 behavior that eslintrc might be relying on, as we did in #15439 for eslint/eslint.

That update seems a bit risky though, and eslintrc will be replaced by the new config system in the next major release anyway.

@nzakas what do you think, should we switch to ignore v5.2.0 in @eslint/eslintrc and see what happens?

@mdjermanovic mdjermanovic added core Relates to ESLint's core APIs and features repro:yes and removed repro:needed labels Feb 25, 2022
@mdjermanovic mdjermanovic moved this from Triaging to Feedback Needed in Triage Feb 25, 2022
@nzakas
Copy link
Member

nzakas commented Feb 26, 2022

I’d like to avoid anything that changes how eslintrc behaves at this point, as that will make the new config system work more complicated. If we can upgrade without affecting any existing tests, then I think that’s okay, but if we need to change any existing tests then we should wait for the new config system.

@snitin315
Copy link
Contributor

I tried upgrading ignore in eslint/eslintrc#72 and it doesn't affect any existing tests.

Triage automation moved this from Feedback Needed to Complete Mar 4, 2022
@snitin315
Copy link
Contributor

Let's keep it open until we update eslintrc in eslint itself. - #15666

@snitin315 snitin315 reopened this Mar 4, 2022
Triage automation moved this from Complete to Evaluating Mar 4, 2022
@snitin315 snitin315 moved this from Evaluating to Pull Request Opened in Triage Mar 4, 2022
Triage automation moved this from Pull Request Opened to Complete Mar 11, 2022
mdjermanovic added a commit that referenced this issue Mar 11, 2022
* fix: escaping for square brackets in ignore patterns

Fixes #15642

* remove file to fix its filename

* re-add file to fix its filename

* use github:eslint/eslintrc main branch

* use @eslint/eslintrc@1.2.1
@beltekylevi
Copy link
Author

Many thanks for your work.

srijan-deepsource pushed a commit to DeepSourceCorp/eslint that referenced this issue May 30, 2022
* fix: escaping for square brackets in ignore patterns

Fixes eslint#15642

* remove file to fix its filename

* re-add file to fix its filename

* use github:eslint/eslintrc main branch

* use @eslint/eslintrc@1.2.1
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Sep 8, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features repro:yes
Projects
Archived in project
Triage
Complete
4 participants