Skip to content
← Back to rules

unicorn/no-console-spaces Style

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

它的作用

禁止在 console.log() 和类似方法中出现前导/尾随空格。

为什么这不好?

console.log() 方法和类似方法会用空格连接参数, 因此如果给参数添加前导/尾随空格, 就会额外插入两个空格。

示例

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

javascript
console.log("abc ", "def");

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

javascript
console.log("abc", "def");

如何使用

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

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

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

版本

此规则于 v0.0.14 中添加。

参考资料