From b5be1d1925ba0962ea3804b01e66aa84d8a85bfa Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Jan 2024 14:17:26 -0800 Subject: [PATCH] Update to latest lints, require Dart 3.2 --- .github/workflows/test-package.yml | 2 +- CHANGELOG.md | 2 +- analysis_options.yaml | 9 +++--- lib/src/subscription_stream.dart | 2 +- pubspec.yaml | 4 +-- test/async_cache_test.dart | 2 +- test/cancelable_operation_test.dart | 4 +-- test/lazy_stream_test.dart | 6 ++-- test/null_stream_sink_test.dart | 8 ++--- test/reject_errors_test.dart | 4 +-- test/restartable_timer_test.dart | 41 +++++++++++++------------ test/result/result_captureAll_test.dart | 2 +- test/result/result_test.dart | 18 +++++------ test/sink_base_test.dart | 2 +- test/stream_closer_test.dart | 2 +- test/stream_completer_test.dart | 6 ++-- test/stream_extensions_test.dart | 4 +-- test/stream_queue_test.dart | 4 ++- test/stream_sink_transformer_test.dart | 4 +-- test/subscription_stream_test.dart | 2 +- test/utils.dart | 4 +-- 21 files changed, 67 insertions(+), 65 deletions(-) diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 04c07a6..cf89e3c 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index ccda9d8..b2b6f25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.12.0-wip -- Require Dart 2.19 +- Require Dart 3.2 ## 2.11.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index 260fdb0..265204b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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: @@ -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 diff --git a/lib/src/subscription_stream.dart b/lib/src/subscription_stream.dart index 5572adf..9ce4942 100644 --- a/lib/src/subscription_stream.dart +++ b/lib/src/subscription_stream.dart @@ -73,7 +73,7 @@ class _CancelOnErrorSubscriptionWrapper @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) { diff --git a/pubspec.yaml b/pubspec.yaml index dd2046c..a758422 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/async_cache_test.dart b/test/async_cache_test.dart index 77bda7c..c1e38b7 100644 --- a/test/async_cache_test.dart +++ b/test/async_cache_test.dart @@ -60,7 +60,7 @@ void main() { Future 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.delayed(const Duration(milliseconds: 5)); Future call() async => 'Completed'; expect(await cache.fetch(call), 'Completed', reason: 'Cache invalidates'); diff --git a/test/cancelable_operation_test.dart b/test/cancelable_operation_test.dart index 6d415ed..e6d3d4a 100644 --- a/test/cancelable_operation_test.dart +++ b/test/cancelable_operation_test.dart @@ -574,8 +574,8 @@ void main() { test('waits for chained cancellation', () async { var completer = CancelableCompleter(); var chainedOperation = completer.operation - .then((_) => Future.delayed(Duration(milliseconds: 1))) - .then((_) => Future.delayed(Duration(milliseconds: 1))); + .then((_) => Future.delayed(const Duration(milliseconds: 1))) + .then((_) => Future.delayed(const Duration(milliseconds: 1))); await completer.operation.cancel(); expect(completer.operation.isCanceled, true); diff --git a/test/lazy_stream_test.dart b/test/lazy_stream_test.dart index cde1928..9785b2e 100644 --- a/test/lazy_stream_test.dart +++ b/test/lazy_stream_test.dart @@ -14,7 +14,7 @@ void main() { var callbackCalled = false; var stream = LazyStream(expectAsync0(() { callbackCalled = true; - return Stream.empty(); + return const Stream.empty(); })); await flushMicrotasks(); @@ -28,7 +28,7 @@ void main() { var callbackCalled = false; var stream = LazyStream(expectAsync0(() { callbackCalled = true; - return Stream.empty(); + return const Stream.empty(); })); await flushMicrotasks(); @@ -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); }); diff --git a/test/null_stream_sink_test.dart b/test/null_stream_sink_test.dart index 649cbad..fd86368 100644 --- a/test/null_stream_sink_test.dart +++ b/test/null_stream_sink_test.dart @@ -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', () { @@ -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); }); }); }); diff --git a/test/reject_errors_test.dart b/test/reject_errors_test.dart index 5b8b3e7..995f1bd 100644 --- a/test/reject_errors_test.dart +++ b/test/reject_errors_test.dart @@ -171,7 +171,7 @@ void main() { test('throws on addStream()', () { var sink = controller.sink.rejectErrors()..close(); - expect(() => sink.addStream(Stream.empty()), throwsStateError); + expect(() => sink.addStream(const Stream.empty()), throwsStateError); }); test('allows close()', () { @@ -196,7 +196,7 @@ void main() { test('throws on addStream()', () { var sink = controller.sink.rejectErrors() ..addStream(StreamController().stream); - expect(() => sink.addStream(Stream.empty()), throwsStateError); + expect(() => sink.addStream(const Stream.empty()), throwsStateError); }); test('throws on close()', () { diff --git a/test/restartable_timer_test.dart b/test/restartable_timer_test.dart index 41f52ab..4aab287 100644 --- a/test/restartable_timer_test.dart +++ b/test/restartable_timer_test.dart @@ -10,14 +10,14 @@ void main() { test('runs the callback once the duration has elapsed', () { FakeAsync().run((async) { var fired = false; - RestartableTimer(Duration(seconds: 5), () { + RestartableTimer(const Duration(seconds: 5), () { fired = true; }); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); - async.elapse(Duration(seconds: 1)); + async.elapse(const Duration(seconds: 1)); expect(fired, isTrue); }); }); @@ -25,15 +25,15 @@ void main() { test("doesn't run the callback if the timer is canceled", () { FakeAsync().run((async) { var fired = false; - var timer = RestartableTimer(Duration(seconds: 5), () { + var timer = RestartableTimer(const Duration(seconds: 5), () { fired = true; }); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); timer.cancel(); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); }); }); @@ -41,18 +41,18 @@ void main() { test('resets the duration if the timer is reset before it fires', () { FakeAsync().run((async) { var fired = false; - var timer = RestartableTimer(Duration(seconds: 5), () { + var timer = RestartableTimer(const Duration(seconds: 5), () { fired = true; }); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); timer.reset(); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); - async.elapse(Duration(seconds: 1)); + async.elapse(const Duration(seconds: 1)); expect(fired, isTrue); }); }); @@ -60,19 +60,19 @@ void main() { test('re-runs the callback if the timer is reset after firing', () { FakeAsync().run((async) { var fired = 0; - var timer = RestartableTimer(Duration(seconds: 5), () { + var timer = RestartableTimer(const Duration(seconds: 5), () { fired++; }); - async.elapse(Duration(seconds: 5)); + async.elapse(const Duration(seconds: 5)); expect(fired, equals(1)); timer.reset(); - async.elapse(Duration(seconds: 5)); + async.elapse(const Duration(seconds: 5)); expect(fired, equals(2)); timer.reset(); - async.elapse(Duration(seconds: 5)); + async.elapse(const Duration(seconds: 5)); expect(fired, equals(3)); }); }); @@ -80,27 +80,28 @@ void main() { test('runs the callback if the timer is reset after being canceled', () { FakeAsync().run((async) { var fired = false; - var timer = RestartableTimer(Duration(seconds: 5), () { + var timer = RestartableTimer(const Duration(seconds: 5), () { fired = true; }); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); timer.cancel(); - async.elapse(Duration(seconds: 4)); + async.elapse(const Duration(seconds: 4)); expect(fired, isFalse); timer.reset(); - async.elapse(Duration(seconds: 5)); + async.elapse(const Duration(seconds: 5)); expect(fired, isTrue); }); }); test("only runs the callback once if the timer isn't reset", () { FakeAsync().run((async) { - RestartableTimer(Duration(seconds: 5), expectAsync0(() {}, count: 1)); - async.elapse(Duration(seconds: 10)); + RestartableTimer( + const Duration(seconds: 5), expectAsync0(() {}, count: 1)); + async.elapse(const Duration(seconds: 10)); }); }); } diff --git a/test/result/result_captureAll_test.dart b/test/result/result_captureAll_test.dart index 25c5775..e85999e 100644 --- a/test/result/result_captureAll_test.dart +++ b/test/result/result_captureAll_test.dart @@ -147,7 +147,7 @@ void main() { expect(all, completion(expected)); - var completeFunctions = List.generate(n, (i) { + var completeFunctions = List.generate(n, (i) { var c = cs[i]; return () => throws(i) ? c.completeError('$i', someStack) : c.complete(i); diff --git a/test/result/result_test.dart b/test/result/result_test.dart index 568a891..14a6f4d 100644 --- a/test/result/result_test.dart +++ b/test/result/result_test.dart @@ -122,7 +122,7 @@ void main() { expect(result.isError, isFalse); var value = result.asValue!; expect(value.value, equals(42)); - }), onError: (e, s) { + }), onError: (Object e, s) { fail('Unexpected error: $e'); }); }); @@ -135,7 +135,7 @@ void main() { var error = result.asError!; expect(error.error, equals('BAD')); expect(error.stackTrace, same(stack)); - }), onError: (e, s) { + }), onError: (Object e, s) { fail('Unexpected error: $e'); }); }); @@ -144,7 +144,7 @@ void main() { var future = Future>.value(Result.value(42)); Result.release(future).then(expectAsync1((v) { expect(v, equals(42)); - }), onError: (e, s) { + }), onError: (Object e, s) { fail('Unexpected error: $e'); }); }); @@ -207,7 +207,7 @@ void main() { expect(v, equals(expected.asValue!.value)); } - void errorListener(error, StackTrace stackTrace) { + void errorListener(Object error, StackTrace stackTrace) { expect(expectedList.isEmpty, isFalse); Result expected = expectedList.removeFirst(); expect(expected.isError, isTrue); @@ -263,7 +263,7 @@ void main() { test('handle unary', () { var result = ErrorResult('error', stack); var called = false; - result.handle((error) { + result.handle((Object error) { called = true; expect(error, 'error'); }); @@ -273,7 +273,7 @@ void main() { test('handle binary', () { var result = ErrorResult('error', stack); var called = false; - result.handle((error, stackTrace) { + result.handle((Object error, StackTrace stackTrace) { called = true; expect(error, 'error'); expect(stackTrace, same(stack)); @@ -284,7 +284,7 @@ void main() { test('handle unary and binary', () { var result = ErrorResult('error', stack); var called = false; - result.handle((error, [stackTrace]) { + result.handle((Object? error, [StackTrace? stackTrace]) { called = true; expect(error, 'error'); expect(stackTrace, same(stack)); @@ -344,11 +344,11 @@ class TestSink implements EventSink { onDone(); } - static void _nullData(value) { + static void _nullData(dynamic value) { fail('Unexpected sink add: $value'); } - static void _nullError(e, StackTrace s) { + static void _nullError(dynamic e, StackTrace s) { fail('Unexpected sink addError: $e'); } diff --git a/test/sink_base_test.dart b/test/sink_base_test.dart index 95f51c9..10f896a 100644 --- a/test/sink_base_test.dart +++ b/test/sink_base_test.dart @@ -328,7 +328,7 @@ void main() { sink.flush(); expect(() => sink.add([0]), throwsStateError); expect(() => sink.addError('oh no'), throwsStateError); - expect(() => sink.addStream(Stream.empty()), throwsStateError); + expect(() => sink.addStream(const Stream.empty()), throwsStateError); expect(() => sink.flush(), throwsStateError); expect(() => sink.close(), throwsStateError); }); diff --git a/test/stream_closer_test.dart b/test/stream_closer_test.dart index 28ab970..a2bad1a 100644 --- a/test/stream_closer_test.dart +++ b/test/stream_closer_test.dart @@ -27,7 +27,7 @@ void main() { }); test('transforms a broadcast stream into a broadcast stream', () { - expect(Stream.empty().transform(closer).isBroadcast, isTrue); + expect(const Stream.empty().transform(closer).isBroadcast, isTrue); }); test("doesn't eagerly listen", () { diff --git a/test/stream_completer_test.dart b/test/stream_completer_test.dart index eaeb719..eb1d485 100644 --- a/test/stream_completer_test.dart +++ b/test/stream_completer_test.dart @@ -274,7 +274,7 @@ void main() { var subscription = completer.stream.listen(null); Object lastEvent = 0; subscription.onData((value) => lastEvent = value); - subscription.onError((value) => lastEvent = '$value'); + subscription.onError((Object value) => lastEvent = '$value'); subscription.onDone(() => lastEvent = -1); completer.setSourceStream(controller.stream); await flushMicrotasks(); @@ -285,7 +285,7 @@ void main() { await flushMicrotasks(); expect(lastEvent, '2'); subscription.onData((value) => lastEvent = -value); - subscription.onError((value) => lastEvent = '${-(value as int)}'); + subscription.onError((Object value) => lastEvent = '${-(value as int)}'); controller.add(1); await flushMicrotasks(); expect(lastEvent, -1); @@ -323,7 +323,7 @@ void main() { await flushMicrotasks(); expect(controller.hasListener, isTrue); controller.addError(42); - await done.then(unreachable('data'), onError: (error) { + await done.then(unreachable('data'), onError: (Object error) { expect(error, 42); }); expect(controller.hasListener, isFalse); diff --git a/test/stream_extensions_test.dart b/test/stream_extensions_test.dart index c922923..b43dedc 100644 --- a/test/stream_extensions_test.dart +++ b/test/stream_extensions_test.dart @@ -10,7 +10,7 @@ import 'package:test/test.dart'; void main() { group('.slices', () { test('empty', () { - expect(Stream.empty().slices(1).toList(), completion(equals([]))); + expect(const Stream.empty().slices(1).toList(), completion(equals([]))); }); test('with the same length as the iterable', () { @@ -67,7 +67,7 @@ void main() { }); test('returns null for an empty stream', () { - expect(Stream.empty().firstOrNull, completion(isNull)); + expect(const Stream.empty().firstOrNull, completion(isNull)); }); test('cancels the subscription after an event', () async { diff --git a/test/stream_queue_test.dart b/test/stream_queue_test.dart index 7c575c0..b4da96c 100644 --- a/test/stream_queue_test.dart +++ b/test/stream_queue_test.dart @@ -250,7 +250,9 @@ void main() { var skip4 = events.skip(1); var index = 0; // Check that futures complete in order. - Func1Required sequence(expectedValue, sequenceIndex) => (value) { + Func1Required sequence( + Object expectedValue, Object sequenceIndex) => + (value) { expect(value, expectedValue); expect(index, sequenceIndex); index++; diff --git a/test/stream_sink_transformer_test.dart b/test/stream_sink_transformer_test.dart index e5f6baa..905e713 100644 --- a/test/stream_sink_transformer_test.dart +++ b/test/stream_sink_transformer_test.dart @@ -43,7 +43,7 @@ void main() { var results = []; controller.stream.listen(expectAsync1((_) {}, count: 0), - onError: (error, stackTrace) { + onError: (Object error, stackTrace) { results.add(error); }, onDone: expectAsync0(() { expect(results, equals([2, 4, 6])); @@ -142,7 +142,7 @@ void main() { var results = []; controller.stream.listen(expectAsync1((_) {}, count: 0), - onError: (error, stackTrace) { + onError: (Object error, stackTrace) { results.add(error); }, onDone: expectAsync0(() { expect(results, equals([2, 4, 6])); diff --git a/test/subscription_stream_test.dart b/test/subscription_stream_test.dart index ea626b1..2c1cd38 100644 --- a/test/subscription_stream_test.dart +++ b/test/subscription_stream_test.dart @@ -110,7 +110,7 @@ void main() { var completer = Completer(); var events = []; subscriptionStream.listen(events.add, - onError: (value) { + onError: (Object value) { events.add(value); completer.complete(); }, diff --git a/test/utils.dart b/test/utils.dart index fd87a4e..d2d9fe6 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -40,10 +40,10 @@ Matcher throwsZoned(Matcher matcher) => predicate((void Function() callback) { /// A matcher that runs a callback in its own zone and asserts that that zone /// emits a [TypeError]. -final throwsZonedTypeError = throwsZoned(TypeMatcher()); +final throwsZonedTypeError = throwsZoned(isA()); /// A matcher that matches a callback or future that throws a [TypeError]. -final throwsTypeError = throwsA(TypeMatcher()); +final throwsTypeError = throwsA(isA()); /// A badly behaved stream which throws if it's ever listened to. ///