Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint / IDE warning if async function is called without await #4167

Open
lewinpauli opened this issue Nov 21, 2024 · 8 comments
Open

Lint / IDE warning if async function is called without await #4167

lewinpauli opened this issue Nov 21, 2024 · 8 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@lewinpauli
Copy link

I think it would help a lot if the IDE or linter would highlight if a async function is called without a await. This could prevent some simple mistakes.

@lewinpauli lewinpauli added the feature Proposed language feature that solves one or more problems label Nov 21, 2024
@lrhn
Copy link
Member

lrhn commented Nov 21, 2024

There is a lint for that: unawaited_futures.

The lint is in the recommended lint set, so it should be enabled for all new projects created using dart create.
It only reports such calls in asynchronous functions (where you could add await). There is no corresponding lint for calling an asynchronous function from a synchronous function.

(There is a much stricter lint, discarded_futures which say you just can't call asynchronous functions from a synchronous function, you must convert the containing funtion to async. A little too strict to recommend, and often a source of confusion from people who think it is the synchronous version of unawaited_futures, partly because of the name being a little misleading.)

@lewinpauli
Copy link
Author

lewinpauli commented Nov 21, 2024

thank you for that!! just finding future methods where im not using await :)

its also good integrated into vscode

documentation:
unawaited_futures

@lewinpauli
Copy link
Author

lewinpauli commented Nov 21, 2024

Could unawaited_futures not be activated by default 🤔
should also not break any code

@lrhn
Copy link
Member

lrhn commented Nov 21, 2024

The lint is activated by default in all projects created using dart create. It's a lint, it can be disabled if you want to, but it's intended to be on by default.
If you don't use dart create to create your project, or your project is older than the lints package, the lint may not be enabled for you.

@lewinpauli
Copy link
Author

Good to know, additionally it would be nice if flutter would have this by default... But here is probably the wrong place for that request

@lrhn
Copy link
Member

lrhn commented Nov 22, 2024

I'm pretty sure flutter create also has the Flutter lints enabled, which includes the Dart recommended lints.

@lewinpauli
Copy link
Author

lewinpauli commented Nov 23, 2024

Thanks for the link of the recommended lints in dart @lrhn, but unawaited_futures seems to be missing.

In flutter stable 3.24.4 the lint of unawaited_futures only appears if manually added

@lrhn
Copy link
Member

lrhn commented Nov 23, 2024

Ack, my bad. It has been the intent to add the lint to the recommended set for still long that I've forgotten that it hasn't actually been added.
The issue for adding it is dart-lang/lints#25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants