Skip to content

Commit

Permalink
Prepare for the latest dart_flutter_team_lints (#2127)
Browse files Browse the repository at this point in the history
Eagerly apply autofixes and manual fixes in the code before landing
dependabot PRs #2124 and #2125

Ignore the `comment_references` lint since there are false positives
(likely amongst true positives) in these packages.
  • Loading branch information
natebosch authored Oct 20, 2023
1 parent 6ac4ff9 commit 5420745
Show file tree
Hide file tree
Showing 56 changed files with 193 additions and 181 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ analyzer:
# Ignoring a number of lints from dart_flutter_team_lints – for now
avoid_catching_errors: ignore
avoid_dynamic_calls: ignore
comment_references: ignore
lines_longer_than_80_chars: ignore
only_throw_errors: ignore
unawaited_futures: ignore
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/lib/src/runner/browser/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract class Browser {
// resolve the ambiguity is to wait a brief amount of time and see if this
// browser is actually closed.
if (!_closed && exitCode < 0) {
await Future.delayed(Duration(milliseconds: 200));
await Future<void>.delayed(const Duration(milliseconds: 200));
}

if (!_closed && exitCode != 0) {
Expand Down
6 changes: 3 additions & 3 deletions pkgs/test/lib/src/runner/browser/browser_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class BrowserManager {
completer.completeError(error, stackTrace);
});

return completer.future.timeout(Duration(seconds: 30), onTimeout: () {
return completer.future.timeout(const Duration(seconds: 30), onTimeout: () {
browser.close();
if (attempt >= _maxRetries) {
throw ApplicationException(
Expand Down Expand Up @@ -174,7 +174,7 @@ class BrowserManager {
//
// Start this canceled because we don't want it to start ticking until we
// get some response from the iframe.
_timer = RestartableTimer(Duration(seconds: 3), () {
_timer = RestartableTimer(const Duration(seconds: 3), () {
for (var controller in _controllers) {
controller.setDebugging(true);
}
Expand Down Expand Up @@ -335,7 +335,7 @@ class BrowserManager {
_controllers.clear();
return _browser.close();
});
final _closeMemoizer = AsyncMemoizer();
final _closeMemoizer = AsyncMemoizer<void>();
}

/// An implementation of [Environment] for the browser.
Expand Down
9 changes: 4 additions & 5 deletions pkgs/test/lib/src/runner/browser/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ class Chrome extends Browser {
return coverage;
}

Chrome._(Future<Process> Function() startBrowser, this.remoteDebuggerUrl,
this._tabConnection, this._idToUrl)
: super(startBrowser);
Chrome._(super.startBrowser, this.remoteDebuggerUrl, this._tabConnection,
this._idToUrl);

Future<Uri?> _sourceUriProvider(String sourceUrl, String scriptId) async {
var script = _idToUrl[scriptId];
Expand Down Expand Up @@ -136,7 +135,7 @@ Future<WipConnection> _connect(
// Wait for Chrome to be in a ready state.
await process.stderr
.transform(utf8.decoder)
.transform(LineSplitter())
.transform(const LineSplitter())
.firstWhere((line) => line.startsWith('DevTools listening'));

var chromeConnection = ChromeConnection('localhost', port);
Expand All @@ -147,7 +146,7 @@ Future<WipConnection> _connect(
var tabs = await chromeConnection.getTabs();
tab = tabs.firstWhereOrNull((tab) => tab.url == url.toString());
if (tab == null) {
await Future.delayed(Duration(milliseconds: 100));
await Future<void>.delayed(const Duration(milliseconds: 100));
if (attempt > 5) {
throw StateError('Could not connect to test tab with url: $url');
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/lib/src/runner/browser/chromium.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import 'dart:async';
import 'dart:io';

import 'package:test/src/runner/browser/default_settings.dart';
import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports

import '../executable_settings.dart';
import 'default_settings.dart';

enum ChromiumBasedBrowser {
chrome(Runtime.chrome),
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/lib/src/runner/browser/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ extension EventTargetExtension on EventTarget {
void addEventListener(String type, EventListener? listener,
[bool? useCapture]) {
if (listener != null) {
js_util.callMethod(this, 'addEventListener',
js_util.callMethod<void>(this, 'addEventListener',
<Object>[type, listener, if (useCapture != null) useCapture]);
}
}

void removeEventListener(String type, EventListener? listener,
[bool? useCapture]) {
if (listener != null) {
js_util.callMethod(this, 'removeEventListener',
js_util.callMethod<void>(this, 'removeEventListener',
<Object>[type, listener, if (useCapture != null) useCapture]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkgs/test/lib/src/runner/browser/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class BrowserPlatform extends PlatformPlugin
.add(_wrapperHandler);
}

var pipeline = shelf.Pipeline()
var pipeline = const shelf.Pipeline()
.addMiddleware(PathHandler.nestedIn(_secret))
.addHandler(cascade.handler);

Expand Down Expand Up @@ -305,7 +305,7 @@ class BrowserPlatform extends PlatformPlugin
Future<void> _pubServeSuite(String path, Uri dartUrl, Runtime browser,
SuiteConfiguration suiteConfig) {
return _pubServePool.withResource(() async {
var timer = Timer(Duration(seconds: 1), () {
var timer = Timer(const Duration(seconds: 1), () {
print('"pub serve" is compiling $path...');
});

Expand All @@ -317,7 +317,7 @@ class BrowserPlatform extends PlatformPlugin

if (response.statusCode != 200) {
// Drain response to avoid VM hang.
response.drain();
response.drain<void>();

throw LoadException(
path,
Expand All @@ -328,7 +328,7 @@ class BrowserPlatform extends PlatformPlugin

if (suiteConfig.jsTrace) {
// Drain response to avoid VM hang.
response.drain();
response.drain<void>();
return;
}
_mappers[path] = JSStackTraceMapper(await utf8.decodeStream(response),
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/lib/src/runner/node/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class NodePlatform extends PlatformPlugin
'Unsupported compiler for the Node platform ${platform.compiler}.');
}
var pair = await _loadChannel(path, platform, suiteConfig);
var controller = deserializeSuite(
path, platform, suiteConfig, PluginEnvironment(), pair.first, message);
var controller = deserializeSuite(path, platform, suiteConfig,
const PluginEnvironment(), pair.first, message);

controller.channel('test.node.mapper').sink.add(pair.last?.serialize());

Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/lib/src/runner/wasm/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class BrowserWasmPlatform extends PlatformPlugin
.add(createStaticHandler(_root))
.add(_wrapperHandler);

var pipeline = shelf.Pipeline()
var pipeline = const shelf.Pipeline()
.addMiddleware(PathHandler.nestedIn(_secret))
.addHandler(cascade.handler);

Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:test/test.dart';

void myTest(String name, Function() testFn) => test(name, testFn);
void myTest(String name, void Function() testFn) => test(name, testFn);
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/browser/chrome_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ webSocket.addEventListener("open", function() {
},
// It's not clear why, but this test in particular seems to time out
// when run in parallel with many other tests.
timeout: Timeout.factor(2));
timeout: const Timeout.factor(2));

test("a process can be killed synchronously after it's started", () async {
var server = await CodeServer.start();
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/browser/microsoft_edge_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ webSocket.addEventListener("open", function() {
addTearDown(() => edge.close());

expect(await (await webSocket).stream.first, equals('loaded!'));
}, timeout: Timeout.factor(2));
}, timeout: const Timeout.factor(2));

test('reports an error in onExit', () {
var edge = MicrosoftEdge(Uri.parse('https://dart.dev'), configuration(),
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/configuration/top_level_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand Down
8 changes: 4 additions & 4 deletions pkgs/test/test/runner/engine_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
});

test('returns fail if any test does not complete', () async {
var completer = Completer();
var completer = Completer<void>();
var engine = declareEngine(() {
test('completes', () {});
test('does not complete', () async {
Expand Down Expand Up @@ -161,15 +161,15 @@ void main() {
var engine = declareEngine(() {
// This ensures that the first test doesn't actually finish until the
// second test runs.
var firstTestCompleter = Completer();
var firstTestCompleter = Completer<void>();

group('group', () {
tearDown(tearDownBody);

test('first test', () async {
await firstTestCompleter.future;
firstTestFinished = true;
}, timeout: Timeout(Duration.zero));
}, timeout: const Timeout(Duration.zero));
});

test('second test', () {
Expand Down Expand Up @@ -311,7 +311,7 @@ void main() {
}
// Simulate the test/loading taking some amount of time so that
// we actually reach max concurrency.
await Future.delayed(Duration(milliseconds: 100));
await Future<void>.delayed(const Duration(milliseconds: 100));
if (!isLoadSuite) {
testsRunning--;
testsLoaded--;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/test/test/runner/load_suite_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ void main() {

var liveTest = (suite.group.entries.single as Test).load(suite);
expect(liveTest.run(), completes);
await Future.delayed(Duration.zero);
await Future<void>.delayed(Duration.zero);
expect(liveTest.state.status, equals(Status.running));

completer.complete(innerSuite);
await Future.delayed(Duration.zero);
await Future<void>.delayed(Duration.zero);
expectTestPassed(liveTest);
});

Expand All @@ -84,7 +84,7 @@ void main() {

var liveTest = (suite.group.entries.single as Test).load(suite);
expect(liveTest.run(), completes);
await Future.delayed(Duration.zero);
await Future<void>.delayed(Duration.zero);
expect(liveTest.state.status, equals(Status.running));

expect(liveTest.close(), completes);
Expand Down
6 changes: 3 additions & 3 deletions pkgs/test/test/runner/parse_metadata_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ library foo;
''', {});
expect(
metadata.timeout.duration,
equals(Duration(
equals(const Duration(
hours: 1,
minutes: 2,
seconds: 3,
Expand All @@ -102,7 +102,7 @@ library foo;
''', {});
expect(
metadata.timeout.duration,
equals(Duration(
equals(const Duration(
hours: 1,
minutes: 2,
seconds: 3,
Expand All @@ -122,7 +122,7 @@ import 'dart:core' as core;
''', {});
expect(
metadata.timeout.duration,
equals(Duration(
equals(const Duration(
hours: 1,
minutes: 2,
seconds: 3,
Expand Down
14 changes: 7 additions & 7 deletions pkgs/test/test/runner/pause_after_load_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand All @@ -76,7 +76,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand Down Expand Up @@ -122,7 +122,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand All @@ -144,7 +144,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand All @@ -165,7 +165,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand Down Expand Up @@ -232,7 +232,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand Down Expand Up @@ -272,7 +272,7 @@ void main() {

// Wait a little bit to be sure that the tests don't start running without
// our input.
await Future.delayed(Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
expect(nextLineFired, isFalse);

test.stdin.writeln();
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/test/runner/signal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main() {
// TODO(nweiz): Sending two signals in close succession can cause the
// second one to be ignored, so we wait a bit before the second
// one. Remove this hack when issue 23047 is fixed.
await Future.delayed(Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));

await signalAndQuit(test);
});
Expand Down Expand Up @@ -179,7 +179,7 @@ void main() {
// TODO(nweiz): Sending two signals in close succession can cause the
// second one to be ignored, so we wait a bit before the second
// one. Remove this hack when issue 23047 is fixed.
await Future.delayed(Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
await signalAndQuit(test);
});

Expand Down
6 changes: 3 additions & 3 deletions pkgs/test/tool/host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void main() {

// Send periodic pings to the test runner so it can know when the browser is
// paused for debugging.
Timer.periodic(Duration(seconds: 1),
Timer.periodic(const Duration(seconds: 1),
(_) => serverChannel.sink.add({'command': 'ping'}));

var play = dom.document.querySelector('#play');
Expand Down Expand Up @@ -167,7 +167,7 @@ MultiChannel<dynamic> _connectToServer() {
var webSocket =
dom.createWebSocket(_currentUrl.queryParameters['managerUrl']!);

var controller = StreamChannelController(sync: true);
var controller = StreamChannelController<Object?>(sync: true);
webSocket.addEventListener('message', allowInterop((message) {
controller.local.sink
.add(jsonDecode((message as dom.MessageEvent).data as String));
Expand Down Expand Up @@ -205,7 +205,7 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
dom.window.console.log('Starting suite $suiteUrl');
var iframe = dom.createHTMLIFrameElement();
_iframes[id] = iframe;
var controller = StreamChannelController(sync: true);
var controller = StreamChannelController<Object?>(sync: true);

late dom.Subscription windowSubscription;
windowSubscription =
Expand Down
Loading

0 comments on commit 5420745

Please sign in to comment.