unnecessaryBlocks
Reports standalone block statements that don't create a meaningful scope.
✅ This rule is included in the ts stylistic preset.
Standalone block statements that aren’t part of control flow structures (if/else, loops, switch, etc.) or don’t create a meaningful lexical scope can make code harder to understand.
In modern JavaScript and TypeScript, blocks primarily serve to create lexical scope for let and const variables, but using standalone blocks for this purpose is often confusing compared to other patterns like functions or modules.
Examples
Section titled “Examples”{ const temporaryValue = computeValue(); processValue(temporaryValue);}function processData() { { const result = calculate(); console.log(result); }}const temporaryValue = computeValue();processValue(temporaryValue);function processData() { const result = calculate(); console.log(result);}// Valid: block is part of control flowif (condition) { const value = getValue(); processValue(value);}// Valid: block creates scope in switch caseswitch (type) { case "a": { const value = getA(); break; }}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you frequently use standalone blocks for visual organization or temporary scoping in ways that your team finds helpful, you might choose to disable this rule. However, consider whether extracting to functions or using other scoping mechanisms would be clearer.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noUselessLoneBlockStatements - ESLint:
no-lone-blocks - Oxlint:
eslint/no-lone-blocks