noNonoctalDecimalEscape
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noNonoctalDecimalEscape¥Diagnostic Category:
lint/correctness/noNonoctalDecimalEscape -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-nonoctal-decimal-escape相同¥Same as
no-nonoctal-decimal-escape
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noNonoctalDecimalEscape": "error" } } }}¥Description
禁止字符串文字中的 \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:
"\8" === "8"; // true"\9" === "9"; // true虽然此语法已弃用,但出于兼容性原因,它仍然受支持。如果 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
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.”;
│ -
¥Valid
const x = "8";const x = "Don't use \\8 and \\9 escapes.";¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号