{"record":{"id":"4d2215ed842df674","repo":"oxc-project/oxc","slug":"nested-block-is-redundant","errorCode":null,"errorMessage":"Nested block is redundant.","messagePattern":"Nested block is redundant\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs","lineNumber":16,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_ast::ast::{Declaration, VariableDeclarationKind};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_lone_blocks_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Block is unnecessary.\")\n        .with_help(\"Remove the unnecessary block statement. If you need to limit variable scope, consider using a function or module instead.\")\n        .with_label(span)\n}\n\nfn no_nested_lone_blocks_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Nested block is redundant.\")\n        .with_help(\"Remove the redundant nested block statement.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoLoneBlocks;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows unnecessary standalone block statements.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Standalone blocks can be confusing as they do not provide any meaningful purpose when used unnecessarily.\n    /// They may introduce extra nesting, reducing code readability, and can mislead readers about scope or intent.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs#L1-L34","documentation":"Diagnostic from oxlint's eslint/no-lone-blocks rule (crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs:16). It reports a block nested inside another lone block ('{ { ... } }'). The outer block is redundant because it adds no scoping beyond the inner one; this is typically the residue of repeatedly removing wrappers or of copy-pasted code that carried its own braces.","triggerScenarios":"A block statement whose body (after skipping other nested lone blocks) is just another block: '{ { doWork(); } }'; multiple levels of nesting are each reported.","commonSituations":"Automated refactors that wrapped code in blocks; debug/feature-flag wrappers ('if (FLAG) { ... }' where the if was deleted but both brace levels remained); pasting a snippet that already had braces into another braced region.","solutions":["Collapse the nesting to a single level, then remove the remaining braces if that block is itself unnecessary","Re-run the linter after each collapse; the rule reports one diagnostic per redundant layer","Re-enable editor auto-formatting (oxfmt/prettier) so stray brace levels become visible"],"exampleFix":"// before\n{\n  {\n    doWork();\n  }\n}\n\n// after\ndoWork();","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid wrapping pasted snippets in extra braces; paste at statement level","Remove feature-flag wrappers (if (FLAG) { ... }) completely, including all brace levels","Format on save so nesting depth anomalies become visible"],"tags":["lint","javascript","blocks","dead-code","nesting","style"],"backgroundTag":"lone-block-statements","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"}