Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newly enforce package:pedantic lints #48

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/close_guarantee_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class _CloseGuaranteeStream<T> extends Stream<T> {
_CloseGuaranteeStream(this._inner, this._channel);

@override
StreamSubscription<T> listen(void onData(T event),
{Function onError, void onDone(), bool cancelOnError}) {
StreamSubscription<T> listen(void Function(T) onData,
{Function onError, void Function() onDone, bool cancelOnError}) {
// If the channel is already disconnected, we shouldn't dispatch anything
// but a done event.
if (_channel._disconnected) {
Expand Down
14 changes: 7 additions & 7 deletions lib/src/disconnector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class _DisconnectorSink<T> implements StreamSink<T> {

@override
void add(T data) {
if (_closed) throw StateError("Cannot add event after closing.");
if (_closed) throw StateError('Cannot add event after closing.');
if (_inAddStream) {
throw StateError("Cannot add event while adding stream.");
throw StateError('Cannot add event while adding stream.');
}
if (_isDisconnected) return;

Expand All @@ -98,9 +98,9 @@ class _DisconnectorSink<T> implements StreamSink<T> {

@override
void addError(error, [StackTrace stackTrace]) {
if (_closed) throw StateError("Cannot add event after closing.");
if (_closed) throw StateError('Cannot add event after closing.');
if (_inAddStream) {
throw StateError("Cannot add event while adding stream.");
throw StateError('Cannot add event while adding stream.');
}
if (_isDisconnected) return;

Expand All @@ -109,9 +109,9 @@ class _DisconnectorSink<T> implements StreamSink<T> {

@override
Future<void> addStream(Stream<T> stream) {
if (_closed) throw StateError("Cannot add stream after closing.");
if (_closed) throw StateError('Cannot add stream after closing.');
if (_inAddStream) {
throw StateError("Cannot add stream while adding stream.");
throw StateError('Cannot add stream while adding stream.');
}
if (_isDisconnected) return Future.value();

Expand All @@ -127,7 +127,7 @@ class _DisconnectorSink<T> implements StreamSink<T> {
@override
Future<void> close() {
if (_inAddStream) {
throw StateError("Cannot close sink while adding stream.");
throw StateError('Cannot close sink while adding stream.');
}

_closed = true;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/guarantee_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class _GuaranteeSink<T> implements StreamSink<T> {

@override
void add(T data) {
if (_closed) throw StateError("Cannot add event after closing.");
if (_closed) throw StateError('Cannot add event after closing.');
if (_inAddStream) {
throw StateError("Cannot add event while adding stream.");
throw StateError('Cannot add event while adding stream.');
}
if (_disconnected) return;

Expand All @@ -126,9 +126,9 @@ class _GuaranteeSink<T> implements StreamSink<T> {

@override
void addError(error, [StackTrace stackTrace]) {
if (_closed) throw StateError("Cannot add event after closing.");
if (_closed) throw StateError('Cannot add event after closing.');
if (_inAddStream) {
throw StateError("Cannot add event while adding stream.");
throw StateError('Cannot add event while adding stream.');
}
if (_disconnected) return;

Expand Down Expand Up @@ -158,9 +158,9 @@ class _GuaranteeSink<T> implements StreamSink<T> {

@override
Future<void> addStream(Stream<T> stream) {
if (_closed) throw StateError("Cannot add stream after closing.");
if (_closed) throw StateError('Cannot add stream after closing.');
if (_inAddStream) {
throw StateError("Cannot add stream while adding stream.");
throw StateError('Cannot add stream while adding stream.');
}
if (_disconnected) return Future.value();

Expand All @@ -176,7 +176,7 @@ class _GuaranteeSink<T> implements StreamSink<T> {
@override
Future<void> close() {
if (_inAddStream) {
throw StateError("Cannot close sink while adding stream.");
throw StateError('Cannot close sink while adding stream.');
}

if (_closed) return done;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/multi_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class _MultiChannel<T> extends StreamChannelMixin<T>

/// Input IDs of controllers in [_controllers] that we've received messages
/// for but that have not yet had a local [virtualChannel] created.
final _pendingIds = Set<int>();
final _pendingIds = <int>{};

/// Input IDs of virtual channels that used to exist but have since been
/// closed.
final _closedIds = Set<int>();
final _closedIds = <int>{};

/// The next id to use for a local virtual channel.
///
Expand Down Expand Up @@ -201,7 +201,7 @@ class _MultiChannel<T> extends StreamChannelMixin<T>
controller = _controllers[inputId];
} else if (_controllers.containsKey(inputId) ||
_closedIds.contains(inputId)) {
throw ArgumentError("A virtual channel with id $id already exists.");
throw ArgumentError('A virtual channel with id $id already exists.');
} else {
controller = StreamChannelController(sync: true);
_controllers[inputId] = controller;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/stream_channel_completer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class StreamChannelCompleter<T> {
/// Either [setChannel] or [setError] may be called at most once. Trying to
/// call either of them again will fail.
void setChannel(StreamChannel<T> channel) {
if (_set) throw StateError("The channel has already been set.");
if (_set) throw StateError('The channel has already been set.');
_set = true;

_streamCompleter.setSourceStream(channel.stream);
Expand All @@ -67,7 +67,7 @@ class StreamChannelCompleter<T> {
/// Either [setChannel] or [setError] may be called at most once. Trying to
/// call either of them again will fail.
void setError(error, [StackTrace stackTrace]) {
if (_set) throw StateError("The channel has already been set.");
if (_set) throw StateError('The channel has already been set.');
_set = true;

_streamCompleter.setError(error, stackTrace);
Expand Down
8 changes: 4 additions & 4 deletions lib/stream_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ abstract class StreamChannel<T> {

/// Returns a copy of this with [stream] replaced by [change]'s return
/// value.
StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream));
StreamChannel<T> changeStream(Stream<T> Function(Stream<T>) change);

/// Returns a copy of this with [sink] replaced by [change]'s return
/// value.
StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink));
StreamChannel<T> changeSink(StreamSink<T> Function(StreamSink<T>) change);

/// Returns a copy of this with the generic type coerced to [S].
///
Expand Down Expand Up @@ -167,11 +167,11 @@ abstract class StreamChannelMixin<T> implements StreamChannel<T> {
changeSink(transformer.bind);

@override
StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) =>
StreamChannel<T> changeStream(Stream<T> Function(Stream<T>) change) =>
StreamChannel.withCloseGuarantee(change(stream), sink);

@override
StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) =>
StreamChannel<T> changeSink(StreamSink<T> Function(StreamSink<T>) change) =>
StreamChannel.withCloseGuarantee(stream, change(sink));

@override
Expand Down
26 changes: 13 additions & 13 deletions test/disconnector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void main() {
.transform(disconnector);
});

group("before disconnection", () {
test("forwards events from the sink as normal", () {
group('before disconnection', () {
test('forwards events from the sink as normal', () {
channel.sink.add(1);
channel.sink.add(2);
channel.sink.add(3);
Expand All @@ -33,7 +33,7 @@ void main() {
expect(sinkController.stream.toList(), completion(equals([1, 2, 3])));
});

test("forwards events to the stream as normal", () {
test('forwards events to the stream as normal', () {
streamController.add(1);
streamController.add(2);
streamController.add(3);
Expand All @@ -47,7 +47,7 @@ void main() {

expect(channel.sink.close(), completes);
expect(() => channel.sink.add(1), throwsStateError);
expect(() => channel.sink.addError("oh no"), throwsStateError);
expect(() => channel.sink.addError('oh no'), throwsStateError);
expect(() => channel.sink.addStream(Stream.fromIterable([])),
throwsStateError);
});
Expand All @@ -57,7 +57,7 @@ void main() {
channel.sink.addStream(controller.stream);

expect(() => channel.sink.add(1), throwsStateError);
expect(() => channel.sink.addError("oh no"), throwsStateError);
expect(() => channel.sink.addError('oh no'), throwsStateError);
expect(() => channel.sink.addStream(Stream.fromIterable([])),
throwsStateError);
expect(() => channel.sink.close(), throwsStateError);
Expand All @@ -66,7 +66,7 @@ void main() {
});
});

test("cancels addStream when disconnected", () async {
test('cancels addStream when disconnected', () async {
var canceled = false;
var controller = StreamController(onCancel: () {
canceled = true;
Expand All @@ -78,7 +78,7 @@ void main() {
expect(canceled, isTrue);
});

test("disconnect() returns the close future from the inner sink", () async {
test('disconnect() returns the close future from the inner sink', () async {
var streamController = StreamController();
var sinkController = StreamController();
var disconnector = Disconnector();
Expand All @@ -104,12 +104,12 @@ void main() {
expect(disconnectFutureFired, isTrue);
});

group("after disconnection", () {
group('after disconnection', () {
setUp(() {
disconnector.disconnect();
});

test("closes the inner sink and ignores events to the outer sink", () {
test('closes the inner sink and ignores events to the outer sink', () {
channel.sink.add(1);
channel.sink.add(2);
channel.sink.add(3);
Expand All @@ -118,21 +118,21 @@ void main() {
expect(sinkController.stream.toList(), completion(isEmpty));
});

test("closes the stream", () {
test('closes the stream', () {
expect(channel.stream.toList(), completion(isEmpty));
});

test("completes done", () {
test('completes done', () {
sinkController.stream.listen(null); // Work around sdk#19095.
expect(channel.sink.done, completes);
});

test("still emits state errors after explicit close", () {
test('still emits state errors after explicit close', () {
sinkController.stream.listen(null); // Work around sdk#19095.
expect(channel.sink.close(), completes);

expect(() => channel.sink.add(1), throwsStateError);
expect(() => channel.sink.addError("oh no"), throwsStateError);
expect(() => channel.sink.addError('oh no'), throwsStateError);
});
});
}
Expand Down
34 changes: 17 additions & 17 deletions test/isolate_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ void main() {
channel.sink.close();
});

test("the channel can send messages", () {
test('the channel can send messages', () {
channel.sink.add(1);
channel.sink.add(2);
channel.sink.add(3);

expect(receivePort.take(3).toList(), completion(equals([1, 2, 3])));
});

test("the channel can receive messages", () {
test('the channel can receive messages', () {
sendPort.send(1);
sendPort.send(2);
sendPort.send(3);
Expand All @@ -47,7 +47,7 @@ void main() {
test("events can't be added to an explicitly-closed sink", () {
expect(channel.sink.close(), completes);
expect(() => channel.sink.add(1), throwsStateError);
expect(() => channel.sink.addError("oh no"), throwsStateError);
expect(() => channel.sink.addError('oh no'), throwsStateError);
expect(() => channel.sink.addStream(Stream.fromIterable([])),
throwsStateError);
});
Expand All @@ -57,18 +57,18 @@ void main() {
channel.sink.addStream(controller.stream);

expect(() => channel.sink.add(1), throwsStateError);
expect(() => channel.sink.addError("oh no"), throwsStateError);
expect(() => channel.sink.addError('oh no'), throwsStateError);
expect(() => channel.sink.addStream(Stream.fromIterable([])),
throwsStateError);
expect(() => channel.sink.close(), throwsStateError);

controller.close();
});

group("stream channel rules", () {
group('stream channel rules', () {
test(
"closing the sink causes the stream to close before it emits any more "
"events", () {
'closing the sink causes the stream to close before it emits any more '
'events', () {
sendPort.send(1);
sendPort.send(2);
sendPort.send(3);
Expand All @@ -92,10 +92,10 @@ void main() {
expect(receivePort.take(3).toList(), completion(equals([1, 2, 3])));
});

test("the sink closes as soon as an error is added", () async {
channel.sink.addError("oh no");
test('the sink closes as soon as an error is added', () async {
channel.sink.addError('oh no');
channel.sink.add(1);
expect(channel.sink.done, throwsA("oh no"));
expect(channel.sink.done, throwsA('oh no'));

// Since the sink is closed, the stream should also be closed.
expect(channel.stream.isEmpty, completion(isTrue));
Expand All @@ -106,7 +106,7 @@ void main() {
await pumpEventQueue();
});

test("the sink closes as soon as an error is added via addStream",
test('the sink closes as soon as an error is added via addStream',
() async {
var canceled = false;
var controller = StreamController(onCancel: () {
Expand All @@ -116,8 +116,8 @@ void main() {
// This future shouldn't get the error, because it's sent to [Sink.done].
expect(channel.sink.addStream(controller.stream), completes);

controller.addError("oh no");
expect(channel.sink.done, throwsA("oh no"));
controller.addError('oh no');
expect(channel.sink.done, throwsA('oh no'));
await pumpEventQueue();
expect(canceled, isTrue);

Expand All @@ -127,7 +127,7 @@ void main() {
});
});

group("connect constructors", () {
group('connect constructors', () {
ReceivePort connectPort;
setUp(() {
connectPort = ReceivePort();
Expand All @@ -137,7 +137,7 @@ void main() {
connectPort.close();
});

test("create a connected pair of channels", () {
test('create a connected pair of channels', () {
var channel1 = IsolateChannel<int>.connectReceive(connectPort);
var channel2 = IsolateChannel<int>.connectSend(connectPort.sendPort);

Expand All @@ -152,10 +152,10 @@ void main() {
expect(channel1.stream.take(3).toList(), completion(equals([4, 5, 6])));
});

test("the receiving channel produces an error if it gets the wrong message",
test('the receiving channel produces an error if it gets the wrong message',
() {
var connectedChannel = IsolateChannel.connectReceive(connectPort);
connectPort.sendPort.send("wrong value");
connectPort.sendPort.send('wrong value');

expect(connectedChannel.stream.toList(), throwsStateError);
expect(connectedChannel.sink.done, completes);
Expand Down
Loading