Enforce and fix cascade_invocations
diff --git a/pkgs/stream_transform/analysis_options.yaml b/pkgs/stream_transform/analysis_options.yaml
index c015ee7..20e06b2 100644
--- a/pkgs/stream_transform/analysis_options.yaml
+++ b/pkgs/stream_transform/analysis_options.yaml
@@ -30,7 +30,7 @@
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- #- cascade_invocations
+ - cascade_invocations
- comment_references
- constant_identifier_names
- control_flow_in_finally
diff --git a/pkgs/stream_transform/lib/src/async_map_buffer.dart b/pkgs/stream_transform/lib/src/async_map_buffer.dart
index f804666..fd25a21 100644
--- a/pkgs/stream_transform/lib/src/async_map_buffer.dart
+++ b/pkgs/stream_transform/lib/src/async_map_buffer.dart
@@ -28,9 +28,9 @@
/// pending conversions have finished.
StreamTransformer<S, T> asyncMapBuffer<S, T>(
Future<T> convert(List<S> collected)) {
- var workFinished = StreamController();
- // Let the first event through.
- workFinished.add(null);
+ var workFinished = StreamController()
+ // Let the first event through.
+ ..add(null);
return chainTransformers(
buffer(workFinished.stream), _asyncMapThen(convert, workFinished.add));
}
diff --git a/pkgs/stream_transform/lib/src/buffer.dart b/pkgs/stream_transform/lib/src/buffer.dart
index b4c937e..d09d2da 100644
--- a/pkgs/stream_transform/lib/src/buffer.dart
+++ b/pkgs/stream_transform/lib/src/buffer.dart
@@ -96,14 +96,15 @@
onError: controller.addError, onDone: onTriggerDone);
}
if (!values.isBroadcast) {
- controller.onPause = () {
- valueSub?.pause();
- triggerSub?.pause();
- };
- controller.onResume = () {
- valueSub?.resume();
- triggerSub?.resume();
- };
+ controller
+ ..onPause = () {
+ valueSub?.pause();
+ triggerSub?.pause();
+ }
+ ..onResume = () {
+ valueSub?.resume();
+ triggerSub?.resume();
+ };
}
controller.onCancel = () {
var toCancel = <StreamSubscription>[];
diff --git a/pkgs/stream_transform/lib/src/combine_latest_all.dart b/pkgs/stream_transform/lib/src/combine_latest_all.dart
index 679f3ef..16f2e80 100644
--- a/pkgs/stream_transform/lib/src/combine_latest_all.dart
+++ b/pkgs/stream_transform/lib/src/combine_latest_all.dart
@@ -87,16 +87,17 @@
});
}).toList();
if (!source.isBroadcast) {
- controller.onPause = () {
- for (var subscription in subscriptions) {
- subscription.pause();
+ controller
+ ..onPause = () {
+ for (var subscription in subscriptions) {
+ subscription.pause();
+ }
}
- };
- controller.onResume = () {
- for (var subscription in subscriptions) {
- subscription.resume();
- }
- };
+ ..onResume = () {
+ for (var subscription in subscriptions) {
+ subscription.resume();
+ }
+ };
}
controller.onCancel = () {
final toCancel = subscriptions;
diff --git a/pkgs/stream_transform/lib/src/followed_by.dart b/pkgs/stream_transform/lib/src/followed_by.dart
index 1705542..779831f 100644
--- a/pkgs/stream_transform/lib/src/followed_by.dart
+++ b/pkgs/stream_transform/lib/src/followed_by.dart
@@ -63,15 +63,16 @@
assert(subscription == null);
listen();
if (!first.isBroadcast) {
- controller.onPause = () {
- if (!firstDone || !next.isBroadcast) return subscription.pause();
- subscription.cancel();
- subscription = null;
- };
- controller.onResume = () {
- if (!firstDone || !next.isBroadcast) return subscription.resume();
- listen();
- };
+ controller
+ ..onPause = () {
+ if (!firstDone || !next.isBroadcast) return subscription.pause();
+ subscription.cancel();
+ subscription = null;
+ }
+ ..onResume = () {
+ if (!firstDone || !next.isBroadcast) return subscription.resume();
+ listen();
+ };
}
controller.onCancel = () {
if (secondDone) return null;
diff --git a/pkgs/stream_transform/lib/src/from_handlers.dart b/pkgs/stream_transform/lib/src/from_handlers.dart
index 99f71cb..4f7701d 100644
--- a/pkgs/stream_transform/lib/src/from_handlers.dart
+++ b/pkgs/stream_transform/lib/src/from_handlers.dart
@@ -64,8 +64,9 @@
_handleDone(controller);
});
if (!values.isBroadcast) {
- controller.onPause = subscription.pause;
- controller.onResume = subscription.resume;
+ controller
+ ..onPause = subscription.pause
+ ..onResume = subscription.resume;
}
controller.onCancel = () {
var toCancel = subscription;
diff --git a/pkgs/stream_transform/lib/src/merge.dart b/pkgs/stream_transform/lib/src/merge.dart
index 82aa06a..a5b4cf3 100644
--- a/pkgs/stream_transform/lib/src/merge.dart
+++ b/pkgs/stream_transform/lib/src/merge.dart
@@ -52,16 +52,17 @@
});
}).toList();
if (!first.isBroadcast) {
- controller.onPause = () {
- for (var subscription in subscriptions) {
- subscription.pause();
+ controller
+ ..onPause = () {
+ for (var subscription in subscriptions) {
+ subscription.pause();
+ }
}
- };
- controller.onResume = () {
- for (var subscription in subscriptions) {
- subscription.resume();
- }
- };
+ ..onResume = () {
+ for (var subscription in subscriptions) {
+ subscription.resume();
+ }
+ };
}
controller.onCancel = () {
var toCancel = subscriptions;
diff --git a/pkgs/stream_transform/lib/src/switch.dart b/pkgs/stream_transform/lib/src/switch.dart
index 54dc843..2f24704 100644
--- a/pkgs/stream_transform/lib/src/switch.dart
+++ b/pkgs/stream_transform/lib/src/switch.dart
@@ -58,14 +58,15 @@
if (innerSubscription == null) controller.close();
});
if (!outer.isBroadcast) {
- controller.onPause = () {
- innerSubscription?.pause();
- outerSubscription.pause();
- };
- controller.onResume = () {
- innerSubscription?.resume();
- outerSubscription.resume();
- };
+ controller
+ ..onPause = () {
+ innerSubscription?.pause();
+ outerSubscription.pause();
+ }
+ ..onResume = () {
+ innerSubscription?.resume();
+ outerSubscription.resume();
+ };
}
controller.onCancel = () {
var toCancel = <StreamSubscription>[];
diff --git a/pkgs/stream_transform/lib/src/take_until.dart b/pkgs/stream_transform/lib/src/take_until.dart
index 522ef30..62b1013 100644
--- a/pkgs/stream_transform/lib/src/take_until.dart
+++ b/pkgs/stream_transform/lib/src/take_until.dart
@@ -41,8 +41,9 @@
controller.close();
});
if (!values.isBroadcast) {
- controller.onPause = subscription.pause;
- controller.onResume = subscription.resume;
+ controller
+ ..onPause = subscription.pause
+ ..onResume = subscription.resume;
}
controller.onCancel = () {
if (isDone) return null;
diff --git a/pkgs/stream_transform/lib/src/where_type.dart b/pkgs/stream_transform/lib/src/where_type.dart
index 6e5b08f..9164f91 100644
--- a/pkgs/stream_transform/lib/src/where_type.dart
+++ b/pkgs/stream_transform/lib/src/where_type.dart
@@ -41,8 +41,9 @@
controller.close();
});
if (!source.isBroadcast) {
- controller.onPause = subscription.pause;
- controller.onResume = subscription.resume;
+ controller
+ ..onPause = subscription.pause
+ ..onResume = subscription.resume;
}
controller.onCancel = () {
subscription?.cancel();
diff --git a/pkgs/stream_transform/test/async_map_buffer_test.dart b/pkgs/stream_transform/test/async_map_buffer_test.dart
index f96092a..bf7b9d6 100644
--- a/pkgs/stream_transform/test/async_map_buffer_test.dart
+++ b/pkgs/stream_transform/test/async_map_buffer_test.dart
@@ -76,8 +76,7 @@
test('buffers values while work is ongoing', () async {
values.add(1);
await Future(() {});
- values.add(2);
- values.add(3);
+ values..add(2)..add(3);
await Future(() {});
finishWork.complete();
await Future(() {});
@@ -116,8 +115,9 @@
() async {
values.add(1);
await Future(() {});
- values.addError('error');
- values.add(2);
+ values
+ ..addError('error')
+ ..add(2);
await Future(() {});
expect(errors, ['error']);
// [work] will assert that the second iteration is not called because
diff --git a/pkgs/stream_transform/test/audit_test.dart b/pkgs/stream_transform/test/audit_test.dart
index 55a327e..71925fd 100644
--- a/pkgs/stream_transform/test/audit_test.dart
+++ b/pkgs/stream_transform/test/audit_test.dart
@@ -51,8 +51,7 @@
});
test('swallows values that come faster than duration', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await values.close();
await waitForTimer(5);
expect(emittedValues, [2]);
@@ -99,8 +98,7 @@
test('multiple listeners all get values', () async {
var otherValues = [];
transformed.listen(otherValues.add);
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await waitForTimer(5);
expect(emittedValues, [2]);
expect(otherValues, [2]);
diff --git a/pkgs/stream_transform/test/buffer_test.dart b/pkgs/stream_transform/test/buffer_test.dart
index 835a7eb..2461085 100644
--- a/pkgs/stream_transform/test/buffer_test.dart
+++ b/pkgs/stream_transform/test/buffer_test.dart
@@ -80,11 +80,9 @@
});
test('two triggers in a row - emit then emit next value', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
- trigger.add(null);
- trigger.add(null);
+ trigger..add(null)..add(null);
await Future(() {});
values.add(3);
await Future(() {});
@@ -97,8 +95,7 @@
test('pre-emptive trigger then trigger after values', () async {
trigger.add(null);
await Future(() {});
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
trigger.add(null);
await Future(() {});
@@ -109,11 +106,9 @@
});
test('multiple pre-emptive triggers, only emits first value', () async {
- trigger.add(null);
- trigger.add(null);
+ trigger..add(null)..add(null);
await Future(() {});
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [
[1]
@@ -121,12 +116,10 @@
});
test('groups values between trigger', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
trigger.add(null);
- values.add(3);
- values.add(4);
+ values..add(3)..add(4);
await Future(() {});
trigger.add(null);
await Future(() {});
diff --git a/pkgs/stream_transform/test/combine_latest_test.dart b/pkgs/stream_transform/test/combine_latest_test.dart
index cbe3050..e3987c7 100644
--- a/pkgs/stream_transform/test/combine_latest_test.dart
+++ b/pkgs/stream_transform/test/combine_latest_test.dart
@@ -52,8 +52,7 @@
.transform(combineLatest(other.stream, times))
.forEach(results.add));
- source.add('a');
- source.add('b');
+ source..add('a')..add('b');
await Future(() {});
expect(results, isEmpty);
diff --git a/pkgs/stream_transform/test/concurrent_async_map_test.dart b/pkgs/stream_transform/test/concurrent_async_map_test.dart
index 531e941..d26ed03 100644
--- a/pkgs/stream_transform/test/concurrent_async_map_test.dart
+++ b/pkgs/stream_transform/test/concurrent_async_map_test.dart
@@ -63,9 +63,7 @@
});
test('allows calls to convert before the last one finished', () async {
- streamController.add(1);
- streamController.add(2);
- streamController.add(3);
+ streamController..add(1)..add(2)..add(3);
await Future(() {});
expect(values, [1, 2, 3]);
});
diff --git a/pkgs/stream_transform/test/debounce_test.dart b/pkgs/stream_transform/test/debounce_test.dart
index a5dc4b6..aa629db 100644
--- a/pkgs/stream_transform/test/debounce_test.dart
+++ b/pkgs/stream_transform/test/debounce_test.dart
@@ -51,8 +51,7 @@
});
test('swallows values that come faster than duration', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await values.close();
await waitForTimer(5);
expect(emittedValues, [2]);
@@ -89,8 +88,7 @@
test('multiple listeners all get values', () async {
var otherValues = [];
transformed.listen(otherValues.add);
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await waitForTimer(5);
expect(emittedValues, [2]);
expect(otherValues, [2]);
@@ -104,8 +102,7 @@
});
test('Emits all values as a list', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await values.close();
await waitForTimer(5);
expect(emittedValues, [
@@ -129,8 +126,7 @@
test('multiple listeners all get values', () async {
var otherValues = [];
transformed.listen(otherValues.add);
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await waitForTimer(5);
expect(emittedValues, [
[1, 2]
diff --git a/pkgs/stream_transform/test/from_handlers_test.dart b/pkgs/stream_transform/test/from_handlers_test.dart
index d77f676..1953b29 100644
--- a/pkgs/stream_transform/test/from_handlers_test.dart
+++ b/pkgs/stream_transform/test/from_handlers_test.dart
@@ -45,8 +45,7 @@
});
test('forwards values', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [1, 2]);
});
@@ -90,8 +89,7 @@
});
test('forwards values', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [1, 2]);
expect(emittedValues2, [1, 2]);
@@ -128,8 +126,7 @@
}));
});
test('uses transform from handleData', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [2, 3]);
});
diff --git a/pkgs/stream_transform/test/switch_test.dart b/pkgs/stream_transform/test/switch_test.dart
index 8fb190d..d73e7a8 100644
--- a/pkgs/stream_transform/test/switch_test.dart
+++ b/pkgs/stream_transform/test/switch_test.dart
@@ -53,14 +53,12 @@
test('forwards events', () async {
outer.add(first.stream);
await Future(() {});
- first.add(1);
- first.add(2);
+ first..add(1)..add(2);
await Future(() {});
outer.add(second.stream);
await Future(() {});
- second.add(3);
- second.add(4);
+ second..add(3)..add(4);
await Future(() {});
expect(emittedValues, [1, 2, 3, 4]);
diff --git a/pkgs/stream_transform/test/take_until_test.dart b/pkgs/stream_transform/test/take_until_test.dart
index 3c7bb1b..e7614da 100644
--- a/pkgs/stream_transform/test/take_until_test.dart
+++ b/pkgs/stream_transform/test/take_until_test.dart
@@ -47,8 +47,7 @@
});
test('lets values through before trigger', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [1, 2]);
});
@@ -80,8 +79,7 @@
test('multiple listeners all get values', () async {
var otherValues = [];
transformed.listen(otherValues.add);
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await Future(() {});
expect(emittedValues, [1, 2]);
expect(otherValues, [1, 2]);
diff --git a/pkgs/stream_transform/test/throttle_test.dart b/pkgs/stream_transform/test/throttle_test.dart
index b0b839d..524f0c0 100644
--- a/pkgs/stream_transform/test/throttle_test.dart
+++ b/pkgs/stream_transform/test/throttle_test.dart
@@ -51,8 +51,7 @@
});
test('swallows values that come faster than duration', () async {
- values.add(1);
- values.add(2);
+ values..add(1)..add(2);
await values.close();
await waitForTimer(5);
expect(emittedValues, [1]);
diff --git a/pkgs/stream_transform/test/where_type_test.dart b/pkgs/stream_transform/test/where_type_test.dart
index 2c6d7ed..75062c2 100644
--- a/pkgs/stream_transform/test/where_type_test.dart
+++ b/pkgs/stream_transform/test/where_type_test.dart
@@ -41,8 +41,7 @@
filtered
..listen(null, onDone: () => firstDone = true)
..listen(null, onDone: () => secondDone = true);
- values.add(1);
- values.add('a');
+ values..add(1)..add('a');
await values.close();
expect(firstDone, true);
expect(secondDone, true);