Skip to main content

avoid-unnecessary-block

Suggests removing unnecessary blocks ({ ... }).

Blocks that do not introduce a variable that shadows an existing variable are usually unnecessary. Consider removing such blocks to reduce code nesting.

Example

❌ Bad:

void fn() {
// LINT: Avoid unnecessary code block. Try removing this block to reduce nesting.
{
print('hi');
}
}

✅ Good:

void fn() {
print('hi');

final value = 1;

{
final value = 2; // Correct, there is another variable with the same name
}
}