Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 63b0637

Browse files
committed
[web] enable prefer_final_locals lint
1 parent 6e62915 commit 63b0637

File tree

123 files changed

+997
-984
lines changed

Some content is hidden

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

123 files changed

+997
-984
lines changed

lib/web_ui/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ linter:
5454
prefer_const_literals_to_create_immutables: false
5555
prefer_contains: false
5656
prefer_equal_for_default_values: false
57-
prefer_final_locals: false
5857
prefer_foreach: false
5958
prefer_generic_function_type_aliases: false
6059
prefer_initializing_formals: false

lib/web_ui/dev/browser.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
Process process = await startBrowser();
105+
final Process process = await startBrowser();
106106
_processCompleter.complete(process);
107107

108-
Uint8Buffer output = Uint8Buffer();
108+
final 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-
int exitCode = await process.exitCode;
120+
final 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,7 +134,7 @@ abstract class Browser {
134134
}
135135

136136
if (!_closed && exitCode != 0) {
137-
String outputString = utf8.decode(output);
137+
final String outputString = utf8.decode(output);
138138
String message = '$name failed with exit code $exitCode.';
139139
if (outputString.isNotEmpty) {
140140
message += '\nStandard output:\n$outputString';

lib/web_ui/dev/chrome.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Chrome extends Browser {
5959
/// Starts a new instance of Chrome open to the given [url], which may be a
6060
/// [Uri] or a [String].
6161
factory Chrome(Uri url, {bool debug = false}) {
62-
String version = ChromeArgParser.instance.version;
63-
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
62+
final String version = ChromeArgParser.instance.version;
63+
final 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-
List<String> args = <String>[
83+
final List<String> args = <String>[
8484
'--user-data-dir=$dir',
8585
url.toString(),
8686
if (!debug)

lib/web_ui/dev/edge.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class Edge extends Browser {
5959
// Debug is not a valid option for Edge. Remove it.
6060
String pathToOpen = url.toString();
6161
if(pathToOpen.contains('debug')) {
62-
int index = pathToOpen.indexOf('debug');
62+
final int index = pathToOpen.indexOf('debug');
6363
pathToOpen = pathToOpen.substring(0, index-1);
6464
}
6565

66-
Process process = await Process.start(
66+
final Process process = await Process.start(
6767
installation.executable,
6868
<String>['$pathToOpen','-k'],
6969
);

lib/web_ui/dev/firefox.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ 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-
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
59+
final Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
6060
return Firefox._(() async {
6161
final BrowserInstallation installation = await getOrInstallFirefox(
6262
version,
@@ -83,8 +83,8 @@ user_pref("dom.max_script_run_time", 0);
8383

8484
File(path.join(temporaryProfileDirectory.path, 'prefs.js'))
8585
.writeAsStringSync(_profile);
86-
bool isMac = Platform.isMacOS;
87-
List<String> args = <String>[
86+
final bool isMac = Platform.isMacOS;
87+
final List<String> args = <String>[
8888
url.toString(),
8989
'--profile',
9090
'${temporaryProfileDirectory.path}',

lib/web_ui/dev/firefox_installer.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FirefoxArgParser extends BrowserArgParser {
2626
@override
2727
void populateOptions(ArgParser argParser) {
2828
final YamlMap browserLock = BrowserLock.instance.configuration;
29-
String firefoxVersion = browserLock['firefox']['version'] as String;
29+
final String firefoxVersion = browserLock['firefox']['version'] as String;
3030

3131
argParser
3232
..addOption(
@@ -196,7 +196,7 @@ class FirefoxInstaller {
196196

197197
final io.File downloadedFile =
198198
io.File(path.join(versionDir.path, PlatformBinding.instance.getFirefoxDownloadFilename(version)));
199-
io.IOSink sink = downloadedFile.openWrite();
199+
final io.IOSink sink = downloadedFile.openWrite();
200200
await download.stream.pipe(sink);
201201
await sink.flush();
202202
await sink.close();
@@ -226,12 +226,12 @@ class FirefoxInstaller {
226226
/// Mounts the dmg file using hdiutil, copies content of the volume to
227227
/// target path and then unmounts dmg ready for deletion.
228228
Future<void> _mountDmgAndCopy(io.File dmgFile) async {
229-
String volumeName = await _hdiUtilMount(dmgFile);
229+
final String volumeName = await _hdiUtilMount(dmgFile);
230230

231231
final String sourcePath = '$volumeName/Firefox.app';
232232
final String targetPath = path.dirname(dmgFile.path);
233233
try {
234-
io.ProcessResult installResult = await io.Process.run('cp', <String>[
234+
final io.ProcessResult installResult = await io.Process.run('cp', <String>[
235235
'-r',
236236
sourcePath,
237237
targetPath,
@@ -249,7 +249,7 @@ class FirefoxInstaller {
249249
}
250250

251251
Future<String> _hdiUtilMount(io.File dmgFile) async {
252-
io.ProcessResult mountResult = await io.Process.run('hdiutil', <String>[
252+
final io.ProcessResult mountResult = await io.Process.run('hdiutil', <String>[
253253
'attach',
254254
'-readonly',
255255
'${dmgFile.path}',
@@ -260,7 +260,7 @@ class FirefoxInstaller {
260260
'Exit code ${mountResult.exitCode}.\n${mountResult.stderr}');
261261
}
262262

263-
List<String> processOutput = (mountResult.stdout as String).split('\n');
263+
final List<String> processOutput = (mountResult.stdout as String).split('\n');
264264
final String? volumePath = _volumeFromMountResult(processOutput);
265265
if (volumePath == null) {
266266
throw BrowserInstallerException(
@@ -274,7 +274,7 @@ class FirefoxInstaller {
274274
// Output is of form: {devicename} /Volumes/{name}.
275275
String? _volumeFromMountResult(List<String> lines) {
276276
for (String line in lines) {
277-
int pos = line.indexOf('/Volumes');
277+
final int pos = line.indexOf('/Volumes');
278278
if (pos != -1) {
279279
return line.substring(pos);
280280
}
@@ -283,7 +283,7 @@ class FirefoxInstaller {
283283
}
284284

285285
Future<void> _hdiUtilUnmount(String volumeName) async {
286-
io.ProcessResult unmountResult = await io.Process.run('hdiutil', <String>[
286+
final io.ProcessResult unmountResult = await io.Process.run('hdiutil', <String>[
287287
'unmount',
288288
'$volumeName',
289289
]);
@@ -302,7 +302,7 @@ class FirefoxInstaller {
302302
Future<String> _findSystemFirefoxExecutable() async {
303303
final io.ProcessResult which =
304304
await io.Process.run('which', <String>['firefox']);
305-
bool found = which.exitCode != 0;
305+
final bool found = which.exitCode != 0;
306306
const String fireFoxDefaultInstallPath =
307307
'/Applications/Firefox.app/Contents/MacOS/firefox';
308308
if (!found) {

lib/web_ui/dev/licenses.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class LicensesCommand extends Command<bool> {
5555
RegExp(r'// Copyright 2013 The Flutter Authors\. All rights reserved\.');
5656

5757
void _expectLicenseHeader(io.File file) {
58-
List<String> head = file.readAsStringSync().split('\n').take(3).toList();
58+
final List<String> head = file.readAsStringSync().split('\n').take(3).toList();
5959

6060
_expect(head.length >= 3, 'File too short: ${file.path}');
6161
_expect(

lib/web_ui/dev/safari_ios.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SafariIos extends Browser {
6161
// Uses `xcrun simctl`. It is a command line utility to control the
6262
// Simulator. For more details on interacting with the simulator:
6363
// https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/iOS_Simulator_Guide/InteractingwiththeiOSSimulator/InteractingwiththeiOSSimulator.html
64-
io.Process process = await io.Process.start('xcrun', <String>[
64+
final io.Process process = await io.Process.start('xcrun', <String>[
6565
'simctl',
6666
'openurl', // Opens the url on Safari installed on the simulator.
6767
'booted', // The simulator is already booted.

lib/web_ui/dev/safari_macos.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SafariMacOs extends Browser {
6464
// persistent state and wait until it opens.
6565
// The details copied from `man open` on macOS.
6666
// TODO(nurhan): https://github.com/flutter/flutter/issues/50809
67-
Process process = await Process.start(installation.executable, <String>[
67+
final Process process = await Process.start(installation.executable, <String>[
6868
// These are flags for `open` command line tool.
6969
'-F', // Open a fresh Safari with no persistent state.
7070
'-W', // Wait until the Safari opens.

lib/web_ui/dev/test_platform.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,21 @@ class OneOffHandler {
463463
///
464464
/// [handler] will be unmounted as soon as it receives a request.
465465
String create(shelf.Handler handler) {
466-
String path = _counter.toString();
466+
final String path = _counter.toString();
467467
_handlers[path] = handler;
468468
_counter++;
469469
return path;
470470
}
471471

472472
/// Dispatches [request] to the appropriate handler.
473473
FutureOr<shelf.Response> _onRequest(shelf.Request request) {
474-
List<String> components = p.url.split(request.url.path);
474+
final List<String> components = p.url.split(request.url.path);
475475
if (components.isEmpty) {
476476
return shelf.Response.notFound(null);
477477
}
478478

479-
String path = components.removeAt(0);
480-
shelf.Handler? handler = _handlers.remove(path);
479+
final String path = components.removeAt(0);
480+
final shelf.Handler? handler = _handlers.remove(path);
481481
if (handler == null) {
482482
return shelf.Response.notFound(null);
483483
}
@@ -563,9 +563,9 @@ class BrowserManager {
563563
required PackageConfig packageConfig,
564564
bool debug = false,
565565
}) {
566-
Browser browser = _newBrowser(url, browserEnvironment, debug: debug);
566+
final Browser browser = _newBrowser(url, browserEnvironment, debug: debug);
567567

568-
Completer<BrowserManager> completer = Completer<BrowserManager>();
568+
final Completer<BrowserManager> completer = Completer<BrowserManager>();
569569

570570
// For the cases where we use a delegator such as `adb` (for Android) or
571571
// `xcrun` (for IOS), these delegator processes can shut down before the
@@ -658,7 +658,7 @@ class BrowserManager {
658658
'browser': _browserEnvironment.packageTestRuntime.identifier
659659
})));
660660

661-
int suiteID = _suiteID++;
661+
final int suiteID = _suiteID++;
662662
RunnerSuiteController? controller;
663663
void closeIframe() {
664664
if (_closed) {
@@ -670,9 +670,9 @@ class BrowserManager {
670670

671671
// The virtual channel will be closed when the suite is closed, in which
672672
// case we should unload the iframe.
673-
VirtualChannel<dynamic> virtualChannel = _channel.virtualChannel();
674-
int suiteChannelID = virtualChannel.id;
675-
StreamChannel<dynamic> suiteChannel = virtualChannel.transformStream(
673+
final VirtualChannel<dynamic> virtualChannel = _channel.virtualChannel();
674+
final int suiteChannelID = virtualChannel.id;
675+
final StreamChannel<dynamic> suiteChannel = virtualChannel.transformStream(
676676
StreamTransformer<dynamic, dynamic>.fromHandlers(handleDone: (EventSink<dynamic> sink) {
677677
closeIframe();
678678
sink.close();
@@ -697,7 +697,7 @@ class BrowserManager {
697697
final String mapPath = p.join(env.environment.webUiRootDir.path,
698698
'build', pathToTest, sourceMapFileName);
699699

700-
Map<String, Uri> packageMap = <String, Uri>{
700+
final Map<String, Uri> packageMap = <String, Uri>{
701701
for (Package p in packageConfig.packages) p.name: p.packageUriRoot
702702
};
703703
final JSStackTraceMapper mapper = JSStackTraceMapper(

lib/web_ui/dev/test_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
590590
///
591591
/// Later the extra files will be deleted in [_cleanupExtraFilesUnderTestDir].
592592
Future<bool> _buildTest(TestBuildInput input) async {
593-
String targetFileName = path.join(
593+
final String targetFileName = path.join(
594594
environment.webUiBuildDir.path,
595595
'${input.path.relativeToWebUi}.browser_test.dart.js',
596596
);
@@ -603,7 +603,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
603603
directoryToTarget.createSync(recursive: true);
604604
}
605605

606-
List<String> arguments = <String>[
606+
final List<String> arguments = <String>[
607607
'--no-minify',
608608
'--disable-inlining',
609609
'--enable-asserts',

0 commit comments

Comments
 (0)