
no-empty-static-block
禁止空的靜態區塊
✅ 推薦
在設定檔中使用 @eslint/js
的 recommended
設定會啟用此規則
空的靜態區塊雖然在技術上不是錯誤,但通常是由於未完成的重構所造成。它們在閱讀程式碼時可能會造成混淆。
規則詳細資訊
此規則禁止空的靜態區塊。此規則會忽略包含註解的靜態區塊。
此規則的錯誤程式碼範例
在遊樂場開啟
/*eslint no-empty-static-block: "error"*/
class Foo {
}
此規則的正確程式碼範例
在遊樂場開啟
/*eslint no-empty-static-block: "error"*/
class Foo {
static {
bar();
}
}
class Bar {
static {
// comment
}
}
何時不應使用
此規則不應在 ES2022 之前的環境中使用。
相關規則
版本
此規則在 ESLint v8.27.0 中引入。
延伸閱讀
