noOctalEscape
Summary
Section titled Summary- Rule available since:
v1.9.3
- Diagnostic Category:
lint/nursery/noOctalEscape
- 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 DescriptionDisallow 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 ExamplesInvalid
Section titled Invalidconst foo = "Copyright \251";
code-block.js:1:24 lint/nursery/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 │
Valid
Section titled Validconst foo = "Copyright \u00A9"; // unicode escapeconst bar = "Copyright \xA9"; // hexadecimal escape
How to configure
Section titled How to configure{ "linter": { "rules": { "nursery": { "noOctalEscape": "error" } } }}