oxc-project/oxc · warning

Unexpected empty block statements

Error message

Unexpected empty block statements

What it means

This diagnostic comes from the `no_empty` rule in oxlint. It reports block statements that contain no statements, for example `if (x) {}`. Empty blocks usually mean forgotten code or a silent swallow of something. The option `allowEmptyCatch` (default `false`) stops reports on empty `catch` blocks when set to `true`. The help text names the statement kind and suggests removal or a comment inside.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_empty.rs:15

use oxc_ast::{AstKind, ast::BlockStatement};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
};

fn no_empty_diagnostic(stmt_kind: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected empty block statements")
        .with_help(format!("Remove this {stmt_kind} or add a comment inside it"))
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoEmpty {
    /// If set to `true`, allows an empty `catch` block without triggering the linter.
    allow_empty_catch: bool,
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows empty block statements.
    ///
    /// ### Why is this bad?
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add a comment inside the block that states the intent, for example `// intentionally empty`.
  2. Implement the missing body, or remove the whole statement.
  3. For deliberate empty `catch` blocks, set `"allowEmptyCatch": true` in the rule config.
  4. Suppress once with `// oxlint-disable-next-line no-empty`.

Example fix

// before
try {
  removeFile(path);
} catch (e) {}

// after
try {
  removeFile(path);
} catch (e) {
  // file may already be gone; ignore
}
Defensive patterns

Strategy: validation

Validate before calling

// find suspicious empty blocks before lint
if (/{\s*}/.test(src)) console.warn('empty block found in file');

Prevention

When it happens

Trigger: An empty block after `if`, `for`, `while`, or `try`, such as `try { risky(); } catch (e) {}`. A block that holds only a comment states intent and is not treated as empty.

Common situations: A TODO placeholder such as `if (err) { /* TODO */ }`. An empty `catch` used on purpose to ignore errors. A stub left during scaffolding.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/f56d9776d0086548. Report an issue: GitHub.