avoid-nested-streams-and-futures

Path
lint/correctness/avoid-nested-streams-and-futures
Default
Off, opt in
Origin
Falcon
Rule
101 of 512

Avoid directly nesting SDK streams and futures: Stream<Future<T>> and Future<Stream<T>> complicate consumption. Use asyncMap/asyncExpand, or expose a single Stream<T> instead of a future that produces a stream.

FutureOr is also future-like. Explicit type occurrences and typedef expansions are checked with lexical type-parameter scopes; stream-of-stream and future-of-future types are outside this rule. Inferred-only types are not reported.

Reference: https://dcm.dev/docs/rules/common/avoid-nested-streams-and-futures/

Invalid

example.dartdart
import 'dart:async';
import 'dart:async' as async;

Stream<Future<int>>? first;
Future<Stream<int>>? second;
Stream<FutureOr<int>>? third;
FutureOr<Stream<String>>? fourth;
async.Stream<async.Future<int>>? prefixed;
void consume(Future<Stream<void>> value) {}
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
3
4Stream<Future<int>>? first;
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
4Stream<Future<int>>? first;
5Future<Stream<int>>? second;
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
5Future<Stream<int>>? second;
6Stream<FutureOr<int>>? third;
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
6Stream<FutureOr<int>>? third;
7FutureOr<Stream<String>>? fourth;
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
7FutureOr<Stream<String>>? fourth;
8async.Stream<async.Future<int>>? prefixed;
Remove the nested stream/future wrapper; expose a single asynchronous sequence.
8async.Stream<async.Future<int>>? prefixed;
9void consume(Future<Stream<void>> value) {}

Valid

example.dartdart
import 'dart:async';

Stream<int>? sequence;
Future<int>? result;
FutureOr<int>? maybe;
Stream<Stream<int>>? sequences;
Future<Future<int>>? nestedFuture;
Future<List<Stream<int>>>? batches;
Stream<List<Future<int>>>? jobs;
Future<Stream<int> Function()>? callback;

Configure avoid-nested-streams-and-futures

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-nested-streams-and-futures": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/avoid-nested-streams-and-futures: <reason>