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

discarded_futures lint false positive #59504

Closed
ekuleshov opened this issue Aug 8, 2024 · 0 comments
Closed

discarded_futures lint false positive #59504

ekuleshov opened this issue Aug 8, 2024 · 0 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ekuleshov
Copy link

Describe the issue
With discarded_futures lint enabled the false positive is triggered when method returning a Future is called from a non-async method and returned future is passed to another method or Flutter widget. In Flutter MultiFrameImageStreamCompleter and FutureBuilder both are taking Future as a parameter.

Similarly, a future could be assigned to a variable and used later in a method, yet still discarded_futures lint is raised.

To Reproduce
Here is a code snippet that is triggering issue. Note that FutureBuilder is usually within Flutter's build() method, which can't be async.

FutureBuilder<Widget?>(
  future: _buildImage(context, ...), // ignore: discarded_futures
  builder: (_, snapshot) => snapshot.hasData ? snapshot.data! : const Box(),
)

Where the _buildImage method is declared like this:

Future<Widget?> _buildImage(context, ...) async {
  ...get image data asynchronously
  return Image(...);
}

**Expected behavior**
This lint should not be raised when future is assigned to a a used local variable or passed down as a method or constructor parameter.

**Additional context**
N/A
@pq pq added linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Aug 9, 2024
@devoncarew devoncarew added devexp-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. labels Nov 20, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 20, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants