Skip to content
← Back to rules

eslint/no-empty-static-block 正确性

This rule is turned on by default.
💡 A suggestion is available for this rule.

功能

不允许使用空的静态块。

为什么这不好?

空的块语句虽然严格来说不是错误,但通常是由于 未完成的重构导致的。它们在阅读代码时可能会造成困惑。

示例

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

js
class Foo {
  static {}
}

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

js
class Foo {
  static {
    // 带有注释的块是允许的
  }
}
class Bar {
  static {
    doSomething();
  }
}

如何使用

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

json
{
  "rules": {
    "no-empty-static-block": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-empty-static-block": "error",
  },
});
bash
oxlint --deny no-empty-static-block

版本

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

参考资料