Skip to content

noOctalEscape

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noOctalEscape": "error"
}
}
}
}

¥Description

禁止在字符串字面量中使用八进制转义序列

¥Disallow octal escape sequences in string literals

根据 ECMAScript 5 规范,字符串字面量中的八进制转义序列已被弃用,不应再使用。应改用 Unicode 转义序列。

¥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

¥Invalid

const foo = "Copyright \251";
code-block.js:1:24 lint/suspicious/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

const foo = "Copyright \u00A9"; // unicode escape
const bar = "Copyright \xA9"; // hexadecimal escape

¥Related links