Skip to content

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.

{
const temporaryValue = computeValue();
processValue(temporaryValue);
}
function processData() {
{
const result = calculate();
console.log(result);
}
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.