跳转到内容

noUselessEscapeInRegex

此内容尚不支持你的语言。

Diagnostic Category: lint/nursery/noUselessEscapeInRegex

Since: v1.9.0

Sources:

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.

/\a/;
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 │ /[\-]/;
-
/[\&]/v;
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;
-
/\^\d\b/
/[\b]/