oxc-project/oxc · warning · OxcDiagnostic
Nested block is redundant.
Error message
Nested block is redundant.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs:16
use oxc_ast::AstKind;
use oxc_ast::ast::{Declaration, VariableDeclarationKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_lone_blocks_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Block is unnecessary.")
.with_help("Remove the unnecessary block statement. If you need to limit variable scope, consider using a function or module instead.")
.with_label(span)
}
fn no_nested_lone_blocks_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Nested block is redundant.")
.with_help("Remove the redundant nested block statement.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoLoneBlocks;
declare_oxc_lint!(
/// ### What it does
///
/// Disallows unnecessary standalone block statements.
///
/// ### Why is this bad?
///
/// Standalone blocks can be confusing as they do not provide any meaningful purpose when used unnecessarily.
/// They may introduce extra nesting, reducing code readability, and can mislead readers about scope or intent.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
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
Example fix
// before
{
{
doWork();
}
}
// after
doWork(); Defensive patterns
Strategy: validation
Prevention
- 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
When it happens
Trigger: A block statement whose body (after skipping other nested lone blocks) is just another block: '{ { doWork(); } }'; multiple levels of nesting are each reported.
Common situations: 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.
Related errors
- Block is unnecessary.
- Duplicate class member: {member_name:?}
- Duplicate conditions in if-else-if chain
- Duplicate key '{key}'
- Duplicate case label
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/4d2215ed842df674.
Report an issue: GitHub.