noUselessEscapeInRegex
Summary
Section titled “Summary”- Rule available since:
v1.9.0
- Diagnostic Category:
lint/complexity/noUselessEscapeInRegex
- This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-useless-escape
- Same as
Description
Section titled “Description”Disallow unnecessary escape sequence in regular expression literals.
Escaping non-special characters in regular expression literals doesn’t have any effect. Hence, they may confuse a reader.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”/\a/;
code-block.js:1:2 lint/complexity/noUselessEscapeInRegex FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The character doesn’t need to be escaped.
> 1 │ /\a/;
│ ^^
2 │
ℹ Safe fix: Unescape the character.
1 │ /\a/;
│ -
/[\-]/;
code-block.js:1:3 lint/complexity/noUselessEscapeInRegex FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The character doesn’t need to be escaped.
> 1 │ /[\-]/;
│ ^^
2 │
ℹ The character should only be escaped if it appears in the middle of the character class or under the v
flag.
ℹ Safe fix: Unescape the character.
1 │ /[\-]/;
│ -
/[\&]/v;
code-block.js:1:3 lint/complexity/noUselessEscapeInRegex FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The character doesn’t need to be escaped.
> 1 │ /[\&]/v;
│ ^^
2 │
ℹ Safe fix: Unescape the character.
1 │ /[\&]/v;
│ -
/\^\d\b/
/[\b]/
How to configure
Section titled “How to configure”{ "linter": { "rules": { "complexity": { "noUselessEscapeInRegex": "error" } } }}