noUselessEscapeInRegex
诊断类别:lint/nursery/noUselessEscapeInRegex
¥Diagnostic Category: lint/nursery/noUselessEscapeInRegex
自从:v1.9.0
¥Since: v1.9.0
来源:
¥Sources:
-
与以下相同:
no-useless-escape
¥Same as:
no-useless-escape
禁止在正则表达式文字中使用不必要的转义序列。
¥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
¥Invalid
code-block.js:1:2 lint/nursery/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/nursery/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 │ /[\-]/;
│ -
code-block.js:1:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The character doesn’t need to be escaped.
> 1 │ /[\&]/v;
│ ^^
2 │
ℹ Safe fix: Unescape the character.
1 │ /[\&]/v;
│ -
¥Valid
¥Related links