await-only-futures
Same as await_only_futures in Dart lints
- Group
- Correctness
- Path
lint/correctness/await-only-futures- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 190 of 512
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
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;
})();
}Future<void> bad(int count, String label, Object value) async { await count; await count; await label; await label; await value; await value; await true; await true; await syncValue();Future<void> oldStyleFormal(Future<int> callback()) async { await callback; final future = 1; await future; for (final value in values) { await value; await (() async { await 1;Valid
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.
{
"linter": {
"rules": {
"correctness": {
"await-only-futures": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/await-only-futures: <reason>More correctness rules
- banned-importscross-file
Report imports forbidden by package-relative architectural boundaries.
- cancel-subscriptions
cancel_subscriptionsrecommendedCancel instances of
dart:asyncStreamSubscription. - check-is-not-closed-after-async-gaprecommendedbloc
Flags Bloc
addandemitcalls after an await without a freshisClosedcheck. - close-sinks
close_sinksrecommendedClose instances of
dart:coreSink. - collection-methods-unrelated-type
collection_methods_unrelated_typerecommendedReports collection lookups whose argument type is unrelated to the collection's type argument.
- comment-references
comment_referencesrecommendedFlags doc-comment references
[name]that resolve to nothing in scope. - correct-order-for-super-dispose
correct_order_for_super_disposerecommendedflutterRequire
super.dispose()to be the last call indispose. - depend-on-referenced-packages
depend_on_referenced_packagesrecommendedcross-fileRequire imported packages to be declared in
pubspec.yaml.