Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

[BUG] avoid-redundant-async does not handle case where return value may be null #1147

Closed
maxlapides opened this issue Jan 10, 2023 · 3 comments
Assignees
Labels
area-rules type: bug Something isn't working
Milestone

Comments

@maxlapides
Copy link

  • Dart code metrics version: 5.4.0
  • Dart sdk version: 2.18.6

What did you do? Please include the source code example causing the issue.

RefreshIndicator(
  onRefresh: () async {
    if (shouldRefresh) return apiCall();
  }
)

https://api.flutter.dev/flutter/material/RefreshIndicator-class.html

What did you expect to happen?

In this case, the onRefresh function may return a Future when shouldRefresh is true. But, when shouldRefresh is false, the function returns null. So the async keyword is needed, but we are getting a lint error for avoid-redundant-async

What actually happened?

'async' keyword is redundant, consider removing it.
dart[avoid-redundant-async](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async)

If the async keyword is removed, we get this analysis error:

The body might complete normally, causing 'null' to be returned, but the return type, 'Future<void>', is a potentially non-nullable type.
Try adding either a return or a throw statement at the end. body_might_complete_normally

Are you willing to submit a pull request to fix this bug?
Maybe :)

@incendial incendial added this to the 5.5.0 milestone Jan 11, 2023
@incendial
Copy link
Member

incendial commented Jan 11, 2023

This one is tricky. I'll fix this specific case with the if statement, but if you have an option to add another return, I'd recommend to move that way.

@incendial
Copy link
Member

Fixed in 5.5.0 🚀

@incendial incendial removed the waiting for release Will be available after new version is released label Jan 23, 2023
@maxlapides
Copy link
Author

Thanks so much @incendial!

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area-rules type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants