Skip to content

noUselessEscapeInString

¥Summary

¥How to configure

biome.json
{
"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