noOctalEscape
Summary
Section titled “Summary”- Rule available since:
v1.9.3
- Diagnostic Category:
lint/suspicious/noOctalEscape
- This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-octal-escape
- Same as
Description
Section titled “Description”Disallow octal escape sequences in string literals
As of the ECMAScript 5 specification, octal escape sequences in string literals are deprecated and should not be used. Unicode escape sequences should be used instead.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const foo = "Copyright \251";
code-block.js:1:24 lint/suspicious/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Don’t use deprecated octal escape sequences.
> 1 │ const foo = “Copyright \251”;
│ ^^^^
2 │
ℹ Safe fix: Use hexadecimal escape sequences instead.
1 │ - const·foo·=·“Copyright·\251”;
1 │ + const·foo·=·“Copyright·\xa9”;
2 2 │
const foo = "Copyright \u00A9"; // unicode escapeconst bar = "Copyright \xA9"; // hexadecimal escape
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noOctalEscape": "error" } } }}