Unverified Commit 5bf63186 authored by Phil Quitslund's avatar Phil Quitslund Committed by GitHub

Update collection-fors to prefer final (as per updated `prefer_final_in_for_each`) (#127511)

The newly updated lint will soon flag for-each in collections.

See discussion: https://github.com/dart-lang/linter/pull/4383

/cc @goderbauer
parent 1a062a09
...@@ -21,7 +21,7 @@ class OpacityPeepholePage extends StatelessWidget { ...@@ -21,7 +21,7 @@ class OpacityPeepholePage extends StatelessWidget {
body: ListView( body: ListView(
key: const Key(kOpacityScrollableName), key: const Key(kOpacityScrollableName),
children: <Widget>[ children: <Widget>[
for (OpacityPeepholeCase variant in allOpacityPeepholeCases) for (final OpacityPeepholeCase variant in allOpacityPeepholeCases)
ElevatedButton( ElevatedButton(
key: Key(variant.route), key: Key(variant.route),
child: Text(variant.name), child: Text(variant.name),
......
...@@ -86,7 +86,7 @@ Future<void> main() async { ...@@ -86,7 +86,7 @@ Future<void> main() async {
watch.start(); watch.start();
for (int i = 0; i < 10; i += 1) { for (int i = 0; i < 10; i += 1) {
await Future.wait(<Future<ui.ImmutableBuffer>>[ await Future.wait(<Future<ui.ImmutableBuffer>>[
for (String asset in assets) for (final String asset in assets)
rootBundle.loadBuffer(asset) rootBundle.loadBuffer(asset)
]); ]);
} }
......
...@@ -1136,7 +1136,7 @@ Future<void> _runWebUnitTests(String webRenderer) async { ...@@ -1136,7 +1136,7 @@ Future<void> _runWebUnitTests(String webRenderer) async {
Future<void> _runWebLongRunningTests() async { Future<void> _runWebLongRunningTests() async {
final String engineVersion = File(engineVersionFile).readAsStringSync().trim(); final String engineVersion = File(engineVersionFile).readAsStringSync().trim();
final List<ShardRunner> tests = <ShardRunner>[ final List<ShardRunner> tests = <ShardRunner>[
for (String buildMode in _kAllBuildModes) ...<ShardRunner>[ for (final String buildMode in _kAllBuildModes) ...<ShardRunner>[
() => _runFlutterDriverWebTest( () => _runFlutterDriverWebTest(
testAppDirectory: path.join('packages', 'integration_test', 'example'), testAppDirectory: path.join('packages', 'integration_test', 'example'),
target: path.join('test_driver', 'failure.dart'), target: path.join('test_driver', 'failure.dart'),
......
...@@ -155,7 +155,7 @@ void main() { ...@@ -155,7 +155,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
...@@ -239,7 +239,7 @@ void main() { ...@@ -239,7 +239,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
...@@ -329,7 +329,7 @@ void main() { ...@@ -329,7 +329,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
...@@ -422,7 +422,7 @@ void main() { ...@@ -422,7 +422,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
...@@ -514,7 +514,7 @@ void main() { ...@@ -514,7 +514,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
...@@ -578,7 +578,7 @@ void main() { ...@@ -578,7 +578,7 @@ void main() {
], ],
stdout: allBinaries.join('\n'), stdout: allBinaries.join('\n'),
), ),
for (String bin in allBinaries) for (final String bin in allBinaries)
FakeCommand( FakeCommand(
command: <String>['file', '--mime-type', '-b', bin], command: <String>['file', '--mime-type', '-b', bin],
stdout: 'application/x-mach-binary', stdout: 'application/x-mach-binary',
......
...@@ -49,7 +49,7 @@ class ABTest { ...@@ -49,7 +49,7 @@ class ABTest {
static Map<String, List<double>> _convertFrom(dynamic results) { static Map<String, List<double>> _convertFrom(dynamic results) {
final Map<String, dynamic> resultMap = results as Map<String, dynamic>; final Map<String, dynamic> resultMap = results as Map<String, dynamic>;
return <String, List<double>> { return <String, List<double>> {
for (String key in resultMap.keys) for (final String key in resultMap.keys)
key: (resultMap[key] as List<dynamic>).cast<double>(), key: (resultMap[key] as List<dynamic>).cast<double>(),
}; };
} }
......
...@@ -102,7 +102,7 @@ class CustomMultiChildLayoutExample extends StatelessWidget { ...@@ -102,7 +102,7 @@ class CustomMultiChildLayoutExample extends StatelessWidget {
), ),
children: <Widget>[ children: <Widget>[
// Create all of the colored boxes in the colors map. // Create all of the colored boxes in the colors map.
for (MapEntry<String, Color> entry in _colors.entries) for (final MapEntry<String, Color> entry in _colors.entries)
// The "id" can be any Object, not just a String. // The "id" can be any Object, not just a String.
LayoutId( LayoutId(
id: entry.key, id: entry.key,
......
...@@ -76,7 +76,7 @@ class _IndexedStackExampleState extends State<IndexedStackExample> { ...@@ -76,7 +76,7 @@ class _IndexedStackExampleState extends State<IndexedStackExample> {
children: <Widget>[ children: <Widget>[
IndexedStack( IndexedStack(
index: index, index: index,
children: <Widget>[for (String name in names) PersonTracker(name: name)], children: <Widget>[for (final String name in names) PersonTracker(name: name)],
) )
], ],
), ),
......
...@@ -1448,7 +1448,7 @@ class _ContextMenuSheet extends StatelessWidget { ...@@ -1448,7 +1448,7 @@ class _ContextMenuSheet extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
actions.first, actions.first,
for (Widget action in actions.skip(1)) for (final Widget action in actions.skip(1))
DecoratedBox( DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
......
...@@ -1117,7 +1117,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti ...@@ -1117,7 +1117,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
// Only include packages we actually elided from. // Only include packages we actually elided from.
final List<String> where = <String>[ final List<String> where = <String>[
for (MapEntry<String, int> entry in removedPackagesAndClasses.entries) for (final MapEntry<String, int> entry in removedPackagesAndClasses.entries)
if (entry.value > 0) if (entry.value > 0)
entry.key, entry.key,
]..sort(); ]..sort();
......
...@@ -614,7 +614,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> { ...@@ -614,7 +614,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
suffixIcon: trailingButton, suffixIcon: trailingButton,
).applyDefaults(effectiveInputDecorationTheme) ).applyDefaults(effectiveInputDecorationTheme)
), ),
for (Widget c in _initialMenu!) c, for (final Widget c in _initialMenu!) c,
trailingButton, trailingButton,
leadingButton, leadingButton,
], ],
......
...@@ -613,7 +613,7 @@ void paintImage({ ...@@ -613,7 +613,7 @@ void paintImage({
developer.postEvent( developer.postEvent(
'Flutter.ImageSizesForFrame', 'Flutter.ImageSizesForFrame',
<String, Object>{ <String, Object>{
for (ImageSizeInfo imageSizeInfo in _pendingImageSizeInfo.values) for (final ImageSizeInfo imageSizeInfo in _pendingImageSizeInfo.values)
imageSizeInfo.source!: imageSizeInfo.toJson(), imageSizeInfo.source!: imageSizeInfo.toJson(),
}, },
); );
......
...@@ -144,7 +144,7 @@ class LeakCleaner { ...@@ -144,7 +144,7 @@ class LeakCleaner {
Leaks clean(Leaks leaks) { Leaks clean(Leaks leaks) {
final Leaks result = Leaks(<LeakType, List<LeakReport>>{ final Leaks result = Leaks(<LeakType, List<LeakReport>>{
for (LeakType leakType in leaks.byType.keys) for (final LeakType leakType in leaks.byType.keys)
leakType: leaks.byType[leakType]!.where((LeakReport leak) => _shouldReportLeak(leakType, leak)).toList() leakType: leaks.byType[leakType]!.where((LeakReport leak) => _shouldReportLeak(leakType, leak)).toList()
}); });
return result; return result;
......
...@@ -433,7 +433,7 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -433,7 +433,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
} while (currentStart < endTime!); } while (currentStart < endTime!);
return Timeline.fromJson(<String, Object>{ return Timeline.fromJson(<String, Object>{
'traceEvents': <Object?> [ 'traceEvents': <Object?> [
for (Map<String, Object?>? chunk in chunks) for (final Map<String, Object?>? chunk in chunks)
...chunk!['traceEvents']! as List<Object?>, ...chunk!['traceEvents']! as List<Object?>,
], ],
}); });
......
...@@ -930,7 +930,7 @@ Iterable<String> listApkPaths( ...@@ -930,7 +930,7 @@ Iterable<String> listApkPaths(
]; ];
if (androidBuildInfo.splitPerAbi) { if (androidBuildInfo.splitPerAbi) {
return <String>[ return <String>[
for (AndroidArch androidArch in androidBuildInfo.targetArchs) for (final AndroidArch androidArch in androidBuildInfo.targetArchs)
<String>[ <String>[
'app', 'app',
androidArch.archName, androidArch.archName,
......
...@@ -597,7 +597,7 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -597,7 +597,7 @@ class ManifestAssetBundle implements AssetBundle {
if (packageName == null) if (packageName == null)
...manifest.fontsDescriptor ...manifest.fontsDescriptor
else else
for (Font font in _parsePackageFonts( for (final Font font in _parsePackageFonts(
manifest, manifest,
packageName, packageName,
packageConfig, packageConfig,
......
...@@ -324,7 +324,7 @@ class BuildInfo { ...@@ -324,7 +324,7 @@ class BuildInfo {
'-Pbundle-sksl-path=$bundleSkSLPath', '-Pbundle-sksl-path=$bundleSkSLPath',
if (codeSizeDirectory != null) if (codeSizeDirectory != null)
'-Pcode-size-directory=$codeSizeDirectory', '-Pcode-size-directory=$codeSizeDirectory',
for (String projectArg in androidProjectArgs) for (final String projectArg in androidProjectArgs)
'-P$projectArg', '-P$projectArg',
]; ];
if (dartDefineConfigJsonMap != null) { if (dartDefineConfigJsonMap != null) {
......
...@@ -178,7 +178,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -178,7 +178,7 @@ class SourceVisitor implements ResolvedFiles {
.getArtifactPath(artifact, platform: platform, mode: mode); .getArtifactPath(artifact, platform: platform, mode: mode);
if (environment.fileSystem.isDirectorySync(path)) { if (environment.fileSystem.isDirectorySync(path)) {
sources.addAll(<File>[ sources.addAll(<File>[
for (FileSystemEntity entity in environment.fileSystem.directory(path).listSync(recursive: true)) for (final FileSystemEntity entity in environment.fileSystem.directory(path).listSync(recursive: true))
if (entity is File) if (entity is File)
entity, entity,
]); ]);
...@@ -206,7 +206,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -206,7 +206,7 @@ class SourceVisitor implements ResolvedFiles {
final FileSystemEntity entity = environment.artifacts.getHostArtifact(artifact); final FileSystemEntity entity = environment.artifacts.getHostArtifact(artifact);
if (entity is Directory) { if (entity is Directory) {
sources.addAll(<File>[ sources.addAll(<File>[
for (FileSystemEntity entity in entity.listSync(recursive: true)) for (final FileSystemEntity entity in entity.listSync(recursive: true))
if (entity is File) if (entity is File)
entity, entity,
]); ]);
......
...@@ -665,7 +665,7 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment, ...@@ -665,7 +665,7 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment,
await globals.xcode!.clang(<String>[ await globals.xcode!.clang(<String>[
'-x', '-x',
'c', 'c',
for (String arch in iosArchNames ?? <String>{}) ...<String>['-arch', arch], for (final String arch in iosArchNames ?? <String>{}) ...<String>['-arch', arch],
stubSource.path, stubSource.path,
'-dynamiclib', '-dynamiclib',
// Keep version in sync with AOTSnapshotter flag // Keep version in sync with AOTSnapshotter flag
......
...@@ -74,12 +74,12 @@ class GenerateLocalizationsTarget extends Target { ...@@ -74,12 +74,12 @@ class GenerateLocalizationsTarget extends Target {
<File>[ <File>[
configFile, configFile,
if (inputs != null) if (inputs != null)
for (Object inputFile in inputs.whereType<Object>()) for (final Object inputFile in inputs.whereType<Object>())
environment.fileSystem.file(inputFile), environment.fileSystem.file(inputFile),
], ],
<File>[ <File>[
if (outputs != null) if (outputs != null)
for (Object outputFile in outputs.whereType<Object>()) for (final Object outputFile in outputs.whereType<Object>())
environment.fileSystem.file(outputFile), environment.fileSystem.file(outputFile),
], ],
); );
......
...@@ -1290,7 +1290,7 @@ String flattenNameSubdirs(Uri url, FileSystem fileSystem) { ...@@ -1290,7 +1290,7 @@ String flattenNameSubdirs(Uri url, FileSystem fileSystem) {
/// something that doesn't. /// something that doesn't.
String _flattenNameNoSubdirs(String fileName) { String _flattenNameNoSubdirs(String fileName) {
final List<int> replacedCodeUnits = <int>[ final List<int> replacedCodeUnits = <int>[
for (int codeUnit in fileName.codeUnits) for (final int codeUnit in fileName.codeUnits)
..._flattenNameSubstitutions[codeUnit] ?? <int>[codeUnit], ..._flattenNameSubstitutions[codeUnit] ?? <int>[codeUnit],
]; ];
return String.fromCharCodes(replacedCodeUnits); return String.fromCharCodes(replacedCodeUnits);
......
...@@ -147,7 +147,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand { ...@@ -147,7 +147,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
'xcrun', 'xcrun',
'xcodebuild', 'xcodebuild',
'-create-xcframework', '-create-xcframework',
for (Directory framework in frameworks) ...<String>[ for (final Directory framework in frameworks) ...<String>[
'-framework', '-framework',
framework.path, framework.path,
...framework.parent ...framework.parent
......
...@@ -682,7 +682,7 @@ Your $application code is in $relativeAppMain. ...@@ -682,7 +682,7 @@ Your $application code is in $relativeAppMain.
List<String> _getSupportedPlatformsFromTemplateContext(Map<String, Object?> templateContext) { List<String> _getSupportedPlatformsFromTemplateContext(Map<String, Object?> templateContext) {
return <String>[ return <String>[
for (String platform in kAllCreatePlatforms) for (final String platform in kAllCreatePlatforms)
if (templateContext[platform] == true) platform, if (templateContext[platform] == true) platform,
]; ];
} }
......
...@@ -64,7 +64,7 @@ class LinuxDoctorValidator extends DoctorValidator { ...@@ -64,7 +64,7 @@ class LinuxDoctorValidator extends DoctorValidator {
final Map<String, _VersionInfo?> installedVersions = <String, _VersionInfo?>{ final Map<String, _VersionInfo?> installedVersions = <String, _VersionInfo?>{
// Sort the check to make the call order predictable for unit tests. // Sort the check to make the call order predictable for unit tests.
for (String binary in _requiredBinaryVersions.keys.toList()..sort()) for (final String binary in _requiredBinaryVersions.keys.toList()..sort())
binary: await _getBinaryVersion(binary), binary: await _getBinaryVersion(binary),
}; };
......
...@@ -211,7 +211,7 @@ void main() { ...@@ -211,7 +211,7 @@ void main() {
FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, responseError: const OSError('Connection Reset by peer')), FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, responseError: const OSError('Connection Reset by peer')),
FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, responseError: const OSError('Connection Reset by peer')), FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, responseError: const OSError('Connection Reset by peer')),
// This is the value of `<int>[1, 2, 3, 4, 5]` run through `osUtils.gzipLevel1Stream`. // This is the value of `<int>[1, 2, 3, 4, 5]` run through `osUtils.gzipLevel1Stream`.
FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, body: <int>[for (List<int> chunk in expectedEncoded) ...chunk]), FakeRequest(Uri.parse('http://localhost'), method: HttpMethod.put, body: <int>[for (final List<int> chunk in expectedEncoded) ...chunk]),
]), ]),
uploadRetryThrottle: Duration.zero, uploadRetryThrottle: Duration.zero,
); );
......
...@@ -737,7 +737,7 @@ void main() { ...@@ -737,7 +737,7 @@ void main() {
method: kListViewsMethod, method: kListViewsMethod,
jsonResponse: <String, Object>{ jsonResponse: <String, Object>{
'views': <Object>[ 'views': <Object>[
for (FlutterView view in views) view.toJson(), for (final FlutterView view in views) view.toJson(),
], ],
}, },
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment