avoid-redundant-else
preset: recommended
Checks for else
blocks that can be removed without changing semantics.
Example
❌ Bad:
class SomeClass {
String someString = '123';
void withInstance() {
if (someString == '0') {
print("Nothing to do");
return;
} else { // LINT: This 'else' block is redundant. Try moving all statements from it to the outer block and removing the 'else' block.
print("Moving on...");
}
}
}
✅ Good:
class SomeClass {
String someString = '123';
void withInstance() {
if (someString == '0') {
print("Nothing to do");
return;
}
// Correct, no longer inside 'else'
print("Moving on...");
}
}