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

[web] enable prefer_final_locals lint #27420

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/web_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ linter:
prefer_const_literals_to_create_immutables: false
prefer_contains: false
prefer_equal_for_default_values: false
prefer_final_locals: false
prefer_foreach: false
prefer_generic_function_type_aliases: false
prefer_initializing_formals: false
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/dev/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ abstract class Browser {
// for the process to actually start. They should just wait for the HTTP
// request instead.
runZonedGuarded(() async {
Process process = await startBrowser();
final Process process = await startBrowser();
_processCompleter.complete(process);

Uint8Buffer output = Uint8Buffer();
final Uint8Buffer output = Uint8Buffer();
void drainOutput(Stream<List<int>> stream) {
try {
_ioSubscriptions
Expand All @@ -117,7 +117,7 @@ abstract class Browser {
drainOutput(process.stdout);
drainOutput(process.stderr);

int exitCode = await process.exitCode;
final int exitCode = await process.exitCode;

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

if (!_closed && exitCode != 0) {
String outputString = utf8.decode(output);
final String outputString = utf8.decode(output);
String message = '$name failed with exit code $exitCode.';
if (outputString.isNotEmpty) {
message += '\nStandard output:\n$outputString';
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/dev/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class Chrome extends Browser {
/// Starts a new instance of Chrome open to the given [url], which may be a
/// [Uri] or a [String].
factory Chrome(Uri url, {bool debug = false}) {
String version = ChromeArgParser.instance.version;
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
final String version = ChromeArgParser.instance.version;
final Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
return Chrome._(() async {
final BrowserInstallation installation = await getOrInstallChrome(
version,
Expand All @@ -80,7 +80,7 @@ class Chrome extends Browser {
final bool isChromeNoSandbox =
Platform.environment['CHROME_NO_SANDBOX'] == 'true';
final String dir = environment.webUiDartToolDir.createTempSync('test_chrome_user_data_').resolveSymbolicLinksSync();
List<String> args = <String>[
final List<String> args = <String>[
'--user-data-dir=$dir',
url.toString(),
if (!debug)
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/dev/edge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class Edge extends Browser {
// Debug is not a valid option for Edge. Remove it.
String pathToOpen = url.toString();
if(pathToOpen.contains('debug')) {
int index = pathToOpen.indexOf('debug');
final int index = pathToOpen.indexOf('debug');
pathToOpen = pathToOpen.substring(0, index-1);
}

Process process = await Process.start(
final Process process = await Process.start(
installation.executable,
<String>['$pathToOpen','-k'],
);
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/dev/firefox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Firefox extends Browser {
/// [Uri] or a [String].
factory Firefox(Uri url, {bool debug = false}) {
final String version = FirefoxArgParser.instance.version;
Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
final Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
return Firefox._(() async {
final BrowserInstallation installation = await getOrInstallFirefox(
version,
Expand All @@ -83,8 +83,8 @@ user_pref("dom.max_script_run_time", 0);

File(path.join(temporaryProfileDirectory.path, 'prefs.js'))
.writeAsStringSync(_profile);
bool isMac = Platform.isMacOS;
List<String> args = <String>[
final bool isMac = Platform.isMacOS;
final List<String> args = <String>[
url.toString(),
'--profile',
'${temporaryProfileDirectory.path}',
Expand Down
18 changes: 9 additions & 9 deletions lib/web_ui/dev/firefox_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FirefoxArgParser extends BrowserArgParser {
@override
void populateOptions(ArgParser argParser) {
final YamlMap browserLock = BrowserLock.instance.configuration;
String firefoxVersion = browserLock['firefox']['version'] as String;
final String firefoxVersion = browserLock['firefox']['version'] as String;

argParser
..addOption(
Expand Down Expand Up @@ -196,7 +196,7 @@ class FirefoxInstaller {

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

final String sourcePath = '$volumeName/Firefox.app';
final String targetPath = path.dirname(dmgFile.path);
try {
io.ProcessResult installResult = await io.Process.run('cp', <String>[
final io.ProcessResult installResult = await io.Process.run('cp', <String>[
'-r',
sourcePath,
targetPath,
Expand All @@ -249,7 +249,7 @@ class FirefoxInstaller {
}

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

List<String> processOutput = (mountResult.stdout as String).split('\n');
final List<String> processOutput = (mountResult.stdout as String).split('\n');
final String? volumePath = _volumeFromMountResult(processOutput);
if (volumePath == null) {
throw BrowserInstallerException(
Expand All @@ -274,7 +274,7 @@ class FirefoxInstaller {
// Output is of form: {devicename} /Volumes/{name}.
String? _volumeFromMountResult(List<String> lines) {
for (String line in lines) {
int pos = line.indexOf('/Volumes');
final int pos = line.indexOf('/Volumes');
if (pos != -1) {
return line.substring(pos);
}
Expand All @@ -283,7 +283,7 @@ class FirefoxInstaller {
}

Future<void> _hdiUtilUnmount(String volumeName) async {
io.ProcessResult unmountResult = await io.Process.run('hdiutil', <String>[
final io.ProcessResult unmountResult = await io.Process.run('hdiutil', <String>[
'unmount',
'$volumeName',
]);
Expand All @@ -302,7 +302,7 @@ class FirefoxInstaller {
Future<String> _findSystemFirefoxExecutable() async {
final io.ProcessResult which =
await io.Process.run('which', <String>['firefox']);
bool found = which.exitCode != 0;
final bool found = which.exitCode != 0;
const String fireFoxDefaultInstallPath =
'/Applications/Firefox.app/Contents/MacOS/firefox';
if (!found) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/licenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LicensesCommand extends Command<bool> {
RegExp(r'// Copyright 2013 The Flutter Authors\. All rights reserved\.');

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

_expect(head.length >= 3, 'File too short: ${file.path}');
_expect(
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/safari_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SafariIos extends Browser {
// Uses `xcrun simctl`. It is a command line utility to control the
// Simulator. For more details on interacting with the simulator:
// https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/iOS_Simulator_Guide/InteractingwiththeiOSSimulator/InteractingwiththeiOSSimulator.html
io.Process process = await io.Process.start('xcrun', <String>[
final io.Process process = await io.Process.start('xcrun', <String>[
'simctl',
'openurl', // Opens the url on Safari installed on the simulator.
'booted', // The simulator is already booted.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/safari_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SafariMacOs extends Browser {
// persistent state and wait until it opens.
// The details copied from `man open` on macOS.
// TODO(nurhan): https://github.com/flutter/flutter/issues/50809
Process process = await Process.start(installation.executable, <String>[
final Process process = await Process.start(installation.executable, <String>[
// These are flags for `open` command line tool.
'-F', // Open a fresh Safari with no persistent state.
'-W', // Wait until the Safari opens.
Expand Down
22 changes: 11 additions & 11 deletions lib/web_ui/dev/test_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,21 @@ class OneOffHandler {
///
/// [handler] will be unmounted as soon as it receives a request.
String create(shelf.Handler handler) {
String path = _counter.toString();
final String path = _counter.toString();
_handlers[path] = handler;
_counter++;
return path;
}

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

String path = components.removeAt(0);
shelf.Handler? handler = _handlers.remove(path);
final String path = components.removeAt(0);
final shelf.Handler? handler = _handlers.remove(path);
if (handler == null) {
return shelf.Response.notFound(null);
}
Expand Down Expand Up @@ -563,9 +563,9 @@ class BrowserManager {
required PackageConfig packageConfig,
bool debug = false,
}) {
Browser browser = _newBrowser(url, browserEnvironment, debug: debug);
final Browser browser = _newBrowser(url, browserEnvironment, debug: debug);

Completer<BrowserManager> completer = Completer<BrowserManager>();
final Completer<BrowserManager> completer = Completer<BrowserManager>();

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

int suiteID = _suiteID++;
final int suiteID = _suiteID++;
RunnerSuiteController? controller;
void closeIframe() {
if (_closed) {
Expand All @@ -670,9 +670,9 @@ class BrowserManager {

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

Map<String, Uri> packageMap = <String, Uri>{
final Map<String, Uri> packageMap = <String, Uri>{
for (Package p in packageConfig.packages) p.name: p.packageUriRoot
};
final JSStackTraceMapper mapper = JSStackTraceMapper(
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
///
/// Later the extra files will be deleted in [_cleanupExtraFilesUnderTestDir].
Future<bool> _buildTest(TestBuildInput input) async {
String targetFileName = path.join(
final String targetFileName = path.join(
environment.webUiBuildDir.path,
'${input.path.relativeToWebUi}.browser_test.dart.js',
);
Expand All @@ -603,7 +603,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
directoryToTarget.createSync(recursive: true);
}

List<String> arguments = <String>[
final List<String> arguments = <String>[
'--no-minify',
'--disable-inlining',
'--enable-asserts',
Expand Down
Loading