enable lint prefer_final_in_for_each (#47724)
diff --git a/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart b/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
index 736531b..b1cfd66 100644
--- a/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_sdk_test.dart
@@ -201,7 +201,7 @@
});
});
- for (String os in <String>['linux', 'macos']) {
+ for (final String os in <String>['linux', 'macos']) {
testUsingContext('detection on $os (no ndk available)', () {
sdkDir = MockAndroidSdk.createSdkDirectory(withAndroidN: true);
globals.config.setValue('android-sdk', sdkDir.path);
diff --git a/packages/flutter_tools/test/general.shard/android/gradle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
index 17cb651..83f69c7 100644
--- a/packages/flutter_tools/test/general.shard/android/gradle_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
@@ -441,10 +441,10 @@
'See https://goo.gl/CP92wY for more information on the problem and how to fix it.',
'This warning prints for all Android build failures. The real root cause of the error may be unrelated.',
];
- for (String m in nonMatchingLines) {
+ for (final String m in nonMatchingLines) {
expect(androidXPluginWarningRegex.hasMatch(m), isFalse);
}
- for (String m in matchingLines) {
+ for (final String m in matchingLines) {
expect(androidXPluginWarningRegex.hasMatch(m), isTrue);
}
});
diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart
index 222c96f..6ce0823 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart
@@ -70,8 +70,8 @@
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
- for (String packageName in packages) {
- for (String packageFont in packageFonts) {
+ for (final String packageName in packages) {
+ for (final String packageFont in packageFonts) {
final String entryKey = 'packages/$packageName/$packageFont';
expect(bundle.entries.containsKey(entryKey), true);
expect(
@@ -80,7 +80,7 @@
);
}
- for (String localFont in localFonts) {
+ for (final String localFont in localFonts) {
expect(bundle.entries.containsKey(localFont), true);
expect(
utf8.decode(await bundle.entries[localFont].contentsAsBytes()),
diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
index 25e2089..e75dde6 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart
@@ -38,7 +38,7 @@
assets:
''');
- for (String asset in assets) {
+ for (final String asset in assets) {
buffer.write('''
- $asset
''');
@@ -75,8 +75,8 @@
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
- for (String packageName in packages) {
- for (String asset in assets) {
+ for (final String packageName in packages) {
+ for (final String asset in assets) {
final String entryKey = Uri.encodeFull('packages/$packageName/$asset');
expect(bundle.entries.containsKey(entryKey), true, reason: 'Cannot find key on bundle: $entryKey');
expect(
@@ -93,7 +93,7 @@
}
void writeAssets(String path, List<String> assets) {
- for (String asset in assets) {
+ for (final String asset in assets) {
final String fullPath = fixPath(globals.fs.path.join(path, asset));
globals.fs.file(fullPath)
diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
index dcd7627..5fa9fda 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
@@ -65,7 +65,7 @@
'a/b/c/var2/foo',
'a/b/c/var3/foo',
];
- for (String asset in assets) {
+ for (final String asset in assets) {
globals.fs.file(fixPath(asset))
..createSync(recursive: true)
..writeAsStringSync(asset);
@@ -75,7 +75,7 @@
await bundle.build(manifestPath: 'pubspec.yaml');
// The main asset file, /a/b/c/foo, and its variants exist.
- for (String asset in assets) {
+ for (final String asset in assets) {
expect(bundle.entries.containsKey(asset), true);
expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset);
}
@@ -87,7 +87,7 @@
// Now the main asset file, /a/b/c/foo, does not exist. This is OK because
// the /a/b/c/*/foo variants do exist.
expect(bundle.entries.containsKey('a/b/c/foo'), false);
- for (String asset in assets.skip(1)) {
+ for (final String asset in assets.skip(1)) {
expect(bundle.entries.containsKey(asset), true);
expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset);
}
diff --git a/packages/flutter_tools/test/general.shard/base/build_test.dart b/packages/flutter_tools/test/general.shard/base/build_test.dart
index 62c4c18..450e818 100644
--- a/packages/flutter_tools/test/general.shard/base/build_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/build_test.dart
@@ -248,7 +248,7 @@
when(mockXcode.sdkLocation(any)).thenAnswer((_) => Future<String>.value(kSDKPath));
bufferLogger = BufferLogger();
- for (BuildMode mode in BuildMode.values) {
+ for (final BuildMode mode in BuildMode.values) {
when(mockArtifacts.getArtifactPath(Artifact.snapshotDart,
platform: anyNamed('platform'), mode: mode)).thenReturn(kSnapshotDart);
}
diff --git a/packages/flutter_tools/test/general.shard/base/logger_test.dart b/packages/flutter_tools/test/general.shard/base/logger_test.dart
index b30772b..189464c 100644
--- a/packages/flutter_tools/test/general.shard/base/logger_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/logger_test.dart
@@ -103,7 +103,7 @@
} while (doThis());
}
- for (String testOs in testPlatforms) {
+ for (final String testOs in testPlatforms) {
testUsingContext('AnsiSpinner works for $testOs (1)', () async {
bool done = false;
mockStopwatch = FakeStopwatch();
@@ -255,7 +255,7 @@
expect(outputStdout().join('\n'), contains('This is taking an unexpectedly long time.'));
// Test that the number of '\b' is correct.
- for (String line in outputStdout()) {
+ for (final String line in outputStdout()) {
int currLength = 0;
for (int i = 0; i < line.length; i += 1) {
currLength += line[i] == '\b' ? -1 : 1;
diff --git a/packages/flutter_tools/test/general.shard/base/terminal_test.dart b/packages/flutter_tools/test/general.shard/base/terminal_test.dart
index f6bc675..ff62a6f 100644
--- a/packages/flutter_tools/test/general.shard/base/terminal_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/terminal_test.dart
@@ -40,7 +40,7 @@
});
testUsingContext('adding colors works', () {
- for (TerminalColor color in TerminalColor.values) {
+ for (final TerminalColor color in TerminalColor.values) {
expect(
terminal.color('output', color),
equals('${AnsiTerminal.colorCode(color)}output${AnsiTerminal.resetColor}'),
diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
index b83b51b..9d83b2e 100644
--- a/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
@@ -96,7 +96,7 @@
globals.fs.path.join('packages', 'flutter_tools', 'lib', 'src', 'build_system', 'targets', 'dart.dart'),
globals.fs.path.join('packages', 'flutter_tools', 'lib', 'src', 'build_system', 'targets', 'ios.dart'),
];
- for (String path in paths) {
+ for (final String path in paths) {
globals.fs.file(path).createSync(recursive: true);
}
}, overrides: <Type, Generator>{
diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart
index cd09381..56f7b3d 100644
--- a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart
@@ -82,7 +82,7 @@
});
test('Copies files to correct cache directory', () => testbed.run(() async {
- for (File input in inputs) {
+ for (final File input in inputs) {
input.createSync(recursive: true);
}
// Create output directory so we can test that it is deleted.
@@ -100,7 +100,7 @@
expect(target.existsSync(), false);
target.createSync(recursive: true);
- for (FileSystemEntity entity in source.listSync(recursive: true)) {
+ for (final FileSystemEntity entity in source.listSync(recursive: true)) {
if (entity is File) {
final String relative = globals.fs.path.relative(entity.path, from: source.path);
final String destination = globals.fs.path.join(target.path, relative);
@@ -115,7 +115,7 @@
await const DebugUnpackMacOS().build(environment);
expect(globals.fs.directory('$_kOutputPrefix').existsSync(), true);
- for (File file in inputs) {
+ for (final File file in inputs) {
expect(globals.fs.file(file.path.replaceFirst(_kInputPrefix, _kOutputPrefix)).existsSync(), true);
}
}));
diff --git a/packages/flutter_tools/test/general.shard/dart/sdk_validation_test.dart b/packages/flutter_tools/test/general.shard/dart/sdk_validation_test.dart
index 9d864c1..e91b4cc 100644
--- a/packages/flutter_tools/test/general.shard/dart/sdk_validation_test.dart
+++ b/packages/flutter_tools/test/general.shard/dart/sdk_validation_test.dart
@@ -64,7 +64,7 @@
int errorCount = 0;
final Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
server.onErrors.listen((FileAnalysisErrors result) {
- for (AnalysisError error in result.errors) {
+ for (final AnalysisError error in result.errors) {
print(error.toString().trim());
}
errorCount += result.errors.length;
diff --git a/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart b/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart
index dce6b55..eb771ab 100644
--- a/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart
+++ b/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart
@@ -22,8 +22,8 @@
.where(_isDartFile)
.where(_isNotSkipped)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*package:'))) {
continue;
}
@@ -47,8 +47,8 @@
.where(_isDartFile)
.where(_isNotSkipped)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*globals.dart'))
&& !line.contains(r'as globals')) {
final String relativePath = globals.fs.path.relative(file.path, from:flutterTools);
@@ -65,14 +65,14 @@
];
bool _isNotWhitelisted(FileSystemEntity entity) => whitelistedPaths.every((String path) => path != entity.path);
- for (String dirName in <String>['lib', 'bin']) {
+ for (final String dirName in <String>['lib', 'bin']) {
final Iterable<File> files = globals.fs.directory(globals.fs.path.join(flutterTools, dirName))
.listSync(recursive: true)
.where(_isDartFile)
.where(_isNotWhitelisted)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*dart:io')) &&
!line.contains('ignore: dart_io_import')) {
final String relativePath = globals.fs.path.relative(file.path, from:flutterTools);
@@ -92,14 +92,14 @@
];
bool _isNotWhitelisted(FileSystemEntity entity) => whitelistedPaths.every((String path) => path != entity.path);
- for (String dirName in <String>['lib']) {
+ for (final String dirName in <String>['lib']) {
final Iterable<File> files = globals.fs.directory(globals.fs.path.join(flutterTools, dirName))
.listSync(recursive: true)
.where(_isDartFile)
.where(_isNotWhitelisted)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*package:test_api')) &&
!line.contains('ignore: test_api_import')) {
final String relativePath = globals.fs.path.relative(file.path, from:flutterTools);
@@ -112,14 +112,14 @@
test('no unauthorized imports of package:path', () {
final String whitelistedPath = globals.fs.path.join(flutterTools, 'lib', 'src', 'build_runner', 'web_compilation_delegate.dart');
- for (String dirName in <String>['lib', 'bin', 'test']) {
+ for (final String dirName in <String>['lib', 'bin', 'test']) {
final Iterable<File> files = globals.fs.directory(globals.fs.path.join(flutterTools, dirName))
.listSync(recursive: true)
.where(_isDartFile)
.where((FileSystemEntity entity) => entity.path != whitelistedPath)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*package:path/path.dart')) &&
!line.contains('ignore: package_path_import')) {
final String relativePath = globals.fs.path.relative(file.path, from:flutterTools);
@@ -137,14 +137,14 @@
];
bool _isNotWhitelisted(FileSystemEntity entity) => whitelistedPaths.every((String path) => path != entity.path);
- for (String dirName in <String>['lib']) {
+ for (final String dirName in <String>['lib']) {
final Iterable<File> files = globals.fs.directory(globals.fs.path.join(flutterTools, dirName))
.listSync(recursive: true)
.where(_isDartFile)
.where(_isNotWhitelisted)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*dart:convert')) &&
!line.contains('ignore: dart_convert_import')) {
final String relativePath = globals.fs.path.relative(file.path, from:flutterTools);
@@ -163,14 +163,14 @@
];
bool _isNotWhitelisted(FileSystemEntity entity) => whitelistedPaths.every((String path) => !entity.path.contains(path));
- for (String dirName in <String>['lib']) {
+ for (final String dirName in <String>['lib']) {
final Iterable<File> files = globals.fs.directory(globals.fs.path.join(flutterTools, dirName))
.listSync(recursive: true)
.where(_isDartFile)
.where(_isNotWhitelisted)
.map(_asFile);
- for (File file in files) {
- for (String line in file.readAsLinesSync()) {
+ for (final File file in files) {
+ for (final String line in file.readAsLinesSync()) {
if (line.startsWith(RegExp(r'import.*package:build_runner_core/build_runner_core.dart')) ||
line.startsWith(RegExp(r'import.*package:build_runner/build_runner.dart')) ||
line.startsWith(RegExp(r'import.*package:build_config/build_config.dart')) ||
diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
index d5b4e58..3bc889f 100644
--- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
+++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
@@ -337,7 +337,7 @@
Future<Uri> findUri(List<MockFlutterView> views, String expectedIsolateName) async {
when(vm.views).thenReturn(views);
- for (MockFlutterView view in views) {
+ for (final MockFlutterView view in views) {
when(view.owner).thenReturn(vm);
}
final MockFuchsiaDevice fuchsiaDevice =
diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
index 4820ae2..fbf7ff0 100644
--- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
@@ -80,7 +80,7 @@
Platform: () => macPlatform,
});
- for (Platform platform in unsupportedPlatforms) {
+ for (final Platform platform in unsupportedPlatforms) {
testUsingContext('throws UnsupportedError exception if instantiated on ${platform.operatingSystem}', () {
expect(
() { IOSDevice('device-123'); },
@@ -781,7 +781,7 @@
});
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
- for (Platform platform in unsupportedPlatforms) {
+ for (final Platform platform in unsupportedPlatforms) {
testUsingContext('throws Unsupported Operation exception on ${platform.operatingSystem}', () async {
when(iMobileDevice.isInstalled).thenReturn(false);
when(iMobileDevice.getAvailableDeviceIDs())
diff --git a/packages/flutter_tools/test/general.shard/plugins_test.dart b/packages/flutter_tools/test/general.shard/plugins_test.dart
index 7d2d821..30b4401 100644
--- a/packages/flutter_tools/test/general.shard/plugins_test.dart
+++ b/packages/flutter_tools/test/general.shard/plugins_test.dart
@@ -208,7 +208,7 @@
pluginClass: UseNewEmbedding
dependencies:
''');
- for (String dependency in dependencies) {
+ for (final String dependency in dependencies) {
pluginDirectory
.childFile('pubspec.yaml')
.writeAsStringSync(' $dependency:\n', mode: FileMode.append);
diff --git a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart
index 3d251a5..d46e5629 100644
--- a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart
+++ b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart
@@ -14,7 +14,7 @@
final DateTime inFuture = DateTime.now().add(const Duration(days: 100));
void main() {
- for (bool asyncScanning in <bool>[true, false]) {
+ for (final bool asyncScanning in <bool>[true, false]) {
testWithoutContext('No last compile, asyncScanning: $asyncScanning', () async {
final ProjectFileInvalidator projectFileInvalidator = ProjectFileInvalidator(
fileSystem: MemoryFileSystem(),
diff --git a/packages/flutter_tools/test/general.shard/project_test.dart b/packages/flutter_tools/test/general.shard/project_test.dart
index d42a617..1fcdfe6 100644
--- a/packages/flutter_tools/test/general.shard/project_test.dart
+++ b/packages/flutter_tools/test/general.shard/project_test.dart
@@ -643,7 +643,7 @@
void transfer(FileSystemEntity entity, FileSystem target) {
if (entity is Directory) {
target.directory(entity.absolute.path).createSync(recursive: true);
- for (FileSystemEntity child in entity.listSync()) {
+ for (final FileSystemEntity child in entity.listSync()) {
transfer(child, target);
}
} else if (entity is File) {
diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart
index bf68b53..41d77c0 100644
--- a/packages/flutter_tools/test/general.shard/version_test.dart
+++ b/packages/flutter_tools/test/general.shard/version_test.dart
@@ -30,7 +30,7 @@
mockCache = MockCache();
});
- for (String channel in FlutterVersion.officialChannels) {
+ for (final String channel in FlutterVersion.officialChannels) {
DateTime getChannelUpToDateVersion() {
return _testClock.ago(FlutterVersion.versionAgeConsideredUpToDate(channel) ~/ 2);
}