noUselessEscapeInString
Summary
Section titled “Summary”- Rule available since:
v2.0.0
- Diagnostic Category:
lint/nursery/noUselessEscapeInString
- This rule has a safe fix.
- The default severity of this rule is warning.
Description
Section titled “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
Section titled “Examples”Invalid
Section titled “Invalid”a::after { content: "\a"}
code-block.css:2:14 lint/nursery/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/nursery/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:·”\’”
│ -
a::after { content: "\""}
a::after { content: "\n"}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessEscapeInString": "error" } } }}
Related links
Section titled “Related links”Summary
Section titled “Summary”- Rule available since:
v2.0.0
- Diagnostic Category:
lint/nursery/noUselessEscapeInString
- This rule has a safe fix.
- The default severity of this rule is warning.
Description
Section titled “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
Section titled “Examples”Invalid
Section titled “Invalid”const s = "\a";
code-block.js:1:13 lint/nursery/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/nursery/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/nursery/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}<span style="color: Tomato;">\</span>a
;
│ -
const s = "\n";
Tagged string template are ignored:
const s = tagged`\a`;
JSX strings are ignored:
<div attr="str\a"/>;
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessEscapeInString": "error" } } }}