Skip to content

avoid_future_ignore

v1.0.0 Warning Async Safety

This rule flags Future.ignore() when no adjacent comment explains why both the result and any asynchronous error are intentionally irrelevant. It only matches Dart’s FutureExtensions.ignore, so an unrelated class with its own ignore() method is left alone.

The rule is part of the recommended preset.

unawaited(future) documents fire-and-forget execution while leaving an unexpected error visible to the current zone. future.ignore() goes further: it installs an error handler that deliberately consumes the error. That is occasionally correct, but it should be a reviewed decision rather than a convenient way to silence unawaited_futures.

An immediately preceding line or block comment exempts the call. This keeps best-effort cleanup and obsolete requests expressible while making the reason visible beside the suppression.

See also: Dart Future.ignore(), DCM avoid-future-ignore, unawaited_futures

Reaching for .ignore() to quiet an unawaited_futures warning. A failed save now vanishes with no trace anywhere:

void saveDraft(Future<void> save) {
save.ignore();
}

Keep unexpected errors observable. unawaited says “I am not waiting for this” without also saying “I do not care if it fails”:

import 'dart:async';
void saveDraft(Future<void> save) {
unawaited(save);
}

When discarding the error really is the contract

Section titled “When discarding the error really is the contract”

Write the reason immediately above the call and the rule accepts it:

void discardObsoleteRequest(Future<void> request) {
// The user typed again, so this response is obsolete — including any
// failure it produces.
request.ignore();
}

An inline block comment before the call works too, which suits a one-liner:

void pingBeacon(Future<void> ping) {
/* Best-effort analytics; a failure changes nothing. */ ping.ignore();
}

The comment must come immediately before the call. A blank line between them breaks the exemption, and a trailing comment on the same line does not count — the rule only reads comments attached ahead of the call:

// Not exempt: a blank line separates them.
void a(Future<void> f) {
// The failure is irrelevant.
f.ignore(); // still reported
}
// Not exempt: the comment trails the call.
void b(Future<void> f) {
f.ignore(); // the failure is irrelevant — still reported
}

Only Dart’s own FutureExtensions.ignore is matched, resolved by declaration. A class of your own with an ignore() method is never flagged, and neither is a call passing arguments.

To disable this rule:

many_lints.yaml
rules:
avoid_future_ignore: false

To keep the rule on but skip certain paths, use per-rule exclude.