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 rule is not handling regex back references correctly #7472

Closed
jvswatson opened this issue Oct 28, 2016 · 3 comments
Closed
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly patch candidate This issue may necessitate a patch release in the next few days regression Something broke rule Relates to ESLint's core rules

Comments

@jvswatson
Copy link

It appears that the recent changes related to the no-useless-escape rule are not handling the integer back references (e.g. \1) correctly.

eslint: 3.9.0
node: 4.4.3
npm: 2.15.1
parser: default

.eslintrc:

{
  "rules": {
    "no-useless-escape": 2,
    "no-console": 0
  }
}

JavaScript file:

var keyword = "'the thing \"on the inside\" is what to match'";
var exactMatchPhrases = keyword.match(/(["'])(.*?)\1/g);
console.log(exactMatchPhrases);

What did you expect to happen?
No eslint errors

What actually happened? Please include the actual, raw output from ESLint.
2:51 error Unnecessary escape character: \1 no-useless-escape

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Oct 28, 2016
@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion regression Something broke patch candidate This issue may necessitate a patch release in the next few days and removed triage An ESLint team member will look at this issue soon labels Oct 28, 2016
@not-an-aardvark
Copy link
Member

Confirmed, thanks for the report.

@not-an-aardvark
Copy link
Member

I think the issue is that digits in regex literals should always be valid escapes (either they represent control characters, or they represent backreferences).

var foo = /\0/; // null character
var foo = /\1/; // \x01 character
var foo = /(a)\1/; // 2 'a' characters in a row

@ljharb
Copy link
Sponsor Contributor

ljharb commented Oct 29, 2016

Another example: /^(['"]).*\1$/

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly patch candidate This issue may necessitate a patch release in the next few days regression Something broke rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants