New rule proposal: no-useless-backreference #12673
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
feature
This change adds a new feature to ESLint
rule
Relates to ESLint's core rules
Please describe what the rule should do:
Disallow useless backreferences in regular expressions - syntactically valid backreferences that always match zero-length and at the same time can match only zero-length, meaning that they are effectively ignored and present an almost certain error in a regular expression. In particular:
Applies to both numbered and named backreferences.
What category of rule is this? (place an "X" next to just one item)
[X] Warns about a potential error (problem)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
It prevents very possible errors in the code:
Note: this rule targets only backreferences that are parsed as such. It does not aim to disallow "look-like backreferences":
\1
...\7
should be already a parsing error, or (by Anex B) an octal escape. This should be probably an enhancement for theno-octal-escape
rule, which currently targets only strings.\8
or\9
should be a parsing error but it's usually treated as just useless identity escape.\1
...\9
in character classes. Similar to above, this is either a parsing error, octal escape or useless identity escape.u
flag) or just a sequence of characters (for backwards compatibility).Are you willing to submit a pull request to implement this rule?
Yes.
The text was updated successfully, but these errors were encountered: