avoid_void_async

Group: style

Maturity: stable

Dart SDK: >= 2.1.0 • (Linter v0.1.60)

Since info is static, may be stale
has-fix

View all Lint Rules

Using the Linter

DO mark async functions as returning Future.

When declaring an async method or function which does not return a value, declare that it returns Future<void> and not just void.

BAD:

void f() async {}
void f2() async => null;

GOOD:

Future<void> f() async {}
Future<void> f2() async => null;

EXCEPTION:

An exception is made for top-level main functions, where the Future annotation can (and generally should) be dropped in favor of void.

GOOD:

Future<void> f() async {}

void main() async {
  await f();
}

Usage

To enable the avoid_void_async lint, add avoid_void_async under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - avoid_void_async