noNonoctalDecimalEscape
诊断类别:lint/correctness/noNonoctalDecimalEscape
¥Diagnostic Category: lint/correctness/noNonoctalDecimalEscape
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-nonoctal-decimal-escape
¥Same as:
no-nonoctal-decimal-escape
禁止字符串文字中的 \8
和 \9
转义序列。
¥Disallow \8
and \9
escape sequences in string literals.
自 ECMAScript 2021 以来,转义序列 \8 和 \9 已被定义为非八进制十进制转义序列。但是,大多数 JavaScript 引擎将它们视为 “useless” 转义。例如:
¥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:
虽然此语法已弃用,但出于兼容性原因,它仍然受支持。如果 ECMAScript 主机不是 Web 浏览器,则此语法是可选的。但是,仍然需要 Web 浏览器来支持它,但只能在非严格模式下支持。无论你的目标环境如何,建议避免在新代码中使用这些转义序列。
¥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
¥Invalid
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.
ℹ 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.”;
│ -
¥Valid
¥Related links