proposal: lint to catch unawaited futures in try blocks #59155
Labels
analyzer-linter
Issues with the analyzer's support for the linter package
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
linter-lint-proposal
linter-status-pending
The gotcha occurs when you return
Future<T>
fromFuture<T> foo async {}
instead ofT
and that return is inside atry
block.https://twitter.com/_eseidel/status/1660092263190650881
https://dartpad.dev/?id=f4c93eb9f9e24d43079cbc859a867894
Would love a lint that would have caught that (and saved me -- and clearly others according to responses on that twitter thread) a while of searching for the issue.
Discussion checklist
unawaited_futures
could have some overlap, although it doesn't trigger here.unnecessary_await_in_return
seems in direct conflict.List any relevant issues (reported here, the [SDK Tracker], or elsewhere).
If there's any prior art (e.g., in other linters), please add references here.
https://dcm.dev/docs/teams/rules/common/prefer-return-await/
If this proposal corresponds to [Effective Dart] or [Flutter Style Guide] advice, please call it out. (If there isn't any corresponding advice, should there be?)
If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.
Arguably the real bug is that
Future<T> foo async {}
allows returningFuture<T>
directly at all, since it nominally expects you to return aT
. But presumably that's an intentional language decision.The text was updated successfully, but these errors were encountered: