Skip to content
← Back to rules

unicorn/empty-brace-spaces Style

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

作用

移除一对不包含额外代码的花括号内部多余的空格或换行字符。这可确保花括号内部整洁,不包含不必要的空格或换行。

为什么这不好?

花括号内的多余空格会对代码的可读性产生负面影响。保持花括号整洁且不含不必要的字符,可以提升一致性,并使代码更易于理解和维护。

示例

此规则的错误代码示例:

javascript
const a = {  };
class A {
}

此规则的正确代码示例:

javascript
const a = {};
class A {}

如何使用

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

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

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

版本

此规则在 v0.0.18 中添加。

参考