oxc-project/oxc · warning
Unexpected empty static blocks
Error message
Unexpected empty static blocks
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs:9
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_empty_static_block_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected empty static blocks")
.with_help("Remove this empty block or add content to it.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoEmptyStaticBlock;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow empty static blocks.
///
/// ### Why is this bad?
///
/// Empty block statements, while not technically errors, usually occur due
/// to refactoring that wasn’t completed. They can cause confusion when
/// reading code.
///View on GitHub (pinned to e1e7af627c)
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`.
Example fix
// before
class Registry {
static {}
static items = [];
}
// after
class Registry {
static items = [];
} Defensive patterns
Strategy: validation
Validate before calling
// find empty static blocks before lint
if (/static\s*{\s*}/.test(src)) throw new Error('empty static block'); Prevention
- Use static field initializers for simple class setup.
- Delete a scaffolding block in the same commit that removes its body.
When it happens
Trigger: A class that contains `class A { static {} }`. The rule matches static block nodes during traversal and reports each one with an empty body.
Common situations: 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.
Related errors
- Duplicate class member: {member_name:?}
- `debugger` statement is not allowed
- Variables should not be deleted
- A regular expression literal can be confused with '/='.
- Duplicate conditions in if-else-if chain
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/d978a31ba3b00dfe.
Report an issue: GitHub.