no-empty-static-block
不允许空静态块
在 配置文件 中使用来自 @eslint/js 的 recommended 配置可以启用此规则
此规则报告的一些问题可通过编辑器 建议 手动修复
空的静态代码块,虽然在技术上不是错误,通常是由于重构未完成而出现的。它们在阅读代码时可能会引起混淆。
🌐 Empty static blocks, while not technically errors, usually occur due to refactoring that wasn’t completed. They can cause confusion when reading code.
规则详情
🌐 Rule Details
此规则不允许空的静态代码块。此规则会忽略包含注释的静态代码块。
🌐 This rule disallows empty static blocks. This rule ignores static blocks which contain a comment.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-empty-static-block: "error"*/
class Foo {
static {}
}
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-empty-static-block: "error"*/
class Foo {
static {
bar();
}
}
class Bar {
static {
// comment
}
}
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
何时不使用
🌐 When Not To Use It
此规则不应在 ES2022 之前的环境中使用。
🌐 This rule should not be used in environments prior to ES2022.
相关规则
版本
此规则是在 ESLint v8.27.0 中引入。