avoid-returning-void
Suggests calling functions or methods with a void
return type separately from the return statement.
Returning void
invocations can be confusing for code reviewers and introduce unnecessary changes if the return type changes.
Example
❌ Bad:
void someVoidFunction() {
...
}
void someFunction() {
return someVoidFunction(); // LINT: Avoid returning void expressions. Try calling the expression separately.
}
Future<void> asyncFn() async {
return someVoidFunction(); // LINT: Avoid returning void expressions. Try calling the expression separately.
}
✅ Good:
void someVoidFunction() {
...
}
void someFunction() {
someVoidFunction(); // Correct, invoked separately
return;
}
Future<void> asyncFn() async {
someVoidFunction();
return;
}