Enable prefer_typing_uninitialized_variables (#63)
This helps rule out some possibilities for the new Dart 2 failure and is
good practice.
Also:
- Update dependencies on build and test packages.
- Ignore todo from the analysis server.
- Move off of deprecated APIs from test.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index a10d4c5..80d2368 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,2 +1,7 @@
analyzer:
strong-mode: true
+ errors:
+ todo: ignore
+linter:
+ rules:
+ - prefer_typing_uninitialized_variables
diff --git a/lib/src/result/error.dart b/lib/src/result/error.dart
index 45e06a2..2feb2c2 100644
--- a/lib/src/result/error.dart
+++ b/lib/src/result/error.dart
@@ -10,7 +10,7 @@
/// A result representing a thrown error.
class ErrorResult implements Result<Null> {
/// The error object that was thrown.
- final error;
+ final Object error;
/// The stack trace corresponding to where [error] was thrown.
final StackTrace stackTrace;
diff --git a/lib/src/result/result.dart b/lib/src/result/result.dart
index 98b5aa4..25503b5 100644
--- a/lib/src/result/result.dart
+++ b/lib/src/result/result.dart
@@ -98,7 +98,7 @@
static Future<List<Result<T>>> captureAll<T>(Iterable<FutureOr<T>> elements) {
var results = <Result<T>>[];
int pending = 0;
- var completer;
+ Completer<List<Result<T>>> completer;
for (var element in elements) {
if (element is Future<T>) {
int i = results.length;
diff --git a/lib/src/single_subscription_transformer.dart b/lib/src/single_subscription_transformer.dart
index f590860..ff17189 100644
--- a/lib/src/single_subscription_transformer.dart
+++ b/lib/src/single_subscription_transformer.dart
@@ -17,7 +17,7 @@
const SingleSubscriptionTransformer();
Stream<T> bind(Stream<S> stream) {
- var subscription;
+ StreamSubscription<S> subscription;
var controller = new StreamController<T>(
sync: true, onCancel: () => subscription.cancel());
subscription = stream.listen((value) {
diff --git a/pubspec.yaml b/pubspec.yaml
index e1ca801..36246c2 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,17 +1,17 @@
name: async
-version: 2.0.7
+version: 2.0.8-dev
author: Dart Team <misc@dartlang.org>
description: Utility functions and classes related to the 'dart:async' library.
homepage: https://www.github.com/dart-lang/async
environment:
sdk: ">=2.0.0-dev.23.0 <2.0.0"
dependencies:
- collection: "^1.5.0"
+ collection: ^1.5.0
dev_dependencies:
- fake_async: ">=0.1.2 <2.0.0"
- stack_trace: "^1.0.0"
- test: "^0.12.0"
+ fake_async: ^1.0.0
+ stack_trace: ^1.0.0
+ test: ^1.0.0
# For building and testing with DDC
- build_runner: ^0.7.11
- build_web_compilers: ^0.3.1
+ build_runner: ^0.8.0
+ build_web_compilers: ^0.4.0
build_test: ^0.10.1
diff --git a/test/async_memoizer_test.dart b/test/async_memoizer_test.dart
index dc008f1..380f58d 100644
--- a/test/async_memoizer_test.dart
+++ b/test/async_memoizer_test.dart
@@ -6,7 +6,7 @@
import 'package:test/test.dart';
main() {
- var cache;
+ AsyncMemoizer cache;
setUp(() => cache = new AsyncMemoizer());
test("runs the function only the first time runOnce() is called", () async {
diff --git a/test/cancelable_operation_test.dart b/test/cancelable_operation_test.dart
index bded402..8c92e2a 100644
--- a/test/cancelable_operation_test.dart
+++ b/test/cancelable_operation_test.dart
@@ -11,7 +11,7 @@
void main() {
group("without being canceled", () {
- var completer;
+ CancelableCompleter completer;
setUp(() {
completer =
new CancelableCompleter(onCancel: expectAsync0(() {}, count: 0));
@@ -118,7 +118,7 @@
test("fires onCancel", () {
var canceled = false;
- var completer;
+ CancelableCompleter completer;
completer = new CancelableCompleter(onCancel: expectAsync0(() {
expect(completer.isCanceled, isTrue);
canceled = true;
diff --git a/test/future_group_test.dart b/test/future_group_test.dart
index af04799..b6f75ba 100644
--- a/test/future_group_test.dart
+++ b/test/future_group_test.dart
@@ -10,7 +10,7 @@
import 'utils.dart';
void main() {
- var futureGroup;
+ FutureGroup futureGroup;
setUp(() {
futureGroup = new FutureGroup();
});
diff --git a/test/lazy_stream_test.dart b/test/lazy_stream_test.dart
index 8da1366..0c2e344 100644
--- a/test/lazy_stream_test.dart
+++ b/test/lazy_stream_test.dart
@@ -96,7 +96,7 @@
});
test("a lazy stream can't be listened to from within its callback", () {
- var stream;
+ LazyStream stream;
stream = new LazyStream(expectAsync0(() {
expect(() => stream.listen(null), throwsStateError);
return new Stream.empty();
diff --git a/test/result/result_future_test.dart b/test/result/result_future_test.dart
index d8b4e01..ffdbb7c 100644
--- a/test/result/result_future_test.dart
+++ b/test/result/result_future_test.dart
@@ -9,8 +9,8 @@
import 'package:test/test.dart';
void main() {
- var completer;
- var future;
+ Completer completer;
+ ResultFuture future;
setUp(() {
completer = new Completer();
future = new ResultFuture(completer.future);
diff --git a/test/result/result_test.dart b/test/result/result_test.dart
index 23c9f63..33e146e 100644
--- a/test/result/result_test.dart
+++ b/test/result/result_test.dart
@@ -301,12 +301,17 @@
test("handle neither unary nor binary", () {
ErrorResult result = new Result.error("error", stack);
- expect(() => result.handle(() => fail("unreachable")), throws);
- expect(() => result.handle((a, b, c) => fail("unreachable")), throws);
- expect(() => result.handle((a, b, {c}) => fail("unreachable")), throws);
- expect(() => result.handle((a, {b}) => fail("unreachable")), throws);
- expect(() => result.handle(({a, b}) => fail("unreachable")), throws);
- expect(() => result.handle(({a}) => fail("unreachable")), throws);
+ expect(() => result.handle(() => fail("unreachable")), throwsA(anything));
+ expect(() => result.handle((a, b, c) => fail("unreachable")),
+ throwsA(anything));
+ expect(() => result.handle((a, b, {c}) => fail("unreachable")),
+ throwsA(anything));
+ expect(() => result.handle((a, {b}) => fail("unreachable")),
+ throwsA(anything));
+ expect(() => result.handle(({a, b}) => fail("unreachable")),
+ throwsA(anything));
+ expect(
+ () => result.handle(({a}) => fail("unreachable")), throwsA(anything));
});
}
diff --git a/test/stream_completer_test.dart b/test/stream_completer_test.dart
index 4f30a7a..55b4ce3 100644
--- a/test/stream_completer_test.dart
+++ b/test/stream_completer_test.dart
@@ -77,7 +77,7 @@
var completer = new StreamCompleter();
var lastEvent = -1;
var controller = new StreamController();
- var subscription;
+ StreamSubscription subscription;
subscription = completer.stream.listen((value) {
expect(value, lessThan(3));
lastEvent = value;
diff --git a/test/stream_group_test.dart b/test/stream_group_test.dart
index d94f4d0..83b685c 100644
--- a/test/stream_group_test.dart
+++ b/test/stream_group_test.dart
@@ -9,7 +9,7 @@
main() {
group("single-subscription", () {
- var streamGroup;
+ StreamGroup<String> streamGroup;
setUp(() {
streamGroup = new StreamGroup<String>();
});
@@ -250,7 +250,7 @@
});
group("broadcast", () {
- var streamGroup;
+ StreamGroup<String> streamGroup;
setUp(() {
streamGroup = new StreamGroup<String>.broadcast();
});
@@ -439,7 +439,7 @@
}
void regardlessOfType(StreamGroup<String> newStreamGroup()) {
- var streamGroup;
+ StreamGroup<String> streamGroup;
setUp(() {
streamGroup = newStreamGroup();
});
diff --git a/test/stream_queue_test.dart b/test/stream_queue_test.dart
index 8bd9d23..7a3d718 100644
--- a/test/stream_queue_test.dart
+++ b/test/stream_queue_test.dart
@@ -406,7 +406,7 @@
expect(controller.hasListener, isTrue);
expect(controller.isPaused, isFalse);
- var lastEvent;
+ dynamic lastEvent;
subscription.onData((value) => lastEvent = value);
controller.add(2);
@@ -445,7 +445,7 @@
expect(await events.peek, 4);
expect(await events.next, 4);
// Throws at end.
- expect(events.peek, throws);
+ expect(events.peek, throwsA(anything));
await events.cancel();
});
test("multiple requests at the same time", () async {
@@ -610,7 +610,7 @@
var controller = new StreamController<int>();
var events = new StreamQueue<int>(controller.stream);
- var hasNext;
+ bool hasNext;
events.hasNext.then((result) {
hasNext = result;
});
@@ -626,7 +626,7 @@
var controller = new StreamController<int>();
var events = new StreamQueue<int>(controller.stream);
- var hasNext;
+ bool hasNext;
events.hasNext.then((result) {
hasNext = result;
});
diff --git a/test/stream_sink_completer_test.dart b/test/stream_sink_completer_test.dart
index 3c8b576..a149a7f 100644
--- a/test/stream_sink_completer_test.dart
+++ b/test/stream_sink_completer_test.dart
@@ -10,7 +10,7 @@
import "utils.dart";
main() {
- var completer;
+ StreamSinkCompleter completer;
setUp(() {
completer = new StreamSinkCompleter();
});
diff --git a/test/stream_sink_transformer_test.dart b/test/stream_sink_transformer_test.dart
index 208a03a..552bdaa 100644
--- a/test/stream_sink_transformer_test.dart
+++ b/test/stream_sink_transformer_test.dart
@@ -10,7 +10,7 @@
import "utils.dart";
void main() {
- var controller;
+ StreamController controller;
setUp(() {
controller = new StreamController();
});
diff --git a/test/stream_splitter_test.dart b/test/stream_splitter_test.dart
index 70266ee..c118b12 100644
--- a/test/stream_splitter_test.dart
+++ b/test/stream_splitter_test.dart
@@ -9,7 +9,7 @@
main() {
StreamController<int> controller;
- var splitter;
+ StreamSplitter splitter;
setUp(() {
controller = new StreamController<int>();
splitter = new StreamSplitter<int>(controller.stream);
diff --git a/test/stream_zip_test.dart b/test/stream_zip_test.dart
index 71d8eee..018c8ab 100644
--- a/test/stream_zip_test.dart
+++ b/test/stream_zip_test.dart
@@ -307,7 +307,7 @@
var s2 = new Stream.fromIterable([1, 3, 5, 7]);
var sz = new StreamZip([s1, s2]);
int ctr = 0;
- var sub;
+ StreamSubscription sub;
sub = sz.listen(expectAsync1((v) {
expect(v, equals([ctr * 2, ctr * 2 + 1]));
if (ctr == 1) {
diff --git a/test/subscription_stream_test.dart b/test/subscription_stream_test.dart
index 6e2c9d5..804e92f 100644
--- a/test/subscription_stream_test.dart
+++ b/test/subscription_stream_test.dart
@@ -40,7 +40,7 @@
var sourceSubscription = stream.listen(null);
var subscriptionStream = new SubscriptionStream<int>(sourceSubscription);
var subscription = subscriptionStream.listen(null);
- expect(() => subscriptionStream.listen(null), throws);
+ expect(() => subscriptionStream.listen(null), throwsA(anything));
await subscription.cancel();
});
@@ -49,7 +49,7 @@
var sourceSubscription = controller.stream.listen(null);
var subscriptionStream = new SubscriptionStream(sourceSubscription);
expect(controller.isPaused, isTrue);
- var lastEvent;
+ dynamic lastEvent;
var subscription = subscriptionStream.listen((value) {
lastEvent = value;
});
@@ -72,8 +72,8 @@
group("cancelOnError source:", () {
for (var sourceCancels in [false, true]) {
group("${sourceCancels ? "yes" : "no"}:", () {
- var subscriptionStream;
- var onCancel; // Completes if source stream is canceled before done.
+ SubscriptionStream subscriptionStream;
+ Future onCancel; // Completes if source stream is canceled before done.
setUp(() {
var cancelCompleter = new Completer();
var source = createErrorStream(cancelCompleter);
@@ -142,7 +142,7 @@
var subscription =
subscriptionStream.listen(null, cancelOnError: cancelOnError);
- expect(subscription.asFuture(), throws);
+ expect(subscription.asFuture(), throwsA(anything));
});
});
}
diff --git a/test/typed_wrapper/future_test.dart b/test/typed_wrapper/future_test.dart
index 7fb91c8..ea3303f 100644
--- a/test/typed_wrapper/future_test.dart
+++ b/test/typed_wrapper/future_test.dart
@@ -11,7 +11,7 @@
void main() {
group("with valid types, forwards", () {
- var wrapper;
+ TypeSafeFuture<int> wrapper;
TypeSafeFuture<int> errorWrapper;
setUp(() {
wrapper = new TypeSafeFuture<int>(new Future<Object>.value(12));
@@ -62,7 +62,7 @@
expect(
new TypeSafeFuture<int>(new Completer<Object>().future)
.timeout(Duration.zero),
- throwsA(new isInstanceOf<TimeoutException>()));
+ throwsA(new TypeMatcher<TimeoutException>()));
expect(
new TypeSafeFuture<int>(new Completer<Object>().future)
diff --git a/test/typed_wrapper/stream_subscription_test.dart b/test/typed_wrapper/stream_subscription_test.dart
index f52abe7..50c07b6 100644
--- a/test/typed_wrapper/stream_subscription_test.dart
+++ b/test/typed_wrapper/stream_subscription_test.dart
@@ -11,9 +11,9 @@
void main() {
group("with valid types, forwards", () {
- var controller;
- var wrapper;
- var isCanceled;
+ StreamController controller;
+ StreamSubscription wrapper;
+ bool isCanceled;
setUp(() {
controller = new StreamController<Object>(onCancel: () {
isCanceled = true;
@@ -68,9 +68,9 @@
});
group("with invalid types,", () {
- var controller;
- var wrapper;
- var isCanceled;
+ StreamController controller;
+ StreamSubscription wrapper;
+ bool isCanceled;
setUp(() {
controller = new StreamController<Object>(onCancel: () {
isCanceled = true;
diff --git a/test/utils.dart b/test/utils.dart
index 39df0f6..3f8c0ef 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -38,10 +38,10 @@
/// A matcher that runs a callback in its own zone and asserts that that zone
/// emits a [CastError].
-final throwsZonedCastError = throwsZoned(new isInstanceOf<CastError>());
+final throwsZonedCastError = throwsZoned(new TypeMatcher<CastError>());
/// A matcher that matches a callback or future that throws a [CastError].
-final throwsCastError = throwsA(new isInstanceOf<CastError>());
+final throwsCastError = throwsA(new TypeMatcher<CastError>());
/// A badly behaved stream which throws if it's ever listened to.
///