avoid-nested-futures
preset: recommended
Warns when a Future
type contains another Future
.
Usually, nested Futures
highlight a problem in code design. Consider rewriting the code instead of nesting Futures
.
Example
❌ Bad:
// LINT: Avoid nested 'Futures'. Try rewriting the code to remove nesting.
Future<Future<int>> function() async => ...;
// LINT: Avoid nested 'Futures'. Try rewriting the code to remove nesting.
FutureOr<Future<int>> function() async => ...;
// LINT: Avoid nested 'Futures'. Try rewriting the code to remove nesting.
FutureOr<FutureOr<int>> function() async => ...;
✅ Good:
Future<int> function() async => ...; // Correct, no nested Future
FutureOr<int> function() async => ...;