prefer-early-return
added in: 1.3.0
style
Warns when an if statement can be transformed to an early return. Early returns allow to reduce the code nesting level, improving the overall readability.
Example
❌ Bad:
void someFunction() {
if (_value == 2) { // LINT
print('hello');
print(_value);
}
}
✅ Good:
void correct() {
if (_value != 2) return;
print('hello');
print(_value);
}