Skip to main content

avoid-returning-void

has auto-fix
pro+

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() {
// LINT: Avoid returning void expressions. Try calling the expression separately.
return someVoidFunction();
}

Future<void> asyncFn() async {
// LINT: Avoid returning void expressions. Try calling the expression separately.
return someVoidFunction();
}

✅ Good:

void someVoidFunction() {
...
}

void someFunction() {
someVoidFunction(); // Correct, invoked separately

return;
}

Future<void> asyncFn() async {
someVoidFunction();

return;
}