Skip to main content

avoid-redundant-async

added in: 1.6.0
🛠
Pro+
preset: recommended

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. async and then throw is shorter than return Future.error(...).
  • A value is returned and it will be implicitly wrapped in Future. async is shorter than Future.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

Additional Resources