Skip to content
← Back to rules

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

This rule is turned on by default.
An auto-fix is available for this rule.

它的作用

禁止使用空的静态块

为什么这是不好的?

空的代码块语句虽然在技术上不是错误,但通常是因为重构未完成导致的。在阅读代码时,它们可能会引起混淆。

示例

此规则的错误代码示例:

js
class Foo {
  static {}
}

此规则的正确代码示例:

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

如何使用

要通过配置文件或命令行界面启用此规则,可以使用:

json
{
  "rules": {
    "no-empty-static-block": "error"
  }
}
bash
oxlint --deny no-empty-static-block

参考资料