Prefer void to null (#22977)

* Future<void> main

* Future<void>.delayed

* prefer_void_to_Null

* address review comments
This commit is contained in:
Alexandre Ardhuin
2018-10-16 22:03:06 +02:00
committed by GitHub
parent 5efe095895
commit 0fb84e96c7
139 changed files with 373 additions and 385 deletions

View File

@@ -29,7 +29,7 @@ class _DummyPortForwarder implements PortForwarder {
int get remotePort => _remotePort;
@override
Future<Null> stop() async {}
Future<void> stop() async {}
}
class _DummySshCommandRunner implements SshCommandRunner {

View File

@@ -242,7 +242,7 @@ class FlutterDriver {
isolate.pauseEvent is! VMPauseExceptionEvent &&
isolate.pauseEvent is! VMPauseInterruptedEvent &&
isolate.pauseEvent is! VMResumeEvent) {
await Future<Null>.delayed(_kShortTimeout ~/ 10);
await Future<void>.delayed(_kShortTimeout ~/ 10);
isolate = await isolateRef.loadRunnable();
}
@@ -288,7 +288,7 @@ class FlutterDriver {
/// results in lost events.
///
/// Details: https://github.com/dart-lang/vm_service_client/issues/17
Future<Null> enableIsolateStreams() async {
Future<void> enableIsolateStreams() async {
await connection.peer.sendRequest('streamListen', <String, String>{
'streamId': 'Isolate',
});
@@ -427,30 +427,26 @@ class FlutterDriver {
}
/// Taps at the center of the widget located by [finder].
Future<Null> tap(SerializableFinder finder, {Duration timeout}) async {
Future<void> tap(SerializableFinder finder, {Duration timeout}) async {
await _sendCommand(Tap(finder, timeout: timeout));
return null;
}
/// Waits until [finder] locates the target.
Future<Null> waitFor(SerializableFinder finder, {Duration timeout}) async {
Future<void> waitFor(SerializableFinder finder, {Duration timeout}) async {
await _sendCommand(WaitFor(finder, timeout: timeout));
return null;
}
/// Waits until [finder] can no longer locate the target.
Future<Null> waitForAbsent(SerializableFinder finder, {Duration timeout}) async {
Future<void> waitForAbsent(SerializableFinder finder, {Duration timeout}) async {
await _sendCommand(WaitForAbsent(finder, timeout: timeout));
return null;
}
/// Waits until there are no more transient callbacks in the queue.
///
/// Use this method when you need to wait for the moment when the application
/// becomes "stable", for example, prior to taking a [screenshot].
Future<Null> waitUntilNoTransientCallbacks({Duration timeout}) async {
Future<void> waitUntilNoTransientCallbacks({Duration timeout}) async {
await _sendCommand(WaitUntilNoTransientCallbacks(timeout: timeout));
return null;
}
/// Tell the driver to perform a scrolling action.
@@ -466,8 +462,8 @@ class FlutterDriver {
///
/// The move events are generated at a given [frequency] in Hz (or events per
/// second). It defaults to 60Hz.
Future<Null> scroll(SerializableFinder finder, double dx, double dy, Duration duration, { int frequency = 60, Duration timeout }) async {
return await _sendCommand(Scroll(finder, dx, dy, duration, frequency, timeout: timeout)).then<Null>((Map<String, dynamic> _) => null);
Future<void> scroll(SerializableFinder finder, double dx, double dy, Duration duration, { int frequency = 60, Duration timeout }) async {
await _sendCommand(Scroll(finder, dx, dy, duration, frequency, timeout: timeout));
}
/// Scrolls the Scrollable ancestor of the widget located by [finder]
@@ -477,8 +473,8 @@ class FlutterDriver {
/// that lazily creates its children, like [ListView] or [CustomScrollView],
/// then this method may fail because [finder] doesn't actually exist.
/// The [scrollUntilVisible] method can be used in this case.
Future<Null> scrollIntoView(SerializableFinder finder, { double alignment = 0.0, Duration timeout }) async {
return await _sendCommand(ScrollIntoView(finder, alignment: alignment, timeout: timeout)).then<Null>((Map<String, dynamic> _) => null);
Future<void> scrollIntoView(SerializableFinder finder, { double alignment = 0.0, Duration timeout }) async {
await _sendCommand(ScrollIntoView(finder, alignment: alignment, timeout: timeout));
}
/// Repeatedly [scroll] the widget located by [scrollable] by [dxScroll] and
@@ -503,7 +499,7 @@ class FlutterDriver {
///
/// The [timeout] value should be long enough to accommodate as many scrolls
/// as needed to bring an item into view. The default is 10 seconds.
Future<Null> scrollUntilVisible(SerializableFinder scrollable, SerializableFinder item, {
Future<void> scrollUntilVisible(SerializableFinder scrollable, SerializableFinder item, {
double alignment = 0.0,
double dxScroll = 0.0,
double dyScroll = 0.0,
@@ -522,11 +518,11 @@ class FlutterDriver {
// the chance to complete if the item is already onscreen; if not, scroll
// repeatedly until we either find the item or time out.
bool isVisible = false;
waitFor(item, timeout: timeout).then<void>((Null value) { isVisible = true; });
await Future<Null>.delayed(const Duration(milliseconds: 500));
waitFor(item, timeout: timeout).then<void>((_) { isVisible = true; });
await Future<void>.delayed(const Duration(milliseconds: 500));
while (!isVisible) {
await scroll(scrollable, dxScroll, dyScroll, const Duration(milliseconds: 100));
await Future<Null>.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
return scrollIntoView(item, alignment: alignment);
@@ -569,7 +565,7 @@ class FlutterDriver {
/// await driver.waitFor(find.text('World!')); // verify new text appears
/// });
/// ```
Future<Null> enterText(String text, { Duration timeout }) async {
Future<void> enterText(String text, { Duration timeout }) async {
await _sendCommand(EnterText(text, timeout: timeout));
}
@@ -586,7 +582,7 @@ class FlutterDriver {
/// When enabled, the operating system's configured keyboard will not be
/// invoked when the widget is focused, as the [SystemChannels.textInput]
/// channel will be mocked out.
Future<Null> setTextEntryEmulation({ @required bool enabled, Duration timeout }) async {
Future<void> setTextEntryEmulation({ @required bool enabled, Duration timeout }) async {
assert(enabled != null);
await _sendCommand(SetTextEntryEmulation(enabled, timeout: timeout));
}
@@ -661,7 +657,7 @@ class FlutterDriver {
// The two-second gap should be long enough for the GPU thread to
// finish rasterizing the frame, but not longer than necessary to keep
// driver tests as fast a possible.
await Future<Null>.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
final Map<String, dynamic> result = await _peer.sendRequest('_flutter.screenshot').timeout(timeout);
return base64.decode(result['screenshot']);
@@ -692,7 +688,7 @@ class FlutterDriver {
}
/// Starts recording performance traces.
Future<Null> startTracing({
Future<void> startTracing({
List<TimelineStream> streams = _defaultStreams,
Duration timeout = _kShortTimeout,
}) async {
@@ -701,7 +697,6 @@ class FlutterDriver {
await _peer.sendRequest(_setVMTimelineFlagsMethodName, <String, String>{
'recordedStreams': _timelineStreamsToString(streams)
}).timeout(timeout);
return null;
} catch (error, stackTrace) {
throw DriverError(
'Failed to start tracing due to remote error',
@@ -755,7 +750,7 @@ class FlutterDriver {
}
/// Clears all timeline events recorded up until now.
Future<Null> clearTimeline({ Duration timeout = _kShortTimeout }) async {
Future<void> clearTimeline({ Duration timeout = _kShortTimeout }) async {
try {
await _peer
.sendRequest(_clearVMTimelineMethodName, <String, String>{})
@@ -799,7 +794,7 @@ class FlutterDriver {
/// Closes the underlying connection to the VM service.
///
/// Returns a [Future] that fires once the connection has been closed.
Future<Null> close() async {
Future<void> close() async {
// Don't leak vm_service_client-specific objects, if any
await _serviceClient.close();
await _peer.close();
@@ -863,7 +858,7 @@ Future<VMServiceClientConnection> _waitAndConnect(String url) async {
if (timer.elapsed < _kLongTimeout * 2) {
_log.info('Waiting for application to start');
await Future<Null>.delayed(_kPauseBetweenReconnectAttempts);
await Future<void>.delayed(_kPauseBetweenReconnectAttempts);
return attemptConnection();
} else {
_log.critical(

View File

@@ -107,7 +107,7 @@ class TimelineSummary {
}
/// Writes all of the recorded timeline data to a file.
Future<Null> writeTimelineToFile(
Future<void> writeTimelineToFile(
String traceName, {
String destinationDirectory,
bool pretty = false,
@@ -119,7 +119,7 @@ class TimelineSummary {
}
/// Writes [summaryJson] to a file.
Future<Null> writeSummaryToFile(
Future<void> writeSummaryToFile(
String traceName, {
String destinationDirectory,
bool pretty = false,

View File

@@ -205,8 +205,8 @@ class FlutterDriverExtension {
}
// Waits until at the end of a frame the provided [condition] is [true].
Future<Null> _waitUntilFrame(bool condition(), [Completer<Null> completer]) {
completer ??= Completer<Null>();
Future<void> _waitUntilFrame(bool condition(), [Completer<void> completer]) {
completer ??= Completer<void>();
if (!condition()) {
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
_waitUntilFrame(condition, completer);
@@ -317,9 +317,10 @@ class FlutterDriverExtension {
return WaitForAbsentResult();
}
Future<Null> _waitUntilNoTransientCallbacks(Command command) async {
Future<Result> _waitUntilNoTransientCallbacks(Command command) async {
if (SchedulerBinding.instance.transientCallbackCount != 0)
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
return null;
}
Future<GetSemanticsIdResult> _getSemanticsId(Command command) async {
@@ -350,11 +351,11 @@ class FlutterDriverExtension {
_prober.binding.hitTest(hitTest, startLocation);
_prober.binding.dispatchEvent(pointer.down(startLocation), hitTest);
await Future<Null>.value(); // so that down and move don't happen in the same microtask
await Future<void>.value(); // so that down and move don't happen in the same microtask
for (int moves = 0; moves < totalMoves; moves += 1) {
currentLocation = currentLocation + delta;
_prober.binding.dispatchEvent(pointer.move(currentLocation), hitTest);
await Future<Null>.delayed(pause);
await Future<void>.delayed(pause);
}
_prober.binding.dispatchEvent(pointer.up(), hitTest);
@@ -417,7 +418,7 @@ class FlutterDriverExtension {
_semantics = RendererBinding.instance.pipelineOwner.ensureSemantics();
if (!semanticsWasEnabled) {
// wait for the first frame where semantics is enabled.
final Completer<Null> completer = Completer<Null>();
final Completer<void> completer = Completer<void>();
SchedulerBinding.instance.addPostFrameCallback((Duration d) {
completer.complete();
});

View File

@@ -64,7 +64,7 @@ void main() {
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
connectionLog.add('resume');
return Future<Null>.value();
return Future<dynamic>.value(null);
});
when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
connectionLog.add('onExtensionAdded');
@@ -79,7 +79,7 @@ void main() {
test('connects to isolate paused mid-flight', () async {
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<Null>.value());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull);
@@ -95,7 +95,7 @@ void main() {
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
// This needs to be wrapped in a closure to not be considered uncaught
// by package:test
return Future<Null>.error(rpc.RpcException(101, ''));
return Future<dynamic>.error(rpc.RpcException(101, ''));
});
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
@@ -132,7 +132,7 @@ void main() {
});
test('closes connection', () async {
when(mockClient.close()).thenAnswer((Invocation invocation) => Future<Null>.value());
when(mockClient.close()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
await driver.close();
});

View File

@@ -24,7 +24,7 @@ void main() {
testWidgets('returns immediately when transient callback queue is empty', (WidgetTester tester) async {
extension.call(WaitUntilNoTransientCallbacks().serialize())
.then<Null>(expectAsync1((Map<String, dynamic> r) {
.then<void>(expectAsync1((Map<String, dynamic> r) {
result = r;
}));
@@ -44,7 +44,7 @@ void main() {
});
extension.call(WaitUntilNoTransientCallbacks().serialize())
.then<Null>(expectAsync1((Map<String, dynamic> r) {
.then<void>(expectAsync1((Map<String, dynamic> r) {
result = r;
}));