avoid-ignoring-return-values

Same as avoid-ignoring-return-values in Dart Code Metrics

Path
lint/suspicious/avoid-ignoring-return-values
Default
Off, opt in
Origin
Dart Code Metrics
Rule
71 of 512

Flags a discarded call whose resolved return type is non-void.

Invalid

example.dartdart
// Test cases for avoid-ignoring-return-values rule
// Lines with violations have an expectation annotation

String transform(String input) => input.toUpperCase();

int compute(int x, int y) => x + y;

List<int> buildList() => [1, 2, 3];

void badUsage() {
  transform('hello');
  compute(2, 3);
  buildList();
  'hello'.toUpperCase();
  [1, 2, 3].map((x) => x * 2);
}

class Counter {
  int value = 0;

  int increment() => ++value;

  void badMethodCall() {
    increment();
  }
}

// `save` is on the receiver-less side-effect allowlist, but the project index
// sees this declaration returns a value, so discarding it is now flagged — a
// precision win the allowlist alone could not make.
int save() => 42;

void resolvedNonVoidDiscard() {
  save();
}
The return value is not being used.
10void badUsage() {
11 transform('hello');
The return value is not being used.
11 transform('hello');
12 compute(2, 3);
The return value is not being used.
12 compute(2, 3);
13 buildList();
The return value is not being used.
13 buildList();
14 'hello'.toUpperCase();
The return value is not being used.
14 'hello'.toUpperCase();
15 [1, 2, 3].map((x) => x * 2);
The return value is not being used.
23 void badMethodCall() {
24 increment();
The return value is not being used.
33void resolvedNonVoidDiscard() {
34 save();

Valid

example.dartdart
// Test cases for avoid-ignoring-return-values rule — no violations
// Return values are used or calls are void-typed.

String transform(String input) => input.toUpperCase();

int compute(int x, int y) => x + y;

List<int> buildList() => [1, 2, 3];

void goodUsage() {
  final result = transform('hello');
  final sum = compute(2, 3);
  final list = buildList();
  final upper = 'hello'.toUpperCase();
  final doubled = [1, 2, 3].map((x) => x * 2).toList();
  print('$result $sum $list $upper $doubled');
}

void voidCallsAreOk() {
  print('logging is fine');
  [1, 2, 3].forEach(print);
}

// `configure` is NOT on the side-effect allowlist, but the project index proves
// it returns void, so discarding its result is correctly not flagged — the
// resolver removes a false positive the allowlist would have raised.
void configure() {}

void resolvedVoidDiscard() {
  configure();
}

class Counter {
  int value = 0;

  int increment() => ++value;

  void goodMethodCall() {
    final newValue = increment();
    print(newValue);
  }
}

void shadowedUnknownCallee() {
  dynamic transform = () {};
  transform();
}

Configure avoid-ignoring-return-values

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "avoid-ignoring-return-values": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/suspicious/avoid-ignoring-return-values: <reason>