Skip to content

Commit

Permalink
Fix newly enforced package:pedantic lints (dart-archive/async#92)
Browse files Browse the repository at this point in the history
- always_declare_return_types
- annotate_overrides
- curly_braces_in_flow_control_structures
- omit_local_variable_types
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_single_quotes
- type_init_formals
- unnecessary_this
- use_function_type_syntax_for_parameters

Bump minimum SDK to 2.2.0 for Set literals
  • Loading branch information
natebosch authored Dec 6, 2019
1 parent 00e4a96 commit 6299483
Show file tree
Hide file tree
Showing 62 changed files with 1,180 additions and 1,056 deletions.
2 changes: 1 addition & 1 deletion pkgs/async/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: dart

dart:
- dev
- 2.0.0
- 2.2.0

dart_task:
- test: --platform vm
Expand Down
60 changes: 30 additions & 30 deletions pkgs/async/lib/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export "src/async_cache.dart";
export "src/async_memoizer.dart";
export "src/byte_collector.dart";
export "src/cancelable_operation.dart";
export "src/delegate/event_sink.dart";
export "src/delegate/future.dart";
export "src/delegate/sink.dart";
export "src/delegate/stream.dart";
export "src/delegate/stream_consumer.dart";
export "src/delegate/stream_sink.dart";
export "src/delegate/stream_subscription.dart";
export "src/future_group.dart";
export "src/lazy_stream.dart";
export "src/null_stream_sink.dart";
export "src/restartable_timer.dart";
export "src/result/result.dart";
export "src/result/error.dart";
export "src/result/future.dart";
export "src/result/value.dart";
export "src/single_subscription_transformer.dart";
export "src/stream_completer.dart";
export "src/stream_group.dart";
export "src/stream_queue.dart";
export "src/stream_sink_completer.dart";
export "src/stream_sink_transformer.dart";
export "src/stream_splitter.dart";
export "src/stream_subscription_transformer.dart";
export "src/stream_zip.dart";
export "src/subscription_stream.dart";
export "src/typed_stream_transformer.dart";
export 'src/async_cache.dart';
export 'src/async_memoizer.dart';
export 'src/byte_collector.dart';
export 'src/cancelable_operation.dart';
export 'src/delegate/event_sink.dart';
export 'src/delegate/future.dart';
export 'src/delegate/sink.dart';
export 'src/delegate/stream.dart';
export 'src/delegate/stream_consumer.dart';
export 'src/delegate/stream_sink.dart';
export 'src/delegate/stream_subscription.dart';
export 'src/future_group.dart';
export 'src/lazy_stream.dart';
export 'src/null_stream_sink.dart';
export 'src/restartable_timer.dart';
export 'src/result/result.dart';
export 'src/result/error.dart';
export 'src/result/future.dart';
export 'src/result/value.dart';
export 'src/single_subscription_transformer.dart';
export 'src/stream_completer.dart';
export 'src/stream_group.dart';
export 'src/stream_queue.dart';
export 'src/stream_sink_completer.dart';
export 'src/stream_sink_transformer.dart';
export 'src/stream_splitter.dart';
export 'src/stream_subscription_transformer.dart';
export 'src/stream_zip.dart';
export 'src/subscription_stream.dart';
export 'src/typed_stream_transformer.dart';
16 changes: 7 additions & 9 deletions pkgs/async/lib/src/async_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AsyncCache<T> {
///
/// If [fetch] has been called recently enough, returns its previous return
/// value. Otherwise, runs [callback] and returns its new return value.
Future<T> fetch(Future<T> callback()) async {
Future<T> fetch(Future<T> Function() callback) async {
if (_cachedStreamSplitter != null) {
throw StateError('Previously used to cache via `fetchStream`');
}
Expand All @@ -74,17 +74,15 @@ class AsyncCache<T> {
/// If [fetchStream] has been called recently enough, returns a copy of its
/// previous return value. Otherwise, runs [callback] and returns its new
/// return value.
Stream<T> fetchStream(Stream<T> callback()) {
Stream<T> fetchStream(Stream<T> Function() callback) {
if (_cachedValueFuture != null) {
throw StateError('Previously used to cache via `fetch`');
}
if (_cachedStreamSplitter == null) {
_cachedStreamSplitter = StreamSplitter(callback()
.transform(StreamTransformer.fromHandlers(handleDone: (sink) {
_startStaleTimer();
sink.close();
})));
}
_cachedStreamSplitter ??= StreamSplitter(
callback().transform(StreamTransformer.fromHandlers(handleDone: (sink) {
_startStaleTimer();
sink.close();
})));
return _cachedStreamSplitter.split();
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/async_memoizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AsyncMemoizer<T> {
/// Runs the function, [computation], if it hasn't been run before.
///
/// If [runOnce] has already been called, this returns the original result.
Future<T> runOnce(FutureOr<T> computation()) {
Future<T> runOnce(FutureOr<T> Function() computation) {
if (!hasRun) _completer.complete(Future.sync(computation));
return future;
}
Expand Down
14 changes: 6 additions & 8 deletions pkgs/async/lib/src/byte_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import "dart:async";
import "dart:typed_data";
import "cancelable_operation.dart";
import 'dart:async';
import 'dart:typed_data';
import 'cancelable_operation.dart';

/// Collects an asynchronous sequence of byte lists into a single list of bytes.
///
Expand Down Expand Up @@ -40,10 +40,8 @@ CancelableOperation<Uint8List> collectBytesCancelable(
/// Performs all the same operations, but the final result is created
/// by the [result] function, which has access to the stream subscription
/// so it can cancel the operation.
T _collectBytes<T>(
Stream<List<int>> source,
T result(
StreamSubscription<List<int>> subscription, Future<Uint8List> result)) {
T _collectBytes<T>(Stream<List<int>> source,
T Function(StreamSubscription<List<int>>, Future<Uint8List>) result) {
var byteLists = <List<int>>[];
var length = 0;
var completer = Completer<Uint8List>.sync();
Expand All @@ -63,7 +61,7 @@ T _collectBytes<T>(
// Join a lists of bytes with a known total length into a single [Uint8List].
Uint8List _collect(int length, List<List<int>> byteLists) {
var result = Uint8List(length);
int i = 0;
var i = 0;
for (var byteList in byteLists) {
var end = i + byteList.length;
result.setRange(i, end, byteList);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/async/lib/src/cancelable_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CancelableOperation<T> {
/// [onCancel] will be called synchronously when the operation is canceled.
/// It's guaranteed to only be called once.
factory CancelableOperation.fromFuture(Future<T> inner,
{FutureOr onCancel()}) {
{FutureOr Function() onCancel}) {
var completer = CancelableCompleter<T>(onCancel: onCancel);
completer.complete(inner);
return completer.operation;
Expand Down Expand Up @@ -145,7 +145,7 @@ class CancelableCompleter<T> {
///
/// [onCancel] will be called synchronously when the operation is canceled.
/// It's guaranteed to only be called once.
CancelableCompleter({FutureOr onCancel()})
CancelableCompleter({FutureOr Function() onCancel})
: _onCancel = onCancel,
_inner = Completer<T>() {
_operation = CancelableOperation<T>._(this);
Expand All @@ -171,7 +171,7 @@ class CancelableCompleter<T> {
/// If [value] is a [Future], this will complete to the result of that
/// [Future] once it completes.
void complete([value]) {
if (_isCompleted) throw StateError("Operation already completed");
if (_isCompleted) throw StateError('Operation already completed');
_isCompleted = true;

if (value is! Future) {
Expand All @@ -197,7 +197,7 @@ class CancelableCompleter<T> {

/// Completes [operation] to [error].
void completeError(Object error, [StackTrace stackTrace]) {
if (_isCompleted) throw StateError("Operation already completed");
if (_isCompleted) throw StateError('Operation already completed');
_isCompleted = true;

if (_isCanceled) return;
Expand Down
3 changes: 3 additions & 0 deletions pkgs/async/lib/src/delegate/event_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ class DelegatingEventSink<T> implements EventSink<T> {
static EventSink<T> typed<T>(EventSink sink) =>
sink is EventSink<T> ? sink : DelegatingEventSink._(sink);

@override
void add(T data) {
_sink.add(data);
}

@override
void addError(error, [StackTrace stackTrace]) {
_sink.addError(error, stackTrace);
}

@override
void close() {
_sink.close();
}
Expand Down
13 changes: 9 additions & 4 deletions pkgs/async/lib/src/delegate/future.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ class DelegatingFuture<T> implements Future<T> {
static Future<T> typed<T>(Future future) =>
future is Future<T> ? future : future.then((v) => v as T);

@override
Stream<T> asStream() => _future.asStream();

Future<T> catchError(Function onError, {bool test(Object error)}) =>
@override
Future<T> catchError(Function onError, {bool Function(Object error) test}) =>
_future.catchError(onError, test: test);

Future<S> then<S>(FutureOr<S> onValue(T value), {Function onError}) =>
@override
Future<S> then<S>(FutureOr<S> Function(T) onValue, {Function onError}) =>
_future.then(onValue, onError: onError);

Future<T> whenComplete(action()) => _future.whenComplete(action);
@override
Future<T> whenComplete(FutureOr action) => _future.whenComplete(action);

Future<T> timeout(Duration timeLimit, {onTimeout()}) =>
@override
Future<T> timeout(Duration timeLimit, {FutureOr<T> Function() onTimeout}) =>
_future.timeout(timeLimit, onTimeout: onTimeout);
}
2 changes: 2 additions & 0 deletions pkgs/async/lib/src/delegate/sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class DelegatingSink<T> implements Sink<T> {
static Sink<T> typed<T>(Sink sink) =>
sink is Sink<T> ? sink : DelegatingSink._(sink);

@override
void add(T data) {
_sink.add(data);
}

@override
void close() {
_sink.close();
}
Expand Down
2 changes: 2 additions & 0 deletions pkgs/async/lib/src/delegate/stream_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class DelegatingStreamConsumer<T> implements StreamConsumer<T> {
? consumer
: DelegatingStreamConsumer._(consumer);

@override
Future addStream(Stream<T> stream) => _consumer.addStream(stream);

@override
Future close() => _consumer.close();
}
5 changes: 5 additions & 0 deletions pkgs/async/lib/src/delegate/stream_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'dart:async';
class DelegatingStreamSink<T> implements StreamSink<T> {
final StreamSink _sink;

@override
Future get done => _sink.done;

/// Create delegating sink forwarding calls to [sink].
Expand All @@ -27,15 +28,19 @@ class DelegatingStreamSink<T> implements StreamSink<T> {
static StreamSink<T> typed<T>(StreamSink sink) =>
sink is StreamSink<T> ? sink : DelegatingStreamSink._(sink);

@override
void add(T data) {
_sink.add(data);
}

@override
void addError(error, [StackTrace stackTrace]) {
_sink.addError(error, stackTrace);
}

@override
Future addStream(Stream<T> stream) => _sink.addStream(stream);

@override
Future close() => _sink.close();
}
12 changes: 10 additions & 2 deletions pkgs/async/lib/src/delegate/stream_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,37 @@ class DelegatingStreamSubscription<T> implements StreamSubscription<T> {
? subscription
: TypeSafeStreamSubscription<T>(subscription);

void onData(void handleData(T data)) {
@override
void onData(void Function(T) handleData) {
_source.onData(handleData);
}

@override
void onError(Function handleError) {
_source.onError(handleError);
}

void onDone(void handleDone()) {
@override
void onDone(void Function() handleDone) {
_source.onDone(handleDone);
}

@override
void pause([Future resumeFuture]) {
_source.pause(resumeFuture);
}

@override
void resume() {
_source.resume();
}

@override
Future cancel() => _source.cancel();

@override
Future<E> asFuture<E>([E futureValue]) => _source.asFuture(futureValue);

@override
bool get isPaused => _source.isPaused;
}
14 changes: 6 additions & 8 deletions pkgs/async/lib/src/future_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,21 @@ class FutureGroup<T> implements Sink<Future<T>> {
///
/// Once this group isn't waiting on any futures *and* [close] has been
/// called, this stream will close.
Stream get onIdle {
if (_onIdleController == null) {
_onIdleController = StreamController.broadcast(sync: true);
}
return _onIdleController.stream;
}
Stream get onIdle =>
(_onIdleController ??= StreamController.broadcast(sync: true)).stream;

StreamController _onIdleController;

/// The values emitted by the futures that have been added to the group, in
/// the order they were added.
///
/// The slots for futures that haven't completed yet are `null`.
final _values = List<T>();
final _values = <T>[];

/// Wait for [task] to complete.
@override
void add(Future<T> task) {
if (_closed) throw StateError("The FutureGroup is closed.");
if (_closed) throw StateError('The FutureGroup is closed.');

// Ensure that future values are put into [values] in the same order they're
// added to the group by pre-allocating a slot for them and recording its
Expand Down Expand Up @@ -87,6 +84,7 @@ class FutureGroup<T> implements Sink<Future<T>> {

/// Signals to the group that the caller is done adding futures, and so
/// [future] should fire once all added futures have completed.
@override
void close() {
_closed = true;
if (_pending != 0) return;
Expand Down
17 changes: 9 additions & 8 deletions pkgs/async/lib/src/lazy_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import "dart:async";
import 'dart:async';

import "delegate/stream.dart";
import "stream_completer.dart";
import "utils.dart";
import 'delegate/stream.dart';
import 'stream_completer.dart';
import 'utils.dart';

/// A [Stream] wrapper that forwards to another [Stream] that's initialized
/// lazily.
Expand All @@ -20,15 +20,16 @@ class LazyStream<T> extends Stream<T> {

/// Creates a single-subscription `Stream` that calls [callback] when it gets
/// a listener and forwards to the returned stream.
LazyStream(FutureOr<Stream<T>> callback()) : _callback = callback {
LazyStream(FutureOr<Stream<T>> Function() callback) : _callback = callback {
// Explicitly check for null because we null out [_callback] internally.
if (_callback == null) throw ArgumentError.notNull('callback');
}

StreamSubscription<T> listen(void onData(T event),
{Function onError, void onDone(), bool cancelOnError}) {
@override
StreamSubscription<T> listen(void Function(T) onData,
{Function onError, void Function() onDone, bool cancelOnError}) {
if (_callback == null) {
throw StateError("Stream has already been listened to.");
throw StateError('Stream has already been listened to.');
}

// Null out the callback before we invoke it to ensure that even while
Expand Down
Loading

0 comments on commit 6299483

Please sign in to comment.