Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Update to latest lints, require Dart 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Feb 13, 2024
1 parent 24266ca commit b5be1d1
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .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 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 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 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 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 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.delayed(const Duration(milliseconds: 5));

Future<String> call() async => 'Completed';
expect(await cache.fetch(call), 'Completed', reason: 'Cache invalidates');
Expand Down
4 changes: 2 additions & 2 deletions test/cancelable_operation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,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.delayed(const Duration(milliseconds: 1)))
.then((_) => Future.delayed(const Duration(milliseconds: 1)));

await completer.operation.cancel();
expect(completer.operation.isCanceled, true);
Expand Down
6 changes: 3 additions & 3 deletions 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
8 changes: 4 additions & 4 deletions test/null_stream_sink_test.dart
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/reject_errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () {
Expand All @@ -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()', () {
Expand Down
41 changes: 21 additions & 20 deletions test/restartable_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,97 +10,98 @@ 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);
});
});

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);
});
});

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);
});
});

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));
});
});

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));
});
});
}
2 changes: 1 addition & 1 deletion test/result/result_captureAll_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void main() {

expect(all, completion(expected));

var completeFunctions = List<Function()>.generate(n, (i) {
var completeFunctions = List<void Function()>.generate(n, (i) {
var c = cs[i];
return () =>
throws(i) ? c.completeError('$i', someStack) : c.complete(i);
Expand Down
18 changes: 9 additions & 9 deletions test/result/result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand All @@ -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');
});
});
Expand All @@ -144,7 +144,7 @@ void main() {
var future = Future<Result<int>>.value(Result<int>.value(42));
Result.release(future).then(expectAsync1((v) {
expect(v, equals(42));
}), onError: (e, s) {
}), onError: (Object e, s) {
fail('Unexpected error: $e');
});
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
});
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -344,11 +344,11 @@ class TestSink<T> implements EventSink<T> {
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');
}

Expand Down
2 changes: 1 addition & 1 deletion test/sink_base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/stream_closer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
});

test('transforms a broadcast stream into a broadcast stream', () {
expect(Stream<int>.empty().transform(closer).isBroadcast, isTrue);
expect(const Stream<int>.empty().transform(closer).isBroadcast, isTrue);
});

test("doesn't eagerly listen", () {
Expand Down
Loading

0 comments on commit b5be1d1

Please sign in to comment.