Skip to content
← Back to rules

unicorn/no-hex-escape Pedantic

🛠️ An auto-fix is available for this rule.

作用

强制使用 Unicode 转义 而不是 十六进制转义,以保持 一致性和清晰度。

为什么这不好?

与 Unicode 转义相比,十六进制转义的可读性更差,也更难理解。

示例

以下是此规则的错误代码示例:

javascript
const foo = "\x1B";
const foo = `\x1B${bar}`;

以下是此规则的正确代码示例:

javascript
const foo = "\u001B";
const foo = `\u001B${bar}`;

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-hex-escape": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-hex-escape": "error",
  },
});
bash
oxlint --deny unicorn/no-hex-escape

版本

此规则是在 v0.0.18 中添加的。

参考资料