Skip to content

Commit f04d941

Browse files
authored
[web] enable always_specify_types lint (flutter#27406)
1 parent 3649200 commit f04d941

File tree

100 files changed

+638
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+638
-612
lines changed

lib/web_ui/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ analyzer:
1313

1414
linter:
1515
rules:
16-
always_specify_types: false
1716
annotate_overrides: false
1817
avoid_classes_with_only_static_members: false
1918
avoid_empty_else: false

lib/web_ui/dev/browser.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ abstract class Browser {
7676
///
7777
/// This will fire once the process has started successfully.
7878
Future<Process> get _process => _processCompleter.future;
79-
final _processCompleter = Completer<Process>();
79+
final Completer<Process> _processCompleter = Completer<Process>();
8080

8181
/// Whether [close] has been called.
82-
var _closed = false;
82+
bool _closed = false;
8383

8484
/// A future that completes when the browser exits.
8585
///
8686
/// If there's a problem starting or running the browser, this will complete
8787
/// with an error.
8888
Future<void> get onExit => _onExitCompleter.future;
89-
final _onExitCompleter = Completer<void>();
89+
final Completer<void> _onExitCompleter = Completer<void>();
9090

9191
/// Standard IO streams for the underlying browser process.
92-
final _ioSubscriptions = <StreamSubscription>[];
92+
final List<StreamSubscription<void>> _ioSubscriptions = <StreamSubscription<void>>[];
9393

9494
/// Creates a new browser.
9595
///
@@ -102,10 +102,10 @@ abstract class Browser {
102102
// for the process to actually start. They should just wait for the HTTP
103103
// request instead.
104104
runZonedGuarded(() async {
105-
var process = await startBrowser();
105+
Process process = await startBrowser();
106106
_processCompleter.complete(process);
107107

108-
var output = Uint8Buffer();
108+
Uint8Buffer output = Uint8Buffer();
109109
void drainOutput(Stream<List<int>> stream) {
110110
try {
111111
_ioSubscriptions
@@ -117,7 +117,7 @@ abstract class Browser {
117117
drainOutput(process.stdout);
118118
drainOutput(process.stderr);
119119

120-
var exitCode = await process.exitCode;
120+
int exitCode = await process.exitCode;
121121

122122
// This hack dodges an otherwise intractable race condition. When the user
123123
// presses Control-C, the signal is sent to the browser and the test
@@ -134,8 +134,8 @@ abstract class Browser {
134134
}
135135

136136
if (!_closed && exitCode != 0) {
137-
var outputString = utf8.decode(output);
138-
var message = '$name failed with exit code $exitCode.';
137+
String outputString = utf8.decode(output);
138+
String message = '$name failed with exit code $exitCode.';
139139
if (outputString.isNotEmpty) {
140140
message += '\nStandard output:\n$outputString';
141141
}
@@ -151,7 +151,7 @@ abstract class Browser {
151151
}
152152

153153
// Make sure the process dies even if the error wasn't fatal.
154-
_process.then((process) => process.kill());
154+
_process.then((Process process) => process.kill());
155155

156156
if (stackTrace == null) {
157157
stackTrace = Trace.current();
@@ -170,13 +170,13 @@ abstract class Browser {
170170
///
171171
/// Returns the same [Future] as [onExit], except that it won't emit
172172
/// exceptions.
173-
Future close() async {
173+
Future<void> close() async {
174174
_closed = true;
175175

176176
// If we don't manually close the stream the test runner can hang.
177177
// For example this happens with Chrome Headless.
178178
// See SDK issue: https://github.com/dart-lang/sdk/issues/31264
179-
for (var stream in _ioSubscriptions) {
179+
for (StreamSubscription<void> stream in _ioSubscriptions) {
180180
unawaited(stream.cancel());
181181
}
182182

@@ -192,7 +192,7 @@ abstract class ScreenshotManager {
192192
/// Capture a screenshot.
193193
///
194194
/// Please read the details for the implementing classes.
195-
Future<Image> capture(math.Rectangle region);
195+
Future<Image> capture(math.Rectangle<num> region);
196196

197197
/// Suffix to be added to the end of the filename.
198198
///

lib/web_ui/dev/build.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import 'dart:async';
77

88
import 'package:args/command_runner.dart';
99
import 'package:path/path.dart' as path;
10+
import 'package:watcher/src/watch_event.dart';
1011

1112
import 'environment.dart';
1213
import 'utils.dart';
1314
import 'watcher.dart';
1415

15-
class BuildCommand extends Command<bool> with ArgUtils {
16+
class BuildCommand extends Command<bool> with ArgUtils<bool> {
1617
BuildCommand() {
1718
argParser
1819
..addFlag(
@@ -48,7 +49,7 @@ class BuildCommand extends Command<bool> with ArgUtils {
4849
dir: libPath.absolute,
4950
pipeline: buildPipeline,
5051
// Ignore font files that are copied whenever tests run.
51-
ignore: (event) => event.path.endsWith('.ttf'),
52+
ignore: (WatchEvent event) => event.path.endsWith('.ttf'),
5253
).start();
5354
}
5455
return true;

lib/web_ui/dev/chrome.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ChromeEnvironment implements BrowserEnvironment {
5151
/// Any errors starting or running the process are reported through [onExit].
5252
class Chrome extends Browser {
5353
@override
54-
final name = 'Chrome';
54+
final String name = 'Chrome';
5555

5656
@override
5757
final Future<Uri> remoteDebuggerUrl;
@@ -60,7 +60,7 @@ class Chrome extends Browser {
6060
/// [Uri] or a [String].
6161
factory Chrome(Uri url, {bool debug = false}) {
6262
String version = ChromeArgParser.instance.version;
63-
var remoteDebuggerCompleter = Completer<Uri>.sync();
63+
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
6464
return Chrome._(() async {
6565
final BrowserInstallation installation = await getOrInstallChrome(
6666
version,
@@ -80,7 +80,7 @@ class Chrome extends Browser {
8080
final bool isChromeNoSandbox =
8181
Platform.environment['CHROME_NO_SANDBOX'] == 'true';
8282
final String dir = environment.webUiDartToolDir.createTempSync('test_chrome_user_data_').resolveSymbolicLinksSync();
83-
var args = [
83+
List<String> args = <String>[
8484
'--user-data-dir=$dir',
8585
url.toString(),
8686
if (!debug)
@@ -218,7 +218,7 @@ class ChromeScreenshotManager extends ScreenshotManager {
218218
/// [region] is used to decide which part of the web content will be used in
219219
/// test image. It includes starting coordinate x,y as well as height and
220220
/// width of the area to capture.
221-
Future<Image> capture(math.Rectangle? region) async {
221+
Future<Image> capture(math.Rectangle<num>? region) async {
222222
final wip.ChromeConnection chromeConnection =
223223
wip.ChromeConnection('localhost', kDevtoolsPort);
224224
final wip.ChromeTab? chromeTab = await chromeConnection.getTab(

lib/web_ui/dev/chrome_installer.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:io' as io;
7+
import 'dart:typed_data';
78

89
import 'package:archive/archive.dart';
910
import 'package:archive/archive_io.dart';
@@ -220,15 +221,15 @@ class ChromeInstaller {
220221
final Stopwatch stopwatch = Stopwatch()..start();
221222

222223
// Read the Zip file from disk.
223-
final bytes = downloadedFile.readAsBytesSync();
224+
final Uint8List bytes = downloadedFile.readAsBytesSync();
224225

225226
final Archive archive = ZipDecoder().decodeBytes(bytes);
226227

227228
// Extract the contents of the Zip archive to disk.
228229
for (final ArchiveFile file in archive) {
229230
final String filename = file.name;
230231
if (file.isFile) {
231-
final data = file.content as List<int>;
232+
final List<int> data = file.content as List<int>;
232233
io.File(path.join(versionDir.path, filename))
233234
..createSync(recursive: true)
234235
..writeAsBytesSync(data);

lib/web_ui/dev/clean.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:path/path.dart' as path;
1111
import 'environment.dart';
1212
import 'utils.dart';
1313

14-
class CleanCommand extends Command<bool> with ArgUtils {
14+
class CleanCommand extends Command<bool> with ArgUtils<bool> {
1515
CleanCommand() {
1616
argParser
1717
..addFlag(

lib/web_ui/dev/common.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class DevNull implements StringSink {
221221
void write(Object? obj) {}
222222

223223
@override
224-
void writeAll(Iterable objects, [String separator = ""]) {}
224+
void writeAll(Iterable<dynamic> objects, [String separator = ""]) {}
225225

226226
@override
227227
void writeCharCode(int charCode) {}

lib/web_ui/dev/create_simulator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:simulators/simulator_manager.dart';
1010
import 'safari_installation.dart';
1111
import 'utils.dart';
1212

13-
class CreateSimulatorCommand extends Command<bool> with ArgUtils {
13+
class CreateSimulatorCommand extends Command<bool> with ArgUtils<bool> {
1414
CreateSimulatorCommand() {
1515
IosSafariArgParser.instance.populateOptions(argParser);
1616
argParser

lib/web_ui/dev/edge.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EdgeEnvironment implements BrowserEnvironment {
4242
/// Any errors starting or running the process are reported through [onExit].
4343
class Edge extends Browser {
4444
@override
45-
final name = 'Edge';
45+
final String name = 'Edge';
4646

4747
/// Starts a new instance of Safari open to the given [url], which may be a
4848
/// [Uri] or a [String].
@@ -63,8 +63,10 @@ class Edge extends Browser {
6363
pathToOpen = pathToOpen.substring(0, index-1);
6464
}
6565

66-
var process =
67-
await Process.start(installation.executable, ['$pathToOpen','-k']);
66+
Process process = await Process.start(
67+
installation.executable,
68+
<String>['$pathToOpen','-k'],
69+
);
6870

6971
return process;
7072
});

lib/web_ui/dev/felt.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'exceptions.dart';
1414
import 'test_runner.dart';
1515
import 'utils.dart';
1616

17-
CommandRunner runner = CommandRunner<bool>(
17+
CommandRunner<bool> runner = CommandRunner<bool>(
1818
'felt',
1919
'Command-line utility for building and testing Flutter web engine.',
2020
)
@@ -26,7 +26,7 @@ CommandRunner runner = CommandRunner<bool>(
2626

2727
void main(List<String> rawArgs) async {
2828
// Remove --clean from the list as that's processed by the wrapper script.
29-
final List<String> args = rawArgs.where((arg) => arg != '--clean').toList();
29+
final List<String> args = rawArgs.where((String arg) => arg != '--clean').toList();
3030

3131
if (args.isEmpty) {
3232
// The felt tool was invoked with no arguments. Print usage.

lib/web_ui/dev/firefox.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FirefoxEnvironment implements BrowserEnvironment {
4747
/// Any errors starting or running the process are reported through [onExit].
4848
class Firefox extends Browser {
4949
@override
50-
final name = 'Firefox';
50+
final String name = 'Firefox';
5151

5252
@override
5353
final Future<Uri> remoteDebuggerUrl;
@@ -56,15 +56,15 @@ class Firefox extends Browser {
5656
/// [Uri] or a [String].
5757
factory Firefox(Uri url, {bool debug = false}) {
5858
final String version = FirefoxArgParser.instance.version;
59-
var remoteDebuggerCompleter = Completer<Uri>.sync();
59+
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
6060
return Firefox._(() async {
6161
final BrowserInstallation installation = await getOrInstallFirefox(
6262
version,
6363
infoLog: isCirrus ? stdout : DevNull(),
6464
);
6565

6666
// Using a profile on opening will prevent popups related to profiles.
67-
final _profile = '''
67+
final String _profile = '''
6868
user_pref("browser.shell.checkDefaultBrowser", false);
6969
user_pref("dom.disable_open_during_load", false);
7070
user_pref("dom.max_script_run_time", 0);
@@ -84,7 +84,7 @@ user_pref("dom.max_script_run_time", 0);
8484
File(path.join(temporaryProfileDirectory.path, 'prefs.js'))
8585
.writeAsStringSync(_profile);
8686
bool isMac = Platform.isMacOS;
87-
var args = [
87+
List<String> args = <String>[
8888
url.toString(),
8989
'--profile',
9090
'${temporaryProfileDirectory.path}',

lib/web_ui/dev/firefox_installer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Future<String> _findSystemFirefoxExecutable() async {
308308
if (!found) {
309309
if (io.Platform.isMacOS &&
310310
io.File(fireFoxDefaultInstallPath).existsSync()) {
311-
return Future.value(fireFoxDefaultInstallPath);
311+
return Future<String>.value(fireFoxDefaultInstallPath);
312312
}
313313
throw BrowserInstallerException(
314314
'Failed to locate system Firefox installation.');

lib/web_ui/dev/licenses.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LicensesCommand extends Command<bool> {
2929
'Dart source listing of ${environment.webUiRootDir.path} must not be empty.');
3030

3131
final List<String> allDartPaths =
32-
allSourceFiles.map((f) => f.path).toList();
32+
allSourceFiles.map((io.File f) => f.path).toList();
3333

3434
for (String expectedDirectory in const <String>[
3535
'lib',
@@ -41,7 +41,7 @@ class LicensesCommand extends Command<bool> {
4141
path.join(environment.webUiRootDir.path, expectedDirectory);
4242
_expect(
4343
allDartPaths
44-
.where((p) => p.startsWith(expectedAbsoluteDirectory))
44+
.where((String p) => p.startsWith(expectedAbsoluteDirectory))
4545
.isNotEmpty,
4646
'Must include the $expectedDirectory/ directory',
4747
);
@@ -51,7 +51,7 @@ class LicensesCommand extends Command<bool> {
5151
print('License headers OK!');
5252
}
5353

54-
final _copyRegex =
54+
final RegExp _copyRegex =
5555
RegExp(r'// Copyright 2013 The Flutter Authors\. All rights reserved\.');
5656

5757
void _expectLicenseHeader(io.File file) {
@@ -80,7 +80,7 @@ class LicensesCommand extends Command<bool> {
8080
}
8181

8282
List<io.File> _flatListSourceFiles(io.Directory directory) {
83-
return directory.listSync(recursive: true).whereType<io.File>().where((f) {
83+
return directory.listSync(recursive: true).whereType<io.File>().where((io.File f) {
8484
if (!f.path.endsWith('.dart') && !f.path.endsWith('.js')) {
8585
// Not a source file we're checking.
8686
return false;

lib/web_ui/dev/macos_info.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MacOSInfo {
2121
Future<void> _printSafariApplications() async {
2222
final ProcessManager systemProfiler = await startProcess(
2323
'system_profiler',
24-
['SPApplicationsDataType', '-json'],
24+
<String>['SPApplicationsDataType', '-json'],
2525
evalOutput: true,
2626
);
2727
final String systemProfileJson = await systemProfiler.evalStdout();
@@ -44,19 +44,19 @@ class MacOSInfo {
4444
Future<void> _printSafariDefaults() async {
4545
final ProcessManager defaults = await startProcess(
4646
'/usr/bin/defaults',
47-
['find', 'Safari'],
47+
<String>['find', 'Safari'],
4848
evalOutput: true,
4949
);
5050
print('Safari related defaults:\n ${await defaults.evalStdout()}');
5151
}
5252

5353
/// Print user limits (file and process).
5454
Future<void> _printUserLimits() async {
55-
ProcessManager ulimit = await startProcess('ulimit', ['-n'], evalOutput: true);
55+
ProcessManager ulimit = await startProcess('ulimit', <String>['-n'], evalOutput: true);
5656
final String fileLimit = await ulimit.evalStdout();
5757
print('MacOS file limit: $fileLimit');
5858

59-
ulimit = await startProcess('ulimit', ['-u'], evalOutput: true);
59+
ulimit = await startProcess('ulimit', <String>['-u'], evalOutput: true);
6060
final String processLimit = await ulimit.evalStdout();
6161
print('MacOS process limit: $processLimit');
6262
}

lib/web_ui/dev/safari_installation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class IosSafariArgParser extends BrowserArgParser {
138138

139139
@override
140140
void populateOptions(ArgParser argParser) {
141-
final pinnedIosVersion =
141+
final String pinnedIosVersion =
142142
'${_pinnedIosMajorVersion}.${_pinnedIosMinorVersion}';
143143
argParser
144144
..addOption('version',

0 commit comments

Comments
 (0)