prefer-return-await
- Group
- Performance
- Path
lint/performance/prefer-return-await- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 399 of 512
Await returned SDK Futures inside a try body protected by a catch clause.
Without awaiting, asynchronous failures bypass the local catch clauses. Function-body boundaries prevent an outer try from affecting nested closures.
Invalid
import 'dart:async';
import 'dart:async' as async;
Future<int> fetch() async => 1;
Future<int> guarded() async {
try {
return fetch();
} catch (_) { return 0; }
}
Future<int> typedCatch() async {
try {
return (fetch());
} on Exception { return 0; }
}
Future<int> branch(bool condition) async {
try {
if (condition) {
return fetch();
}
return 0;
} catch (_) { return 0; }
}
Future<int> nestedTry() async {
try {
try { return fetch(); }
finally { print('cleanup'); }
} catch (_) { return 0; }
}
async.Future<int> prefixed(async.Future<int> value) async {
try { return value; }
catch (_) { return 0; }
} try { return fetch(); try { return (fetch()); if (condition) { return fetch(); try { try { return fetch(); }async.Future<int> prefixed(async.Future<int> value) async { try { return value; }Valid
import 'dart:async';
Future<int> fetch() async => 1;
Future<int> forwarding() => fetch();
Future<int> outside() async { return fetch(); }
Future<int> arrow() async => fetch();
Future<int> awaited() async {
try { return await fetch(); } catch (_) { return 0; }
}
Future<int> scalar() async {
try { return 1; } catch (_) { return 0; }
}
Future<int> finalizerOnly() async {
try { return fetch(); } finally { print('done'); }
}
Future<int> finalizerReturn() async {
try { return 1; } catch (_) { return 0; }
finally { return fetch(); }
}
Future<int> catchReturn() async {
try { return 1; } catch (_) { return fetch(); }
}
Future<int> nested() async {
try {
Future<int> inner() async { return fetch(); }
return await inner();
} catch (_) { return 0; }
}
Future<dynamic> unknown(dynamic value) async {
try { return value; } catch (_) { return 0; }
}Configure prefer-return-await
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"performance": {
"prefer-return-await": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/performance/prefer-return-await: <reason>More performance rules
- prefer-single-setstateflutter
Merge consecutive Flutter State.setState statements in the same block.
- prefer-use-callbackflutter_hooks
Prefer
useCallbackfor synchronous memoized function literals. - prefer-use-memoflutter_hooks
Prefer memoizing freshly allocated collection values used as hook keys.
- prefer-using-list-viewflutter
Suggests considering
ListViewfor aSingleChildScrollViewcontaining a plain Flutter Column with at least two unconditional children in a list literal. - sized-box-for-whitespace
sized_box_for_whitespacerecommendedflutterFlags a
Containerused only to add fixedwidth/heightwhitespace. - unnecessary-to-list-in-spreads
unnecessary_to_list_in_spreadsrecommendedFlags a
.toList()call on the operand of a spread, e.g. - use-is-even-rather-than-modulo
use_is_even_rather_than_moduloPrefers
isEven/isOddto comparingx % 2with0or1. - use-string-buffers
use_string_buffersrecommendedPrefers a
StringBufferto growing aStringwith+inside a loop.