avoid-ignoring-return-values
Same as avoid-ignoring-return-values in Dart Code Metrics
- Group
- Suspicious
- 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
// 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();
}void badUsage() { transform('hello'); transform('hello'); compute(2, 3); compute(2, 3); buildList(); buildList(); 'hello'.toUpperCase(); 'hello'.toUpperCase(); [1, 2, 3].map((x) => x * 2); void badMethodCall() { increment();void resolvedNonVoidDiscard() { save();Valid
// 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.
{
"linter": {
"rules": {
"suspicious": {
"avoid-ignoring-return-values": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-ignoring-return-values: <reason>More suspicious rules
- avoid-incorrect-uri
Reject runtime-invalid Uri constructor arguments: conflicting path or query inputs and query parameter values that are neither null, strings nor iterables of strings.
- avoid-inverted-boolean-checks
Prefer direct equality comparisons and De Morgan forms in control-flow conditions.
- avoid-multi-assignment
Split chained assignments into separate statements.
- avoid-mutating-parameters
Detects writes through named function, method and constructor parameter objects.
- avoid-negated-conditions
Prefer positive conditions when both branches can be swapped.
- avoid-nested-assignments
Require assignments to be standalone statements, arrow bodies or loop operations.
- avoid-non-final-exception-class-fields
Exception and Error payloads should not change after construction.
- avoid-passing-async-when-sync-expected
avoid-passing-async-when-sync-expectedrecommendedFlags an
asyncclosure passed to a proven synchronous callback parameter.