{"record":{"id":"d978a31ba3b00dfe","repo":"oxc-project/oxc","slug":"unexpected-empty-static-blocks","errorCode":null,"errorMessage":"Unexpected empty static blocks","messagePattern":"Unexpected empty static blocks","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_empty_static_block_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected empty static blocks\")\n        .with_help(\"Remove this empty block or add content to it.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoEmptyStaticBlock;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow empty static blocks.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Empty block statements, while not technically errors, usually occur due\n    /// to refactoring that wasn’t completed.  They can cause confusion when\n    /// reading code.\n    ///","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs#L1-L27","documentation":"This diagnostic comes from the `no_empty_static_block` rule in oxlint. It reports a class static initialization block (`static { ... }`, ES2022) that contains no statements. An empty static block has no effect, so it is dead code left by mistake. The report carries a label on the block span.","triggerScenarios":"A class that contains `class A { static {} }`. The rule matches static block nodes during traversal and reports each one with an empty body.","commonSituations":"A static block was planned for class-level setup, then the setup moved to the constructor or to module scope. Generated code emits the block without condition.","solutions":["Remove the empty `static {}` block.","Move the intended initialization into it, or use static field initializers.","Suppress in generated code with `// oxlint-disable-next-line no-empty-static-block`."],"exampleFix":"// before\nclass Registry {\n  static {}\n  static items = [];\n}\n\n// after\nclass Registry {\n  static items = [];\n}","handlingStrategy":"validation","validationCode":"// find empty static blocks before lint\nif (/static\\s*{\\s*}/.test(src)) throw new Error('empty static block');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use static field initializers for simple class setup.","Delete a scaffolding block in the same commit that removes its body."],"tags":["javascript","eslint","lint","classes","es2022"],"backgroundTag":"lint-empty-static-block","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}