Skip to content
← Back to rules

unicorn/consistent-template-literal-escape Style

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

它的作用

强制在模板字面量中对 ${ 采用一致的转义风格。

为什么这不好?

使用 \${ 而不是 ${ 可以提升可读性,并避免混淆。

示例

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

js
const foo = `$\{a}`;
js
const foo = `\$\{a}`;

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

js
const foo = `\${a}`;

如何使用

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

json
{
  "rules": {
    "unicorn/consistent-template-literal-escape": "error"
  }
}
ts
import { defineConfig } from "oxlint";

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

版本

此规则已在 v1.60.0 中添加。

参考资料