avoid-redundant-async
Checks for redundant async in a method or function body.
Cases where async is useful include:
- The function body has
await. - An error is returned asynchronously.
asyncand thenthrowis shorter than returnFuture.error(...). - A value is returned and it will be implicitly wrapped in
Future.asyncis shorter thanFuture.value(...).
Example
❌ Bad:
// LINT: This 'async' keyword is redundant. Try removing it.
Future<void> two(Future<void> first, Future<void> second) async {
return Future.wait([first, second]);
}
✅ Good:
Future<void> usesAwait(Future<String> later) async {
print(await later); // Correct, uses 'await'
}
Future<void> asyncError() async {
throw 'Error!'; // Correct, has 'throw'
}
Future<String> asyncValue() async => 'value'; // Correct, returns a value