noNonoctalDecimalEscape
Diagnostic Category: lint/correctness/noNonoctalDecimalEscape
Since: v1.0.0
Sources:
- Same as:
no-nonoctal-decimal-escape
Disallow \8
and \9
escape sequences in string literals.
Since ECMAScript 2021, the escape sequences \8 and \9 have been defined as non-octal decimal escape sequences. However, most JavaScript engines consider them to be “useless” escapes. For example:
Although this syntax is deprecated, it is still supported for compatibility reasons. If the ECMAScript host is not a web browser, this syntax is optional. However, web browsers are still required to support it, but only in non-strict mode. Regardless of your targeted environment, it is recommended to avoid using these escape sequences in new code.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:12 lint/correctness/noNonoctalDecimalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Don’t use \8
and \9
escape sequences in string literals.
> 1 │ const x = “\8”;
│ ^^
2 │
ℹ The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
ℹ Unsafe fix: Replace \8 with 8. This maintains the current functionality.
1 │ const·x·=·“\8”;
│ -
code-block.js:1:22 lint/correctness/noNonoctalDecimalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Don’t use \8
and \9
escape sequences in string literals.
> 1 │ const x = “Don’t use \8 escape.”;
│ ^^
2 │
ℹ The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
ℹ Unsafe fix: Replace \8 with 8. This maintains the current functionality.
1 │ const·x·=·“Don’t·use·\8·escape.”;
│ -
code-block.js:1:22 lint/correctness/noNonoctalDecimalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Don’t use \8
and \9
escape sequences in string literals.
> 1 │ const x = “Don’t use \9 escape.”;
│ ^^
2 │
ℹ The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.
ℹ Unsafe fix: Replace \9 with 9. This maintains the current functionality.
1 │ const·x·=·“Don’t·use·\9·escape.”;
│ -