Skip to main content

avoid-unnecessary-if

added in: 1.9.0
🛠
preset: recommended

Warns when a return statement inside an if block is equal to the return statement after it.

Example

❌ Bad:

final value = 1;

int function() {
if (value == 2) { // LINT
return 1;
}

return 1;
}

✅ Good:

final value = 1;

int function() {
if (value == 2) {
return 2;
}

return 1;
}