noUselessEscapeInString
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/suspicious/noUselessEscapeInString¥Diagnostic Category:
lint/suspicious/noUselessEscapeInString -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
¥How to configure
{ "linter": { "rules": { "suspicious": { "noUselessEscapeInString": "error" } } }}¥Description
禁止在字符串字面量中使用不必要的转义。
¥Disallow unnecessary escapes in string literals.
转义字符串字面量中的非特殊字符没有任何效果。因此,它们可能会让读者感到困惑。
¥Escaping non-special characters in string literals doesn’t have any effect. Hence, they may confuse a reader.
¥Examples
¥Invalid
a::after { content: "\a"}code-block.css:2:14 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The character doesn’t need to be escaped.
1 │ a::after {
> 2 │ content: “\a”
│ ^
3 │ }
4 │
ℹ Only quotes that enclose the string and special characters need to be escaped.
ℹ Safe fix: Unescape the character.
2 │ ··content:·“\a”
│ -
a::after { content: "\'"}code-block.css:2:14 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The character doesn’t need to be escaped.
1 │ a::after {
> 2 │ content: ”\’”
│ ^
3 │ }
4 │
ℹ Only quotes that enclose the string and special characters need to be escaped.
ℹ Safe fix: Unescape the character.
2 │ ··content:·”\’”
│ -
¥Valid
a::after { content: "\""}a::after { content: "\n"}¥Related links
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/suspicious/noUselessEscapeInString¥Diagnostic Category:
lint/suspicious/noUselessEscapeInString -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
¥How to configure
{ "linter": { "rules": { "suspicious": { "noUselessEscapeInString": "error" } } }}¥Description
禁止在字符串字面量中使用不必要的转义。
¥Disallow unnecessary escapes in string literals.
转义字符串字面量中的非特殊字符没有任何效果。因此,它们可能会让读者感到困惑。
¥Escaping non-special characters in string literals doesn’t have any effect. Hence, they may confuse a reader.
¥Examples
¥Invalid
const s = "\a";code-block.js:1:13 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The character doesn’t need to be escaped.
> 1 │ const s = “\a”;
│ ^
2 │
ℹ Only quotes that enclose the string and special characters need to be escaped.
ℹ Safe fix: Unescape the character.
1 │ const·s·=·“\a”;
│ -
const o = { "\a": 0,};code-block.js:2:7 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The character doesn’t need to be escaped.
1 │ const o = {
> 2 │ “\a”: 0,
│ ^
3 │ };
4 │
ℹ Only quotes that enclose the string and special characters need to be escaped.
ℹ Safe fix: Unescape the character.
2 │ ····“\a”:·0,
│ -
const s = `${0}\a`;code-block.js:1:17 lint/suspicious/noUselessEscapeInString FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The character doesn’t need to be escaped.
> 1 │ const s = `${0}\a`;
│ ^
2 │
ℹ Only quotes that enclose the string and special characters need to be escaped.
ℹ Safe fix: Unescape the character.
1 │ const·s·=·`${0}\a`;
│ -
¥Valid
const s = "\n";在模板字面量中,\${ 和 $\{ 都是有效的转义符:
¥In template literals, \${ and $\{ are valid escapes:
const s = `\${0}`;已标记的字符串模板将被忽略:
¥Tagged string templates are ignored:
const s = tagged`\a`;JSX 字符串将被忽略:
¥JSX strings are ignored:
<div attr="str\a"/>;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号