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

no-useless-escape false positive on chatacter classes including ] #11627

Closed
YodaDaCoda opened this issue Apr 17, 2019 · 4 comments
Closed

no-useless-escape false positive on chatacter classes including ] #11627

YodaDaCoda opened this issue Apr 17, 2019 · 4 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@YodaDaCoda
Copy link

Tell us about your environment

  • ESLint Version: v5.16.0
  • Node Version: v10.15.2
  • npm Version: 5.8.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
{
  "extends": [
    "eslint:recommended"
  ],
  "parserOptions": {
    "ecmaVersion": 2018
  },
  "env": {
    "browser": true
  },
  "globals": {
    "jQuery": "readonly"
  },
  "rules": {
    "no-global-assign": "error",
    "indent": ["warn", 2, {"MemberExpression": "off", "CallExpression": {"arguments": "off"}}],
    "linebreak-style": ["error", "unix"],
    "quotes": ["warn", "single"],
    "semi": ["error", "always"]
  }
}

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

var regex = (/[\[]/);
eslint deleteme.js

What did you expect to happen?
The regular expression should be permitted; the closing bracket ] needs to be escaped within a character class, else it signifies the end of the character class.

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

/mnt/data-ext/Work/Clouding Around/deleteme.js
  1:5   error  'regex' is assigned a value but never used  no-unused-vars
  1:16  error  Unnecessary escape character: \[            no-useless-escape

✖ 2 problems (2 errors, 0 warnings)

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

@YodaDaCoda YodaDaCoda added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Apr 17, 2019
@platinumazure
Copy link
Member

Hi @YodaDaCoda, thanks for the issue.

According to your example, the opening bracket is escaped, not the closing bracket. The opening bracket would not need to be escaped if it's already in a character class.

@platinumazure platinumazure added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Apr 17, 2019
@YodaDaCoda
Copy link
Author

My apologies, you are correct.

Upon further review, I realised that my IDE was highlighting well beyond the unnecessary escape sequence (because eslint -f json doesn't return an endColumn for the no-unnecessary-escape rule). In my attempt to produce a smaller test case for this report (my regex is ~150 chars), I'd bungled the issue.

Would it be possible to add endColumn to the result from no-unnecessary-escape? If so, should I make a separate issue for that, or change this issue?

Thanks for your assistance, and sorry again for the confusion.

@platinumazure
Copy link
Member

@YodaDaCoda No worries. Either way is fine although I think a new issue might be slightly easier for the maintainers if it's not too much trouble. And yes, for something as precisely located as an unnecessary escape, I think we probably could/should include an end location. Thanks for clarifying and for informing us about this UX issue!

@YodaDaCoda
Copy link
Author

Created #11629

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 16, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 16, 2019
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 question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

2 participants