Перейти до вмісту

noNonoctalDecimalEscape

Цей контент ще не доступний вашою мовою.

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:

"\8" === "8"; // true
"\9" === "9"; // true

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.

const x = "\8";
code-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.

Safe fix: Replace \8 with 8. This maintains the current functionality.

1 │ const·x·=·\8”;
-
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 \8 escape.”;
^^
2 │

The nonoctal decimal escape is a deprecated syntax that is left for compatibility and should not be used.

Safe fix: Replace \8 with 8. This maintains the current functionality.

1 │ const·x·=·“Don’t·use·\8·escape.”;
-
const x = "Don't use \9 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.

Safe fix: Replace \9 with 9. This maintains the current functionality.

1 │ const·x·=·“Don’t·use·\9·escape.”;
-
const x = "8";
const x = "Don't use \\8 and \\9 escapes.";
biome.json
{
"linter": {
"rules": {
"correctness": {
"noNonoctalDecimalEscape": "error"
}
}
}
}