Skip to content

avoid_redundant_async

v1.0.0 Warning Async Safety

This rule flags a function marked async whose body never awaits or throws, and whose return paths already produce compatible Future values. Removing async is therefore a cleanup that keeps the code compiling.

The rule is part of the opinionated preset.

async without await is not automatically redundant. It still wraps a raw return value in a future and converts a synchronous throw into an asynchronous error. In both cases removing it would change semantics or produce code that does not compile, so the rule deliberately stays silent.

A function whose paths already return futures needs no async for callers to await it. The rule checks the resolved types of every explicit return before reporting and leaves fall-through or bare-return bodies alone.

Other cases left alone include async*, where the keyword makes the function a stream generator, and an @override, whose implementation details should not be rewritten by this cleanup rule.

See also: Dart asynchrony support

Future<List<Config>> loadAll() async {
return Future.wait(_pending);
}
Future<List<Config>> loadAll() {
return Future.wait(_pending);
}

Returning a raw value is valid and is not reported, because async performs the required wrapping:

Future<int> count() async => 1;

To disable this rule:

many_lints.yaml
rules:
avoid_redundant_async: false

To keep the rule on but skip certain paths, use per-rule exclude.