avoid-void-async

Same as avoid_void_async in Dart lints

Group
Style
Path
lint/style/avoid-void-async
Default
On (recommended)
Origin
Dart lints
Rule
185 of 512
recommended

Avoid async functions and methods declared to return void.

Callers cannot await a void result, so they cannot know when the work has finished or observe its errors. Return Future<void> instead:

void save() async {} // BAD
Future<void> save() async {} // GOOD

A top-level main and async* generators are exempt. Functions without a written return type are skipped: an override may inherit void, which only full type resolution can see.

Invalid

example.dartdart
void save() async {}

void arrow() async => print('x');

class Store {
  void flush() async {}

  static void reset() async {}

  void get refresh async {}
}

void outer() {
  void inner() async {}
  inner();
}

mixin Loader {
  void load() async {}
}

void main() async {
  void callback() async {}
  [callback].forEach((run) => run());
}
An `async` function should have a `Future` return type when it doesn't return a value.
1void save() async {}
An `async` function should have a `Future` return type when it doesn't return a value.
2
3void arrow() async => print('x');
An `async` function should have a `Future` return type when it doesn't return a value.
5class Store {
6 void flush() async {}
An `async` function should have a `Future` return type when it doesn't return a value.
7
8 static void reset() async {}
An `async` function should have a `Future` return type when it doesn't return a value.
9
10 void get refresh async {}
An `async` function should have a `Future` return type when it doesn't return a value.
13void outer() {
14 void inner() async {}
An `async` function should have a `Future` return type when it doesn't return a value.
18mixin Loader {
19 void load() async {}
An `async` function should have a `Future` return type when it doesn't return a value.
22void main() async {
23 void callback() async {}

Valid

example.dartdart
import 'dart:async';

void main() async {}

Future<void> save() async {}

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

void syncWork() {}

Stream<void> events() async* {}

FutureOr<void> maybe() async {}

class Store {
  Future<void> flush() async {}

  void syncFlush() {}

  Future<void> get refresh async {}
}

void outer() {
  Future<void> inner() async {}
  final callback = () async {};
  inner();
  callback();
}

Configure avoid-void-async

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "avoid-void-async": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/avoid-void-async: <reason>