unnecessary_async

Experimental

No await no async.

Details

#

Functions that don't do await don't have to be async.

Usually such functions also don't have to return a Future, which allows an invoker to avoid await in its code, etc. Synchronous code in general runs faster, and is easier to reason about.

BAD:

dart
void f() async {
  // await Future.delayed(const Duration(seconds: 2));
  print(0);
}

GOOD:

dart
void f() {
  // await Future.delayed(const Duration(seconds: 2));
  print(0);
}

Enable

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - unnecessary_async

If you're instead using the YAML map syntax to configure linter rules, add unnecessary_async: true under linter > rules:

analysis_options.yaml
yaml
linter:
  rules:
    unnecessary_async: true