await-only-futures

Same as await_only_futures in Dart lints

Path
lint/correctness/await-only-futures
Default
On (recommended)
Origin
Dart lints
Rule
190 of 512
recommended

Await only values assignable to futures; FutureOr, dynamic, bottom types and extension types are accepted like the analyzer. A type parameter is assignable only through a bound that is a Future subtype, so its bound gets no FutureOr or extension-type exemption. Diagnostics underline only await.

Invalid

example.dartdart
import 'dart:async';

int syncValue() => 1;

Future<void> bad(int count, String label, Object value) async {
  await count;
  await label;
  await value;
  await true;
  await syncValue();
}

Future<void> oldStyleFormal(Future<int> callback()) async {
  await callback;
}

Future<void> scoped(Future<int> future, List<int> values) async {
  {
    final future = 1;
    await future;
  }
  await future;

  for (final value in values) {
    await value;
  }

  await (() async {
    await 1;
  })();
}
Await only futures or other future-like values.
5Future<void> bad(int count, String label, Object value) async {
6 await count;
Await only futures or other future-like values.
6 await count;
7 await label;
Await only futures or other future-like values.
7 await label;
8 await value;
Await only futures or other future-like values.
8 await value;
9 await true;
Await only futures or other future-like values.
9 await true;
10 await syncValue();
Await only futures or other future-like values.
13Future<void> oldStyleFormal(Future<int> callback()) async {
14 await callback;
Await only futures or other future-like values.
19 final future = 1;
20 await future;
Await only futures or other future-like values.
24 for (final value in values) {
25 await value;
Await only futures or other future-like values.
28 await (() async {
29 await 1;

Valid

example.dartdart
import 'dart:async';

extension type FutureBox(Future<int> value) {}

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

Future<void> good<T extends Future<int>>(
  Future<int> future,
  FutureOr<int> futureOr,
  Future<int>? nullableFuture,
  dynamic anything,
  T bounded,
  FutureBox extensionValue,
) async {
  await future;
  await futureOr;
  await nullableFuture;
  await anything;
  await bounded;
  await extensionValue;
  await null;
  await asyncValue();
}

Future<void> branchBindings(bool condition, Future<int> future) async {
  if (condition)
    final future = 1;
  else
    final future = 2;
  await future;
}

Configure await-only-futures

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "await-only-futures": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/correctness/await-only-futures: <reason>