Skip to content

Commit

Permalink
Update to latest lints, require Dart 3.2 (dart-archive/async#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Feb 15, 2024
1 parent 87293d2 commit 42eddc9
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 174 deletions.
2 changes: 1 addition & 1 deletion pkgs/async/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.19.0, dev]
sdk: [3.2, dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.12.0-wip

- Require Dart 2.19
- Require Dart 3.2

## 2.11.0

Expand Down
9 changes: 4 additions & 5 deletions pkgs/async/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://dart.dev/guides/language/analysis-options
# https://dart.dev/tools/analysis#the-analysis-options-file
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
Expand All @@ -7,16 +7,15 @@ analyzer:
errors:
only_throw_errors: ignore
unawaited_futures: ignore
inference_failure_on_instance_creation: ignore
inference_failure_on_function_invocation: ignore
inference_failure_on_collection_literal: ignore

linter:
rules:
- avoid_unused_constructor_parameters
- comment_references
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_relative_imports
- test_types_in_equals
- use_super_parameters
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/subscription_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _CancelOnErrorSubscriptionWrapper<T>
@override
void onError(Function? handleError) {
// Cancel when receiving an error.
super.onError((error, StackTrace stackTrace) {
super.onError((Object error, StackTrace stackTrace) {
// Wait for the cancel to complete before sending the error event.
super.cancel().whenComplete(() {
if (handleError is ZoneBinaryCallback) {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ description: Utility functions and classes related to the 'dart:async' library.
repository: https://github.com/dart-lang/async

environment:
sdk: '>=2.19.0 <4.0.0'
sdk: ^3.2.0

dependencies:
collection: ^1.15.0
meta: ^1.1.7

dev_dependencies:
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.0.0
fake_async: ^1.2.0
stack_trace: ^1.10.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion pkgs/async/test/async_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
Future<String> throwingCall() async => throw Exception();
await expectLater(cache.fetch(throwingCall), throwsA(isException));
// To let the timer invalidate the cache
await Future.delayed(Duration(milliseconds: 5));
await Future<void>.delayed(const Duration(milliseconds: 5));

Future<String> call() async => 'Completed';
expect(await cache.fetch(call), 'Completed', reason: 'Cache invalidates');
Expand Down
34 changes: 18 additions & 16 deletions pkgs/async/test/cancelable_operation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void main() {
});

test('is not complete until the result is available', () async {
var backingWork = Completer();
var backingWork = Completer<void>();
var operation = CancelableOperation.fromFuture(backingWork.future);
expect(operation.isCompleted, isFalse);
backingWork.complete();
Expand All @@ -132,17 +132,19 @@ void main() {

test('successfully then with a future', () {
completer.complete(1);
expect(() => completer.complete(Completer().future), throwsStateError);
expect(() => completer.complete(Completer<void>().future),
throwsStateError);
});

test('with a future then successfully', () {
completer.complete(Completer().future);
completer.complete(Completer<void>().future);
expect(() => completer.complete(1), throwsStateError);
});

test('with a future twice', () {
completer.complete(Completer().future);
expect(() => completer.complete(Completer().future), throwsStateError);
completer.complete(Completer<void>().future);
expect(() => completer.complete(Completer<void>().future),
throwsStateError);
});
});

Expand Down Expand Up @@ -185,7 +187,7 @@ void main() {

group('when canceled', () {
test('causes the future never to fire', () async {
var completer = CancelableCompleter();
var completer = CancelableCompleter<void>();
completer.operation.value.whenComplete(expectAsync0(() {}, count: 0));
completer.operation.cancel();

Expand Down Expand Up @@ -242,7 +244,7 @@ void main() {
'does call onCancel if the completer has completed to an unfired '
'Future', () {
var completer = CancelableCompleter(onCancel: expectAsync0(() {}));
completer.complete(Completer().future);
completer.complete(Completer<void>().future);
expect(completer.operation.cancel(), completes);
});

Expand All @@ -257,15 +259,15 @@ void main() {
});

test('can be completed once after being canceled', () async {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
completer.operation.value.whenComplete(expectAsync0(() {}, count: 0));
await completer.operation.cancel();
completer.complete(1);
expect(() => completer.complete(1), throwsStateError);
});

test('fires valueOrCancellation with the given value', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
expect(completer.operation.valueOrCancellation(1), completion(equals(1)));
completer.operation.cancel();
});
Expand All @@ -279,7 +281,7 @@ void main() {
});

test('valueOrCancellation waits on the onCancel future', () async {
var innerCompleter = Completer();
var innerCompleter = Completer<void>();
var completer =
CancelableCompleter(onCancel: () => innerCompleter.future);

Expand Down Expand Up @@ -389,13 +391,13 @@ void main() {

group('asStream()', () {
test('emits a value and then closes', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
expect(completer.operation.asStream().toList(), completion(equals([1])));
completer.complete(1);
});

test('emits an error and then closes', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<void>();
var queue = StreamQueue(completer.operation.asStream());
expect(queue.next, throwsA('error'));
expect(queue.hasNext, completion(isFalse));
Expand Down Expand Up @@ -425,7 +427,7 @@ void main() {
onError = expectAsync2((e, s) => 'Fake', count: 0, id: 'onError');
onCancel = expectAsync0(() => 'Fake', count: 0, id: 'onCancel');
propagateCancel = false;
originalCompleter = CancelableCompleter();
originalCompleter = CancelableCompleter<int>();
});

CancelableOperation<String> runThen() {
Expand Down Expand Up @@ -574,8 +576,8 @@ void main() {
test('waits for chained cancellation', () async {
var completer = CancelableCompleter<void>();
var chainedOperation = completer.operation
.then((_) => Future.delayed(Duration(milliseconds: 1)))
.then((_) => Future.delayed(Duration(milliseconds: 1)));
.then((_) => Future<void>.delayed(const Duration(milliseconds: 1)))
.then((_) => Future<void>.delayed(const Duration(milliseconds: 1)));

await completer.operation.cancel();
expect(completer.operation.isCanceled, true);
Expand Down Expand Up @@ -655,7 +657,7 @@ void main() {
onError = null;
onCancel = null;
propagateCancel = false;
originalCompleter = CancelableCompleter();
originalCompleter = CancelableCompleter<int>();
});

CancelableOperation<String> runThenOperation() {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/test/chunked_stream_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void main() {
final r = ChunkedStreamReader(() async* {
yield [1, 2, 3];
// This will hang forever, so we will call cancel()
await Completer().future;
await Completer<void>().future;
yield [4]; // this should never be reachable
fail('unreachable!');
}());
Expand All @@ -362,7 +362,7 @@ void main() {
final r = ChunkedStreamReader(() async* {
yield [1, 2, 3];
// This will hang forever, so we will call cancel()
await Completer().future;
await Completer<void>().future;
yield [4]; // this should never be reachable
fail('unreachable!');
}());
Expand Down
30 changes: 15 additions & 15 deletions pkgs/async/test/future_group_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void main() {
});

test('completes once all contained futures complete', () async {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -93,9 +93,9 @@ void main() {
});

test('completes to the values of the futures in order of addition', () {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<int>();
var completer2 = Completer<int>();
var completer3 = Completer<int>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -112,9 +112,9 @@ void main() {

test("completes to the first error to be emitted, even if it's not closed",
() {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -130,9 +130,9 @@ void main() {
var idle = false;
futureGroup.onIdle.listen((_) => idle = true);

var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand Down Expand Up @@ -162,7 +162,7 @@ void main() {
var idle = false;
futureGroup.onIdle.listen((_) => idle = true);

var completer = Completer();
var completer = Completer<void>();
futureGroup.add(completer.future);

completer.complete();
Expand All @@ -171,7 +171,7 @@ void main() {
expect(futureGroup.isIdle, isTrue);

idle = false;
completer = Completer();
completer = Completer<void>();
futureGroup.add(completer.future);

await flushMicrotasks();
Expand Down Expand Up @@ -206,7 +206,7 @@ void main() {
futureFired = true;
}));

var completer = Completer();
var completer = Completer<void>();
futureGroup.add(completer.future);
futureGroup.close();

Expand Down
6 changes: 3 additions & 3 deletions pkgs/async/test/lazy_stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
var callbackCalled = false;
var stream = LazyStream(expectAsync0(() {
callbackCalled = true;
return Stream.empty();
return const Stream.empty();
}));

await flushMicrotasks();
Expand All @@ -28,7 +28,7 @@ void main() {
var callbackCalled = false;
var stream = LazyStream(expectAsync0(() {
callbackCalled = true;
return Stream.empty();
return const Stream.empty();
}));

await flushMicrotasks();
Expand Down Expand Up @@ -95,7 +95,7 @@ void main() {
late LazyStream stream;
stream = LazyStream(expectAsync0(() {
expect(() => stream.listen(null), throwsStateError);
return Stream.empty();
return const Stream.empty();
}));
stream.listen(null);
});
Expand Down
12 changes: 6 additions & 6 deletions pkgs/async/test/null_stream_sink_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
});

test('a custom future may be passed to done', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = NullStreamSink(done: completer.future);

var doneFired = false;
Expand Down Expand Up @@ -51,7 +51,7 @@ void main() {

expect(() => sink.add(1), throwsStateError);
expect(() => sink.addError('oh no'), throwsStateError);
expect(() => sink.addStream(Stream.empty()), throwsStateError);
expect(() => sink.addStream(const Stream.empty()), throwsStateError);
});

group('addStream', () {
Expand All @@ -68,7 +68,7 @@ void main() {
});

test('returns the cancel future', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = NullStreamSink();
var controller = StreamController(onCancel: () => completer.future);

Expand All @@ -93,15 +93,15 @@ void main() {
test('causes events to throw StateErrors until the future completes',
() async {
var sink = NullStreamSink();
var future = sink.addStream(Stream.empty());
var future = sink.addStream(const Stream.empty());
expect(() => sink.add(1), throwsStateError);
expect(() => sink.addError('oh no'), throwsStateError);
expect(() => sink.addStream(Stream.empty()), throwsStateError);
expect(() => sink.addStream(const Stream.empty()), throwsStateError);

await future;
sink.add(1);
sink.addError('oh no');
expect(sink.addStream(Stream.empty()), completes);
expect(sink.addStream(const Stream.empty()), completes);
});
});
});
Expand Down
Loading

0 comments on commit 42eddc9

Please sign in to comment.