{"record":{"id":"f56d9776d0086548","repo":"oxc-project/oxc","slug":"unexpected-empty-block-statements","errorCode":null,"errorMessage":"Unexpected empty block statements","messagePattern":"Unexpected empty block statements","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty.rs","lineNumber":15,"sourceCode":"use oxc_ast::{AstKind, ast::BlockStatement};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_empty_diagnostic(stmt_kind: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected empty block statements\")\n        .with_help(format!(\"Remove this {stmt_kind} or add a comment inside it\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoEmpty {\n    /// If set to `true`, allows an empty `catch` block without triggering the linter.\n    allow_empty_catch: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows empty block statements.\n    ///\n    /// ### Why is this bad?\n    ///","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty.rs#L1-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"A TODO placeholder such as `if (err) { /* TODO */ }`. An empty `catch` used on purpose to ignore errors. A stub left during scaffolding.","solutions":["Add a comment inside the block that states the intent, for example `// intentionally empty`.","Implement the missing body, or remove the whole statement.","For deliberate empty `catch` blocks, set `\"allowEmptyCatch\": true` in the rule config.","Suppress once with `// oxlint-disable-next-line no-empty`."],"exampleFix":"// before\ntry {\n  removeFile(path);\n} catch (e) {}\n\n// after\ntry {\n  removeFile(path);\n} catch (e) {\n  // file may already be gone; ignore\n}","handlingStrategy":"validation","validationCode":"// find suspicious empty blocks before lint\nif (/{\\s*}/.test(src)) console.warn('empty block found in file');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write the intent comment at the moment you write the empty block.","Log or rethrow in catch blocks instead of staying silent.","Decide the `allowEmptyCatch` policy once for the project."],"tags":["javascript","eslint","lint","control-flow","error-handling"],"backgroundTag":"lint-empty-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"}