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
This commit is contained in:
parent
1a062a0978
commit
5bf6318688
@ -21,7 +21,7 @@ class OpacityPeepholePage extends StatelessWidget {
|
||||
body: ListView(
|
||||
key: const Key(kOpacityScrollableName),
|
||||
children: <Widget>[
|
||||
for (OpacityPeepholeCase variant in allOpacityPeepholeCases)
|
||||
for (final OpacityPeepholeCase variant in allOpacityPeepholeCases)
|
||||
ElevatedButton(
|
||||
key: Key(variant.route),
|
||||
child: Text(variant.name),
|
||||
|
@ -86,7 +86,7 @@ Future<void> main() async {
|
||||
watch.start();
|
||||
for (int i = 0; i < 10; i += 1) {
|
||||
await Future.wait(<Future<ui.ImmutableBuffer>>[
|
||||
for (String asset in assets)
|
||||
for (final String asset in assets)
|
||||
rootBundle.loadBuffer(asset)
|
||||
]);
|
||||
}
|
||||
|
@ -1136,7 +1136,7 @@ Future<void> _runWebUnitTests(String webRenderer) async {
|
||||
Future<void> _runWebLongRunningTests() async {
|
||||
final String engineVersion = File(engineVersionFile).readAsStringSync().trim();
|
||||
final List<ShardRunner> tests = <ShardRunner>[
|
||||
for (String buildMode in _kAllBuildModes) ...<ShardRunner>[
|
||||
for (final String buildMode in _kAllBuildModes) ...<ShardRunner>[
|
||||
() => _runFlutterDriverWebTest(
|
||||
testAppDirectory: path.join('packages', 'integration_test', 'example'),
|
||||
target: path.join('test_driver', 'failure.dart'),
|
||||
|
@ -155,7 +155,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
@ -239,7 +239,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
@ -329,7 +329,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
@ -422,7 +422,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
@ -514,7 +514,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
@ -578,7 +578,7 @@ void main() {
|
||||
],
|
||||
stdout: allBinaries.join('\n'),
|
||||
),
|
||||
for (String bin in allBinaries)
|
||||
for (final String bin in allBinaries)
|
||||
FakeCommand(
|
||||
command: <String>['file', '--mime-type', '-b', bin],
|
||||
stdout: 'application/x-mach-binary',
|
||||
|
@ -49,7 +49,7 @@ class ABTest {
|
||||
static Map<String, List<double>> _convertFrom(dynamic results) {
|
||||
final Map<String, dynamic> resultMap = results as Map<String, dynamic>;
|
||||
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>(),
|
||||
};
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ class CustomMultiChildLayoutExample extends StatelessWidget {
|
||||
),
|
||||
children: <Widget>[
|
||||
// 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.
|
||||
LayoutId(
|
||||
id: entry.key,
|
||||
|
@ -76,7 +76,7 @@ class _IndexedStackExampleState extends State<IndexedStackExample> {
|
||||
children: <Widget>[
|
||||
IndexedStack(
|
||||
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 {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
actions.first,
|
||||
for (Widget action in actions.skip(1))
|
||||
for (final Widget action in actions.skip(1))
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
|
@ -1117,7 +1117,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
|
||||
|
||||
// Only include packages we actually elided from.
|
||||
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)
|
||||
entry.key,
|
||||
]..sort();
|
||||
|
@ -614,7 +614,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
suffixIcon: trailingButton,
|
||||
).applyDefaults(effectiveInputDecorationTheme)
|
||||
),
|
||||
for (Widget c in _initialMenu!) c,
|
||||
for (final Widget c in _initialMenu!) c,
|
||||
trailingButton,
|
||||
leadingButton,
|
||||
],
|
||||
|
@ -613,7 +613,7 @@ void paintImage({
|
||||
developer.postEvent(
|
||||
'Flutter.ImageSizesForFrame',
|
||||
<String, Object>{
|
||||
for (ImageSizeInfo imageSizeInfo in _pendingImageSizeInfo.values)
|
||||
for (final ImageSizeInfo imageSizeInfo in _pendingImageSizeInfo.values)
|
||||
imageSizeInfo.source!: imageSizeInfo.toJson(),
|
||||
},
|
||||
);
|
||||
|
@ -144,7 +144,7 @@ class LeakCleaner {
|
||||
|
||||
Leaks clean(Leaks leaks) {
|
||||
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()
|
||||
});
|
||||
return result;
|
||||
|
@ -433,7 +433,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
} while (currentStart < endTime!);
|
||||
return Timeline.fromJson(<String, Object>{
|
||||
'traceEvents': <Object?> [
|
||||
for (Map<String, Object?>? chunk in chunks)
|
||||
for (final Map<String, Object?>? chunk in chunks)
|
||||
...chunk!['traceEvents']! as List<Object?>,
|
||||
],
|
||||
});
|
||||
|
@ -930,7 +930,7 @@ Iterable<String> listApkPaths(
|
||||
];
|
||||
if (androidBuildInfo.splitPerAbi) {
|
||||
return <String>[
|
||||
for (AndroidArch androidArch in androidBuildInfo.targetArchs)
|
||||
for (final AndroidArch androidArch in androidBuildInfo.targetArchs)
|
||||
<String>[
|
||||
'app',
|
||||
androidArch.archName,
|
||||
|
@ -597,7 +597,7 @@ class ManifestAssetBundle implements AssetBundle {
|
||||
if (packageName == null)
|
||||
...manifest.fontsDescriptor
|
||||
else
|
||||
for (Font font in _parsePackageFonts(
|
||||
for (final Font font in _parsePackageFonts(
|
||||
manifest,
|
||||
packageName,
|
||||
packageConfig,
|
||||
|
@ -324,7 +324,7 @@ class BuildInfo {
|
||||
'-Pbundle-sksl-path=$bundleSkSLPath',
|
||||
if (codeSizeDirectory != null)
|
||||
'-Pcode-size-directory=$codeSizeDirectory',
|
||||
for (String projectArg in androidProjectArgs)
|
||||
for (final String projectArg in androidProjectArgs)
|
||||
'-P$projectArg',
|
||||
];
|
||||
if (dartDefineConfigJsonMap != null) {
|
||||
|
@ -178,7 +178,7 @@ class SourceVisitor implements ResolvedFiles {
|
||||
.getArtifactPath(artifact, platform: platform, mode: mode);
|
||||
if (environment.fileSystem.isDirectorySync(path)) {
|
||||
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)
|
||||
entity,
|
||||
]);
|
||||
@ -206,7 +206,7 @@ class SourceVisitor implements ResolvedFiles {
|
||||
final FileSystemEntity entity = environment.artifacts.getHostArtifact(artifact);
|
||||
if (entity is Directory) {
|
||||
sources.addAll(<File>[
|
||||
for (FileSystemEntity entity in entity.listSync(recursive: true))
|
||||
for (final FileSystemEntity entity in entity.listSync(recursive: true))
|
||||
if (entity is File)
|
||||
entity,
|
||||
]);
|
||||
|
@ -665,7 +665,7 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment,
|
||||
await globals.xcode!.clang(<String>[
|
||||
'-x',
|
||||
'c',
|
||||
for (String arch in iosArchNames ?? <String>{}) ...<String>['-arch', arch],
|
||||
for (final String arch in iosArchNames ?? <String>{}) ...<String>['-arch', arch],
|
||||
stubSource.path,
|
||||
'-dynamiclib',
|
||||
// Keep version in sync with AOTSnapshotter flag
|
||||
|
@ -74,12 +74,12 @@ class GenerateLocalizationsTarget extends Target {
|
||||
<File>[
|
||||
configFile,
|
||||
if (inputs != null)
|
||||
for (Object inputFile in inputs.whereType<Object>())
|
||||
for (final Object inputFile in inputs.whereType<Object>())
|
||||
environment.fileSystem.file(inputFile),
|
||||
],
|
||||
<File>[
|
||||
if (outputs != null)
|
||||
for (Object outputFile in outputs.whereType<Object>())
|
||||
for (final Object outputFile in outputs.whereType<Object>())
|
||||
environment.fileSystem.file(outputFile),
|
||||
],
|
||||
);
|
||||
|
@ -1290,7 +1290,7 @@ String flattenNameSubdirs(Uri url, FileSystem fileSystem) {
|
||||
/// something that doesn't.
|
||||
String _flattenNameNoSubdirs(String fileName) {
|
||||
final List<int> replacedCodeUnits = <int>[
|
||||
for (int codeUnit in fileName.codeUnits)
|
||||
for (final int codeUnit in fileName.codeUnits)
|
||||
..._flattenNameSubstitutions[codeUnit] ?? <int>[codeUnit],
|
||||
];
|
||||
return String.fromCharCodes(replacedCodeUnits);
|
||||
|
@ -147,7 +147,7 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
|
||||
'xcrun',
|
||||
'xcodebuild',
|
||||
'-create-xcframework',
|
||||
for (Directory framework in frameworks) ...<String>[
|
||||
for (final Directory framework in frameworks) ...<String>[
|
||||
'-framework',
|
||||
framework.path,
|
||||
...framework.parent
|
||||
|
@ -682,7 +682,7 @@ Your $application code is in $relativeAppMain.
|
||||
|
||||
List<String> _getSupportedPlatformsFromTemplateContext(Map<String, Object?> templateContext) {
|
||||
return <String>[
|
||||
for (String platform in kAllCreatePlatforms)
|
||||
for (final String platform in kAllCreatePlatforms)
|
||||
if (templateContext[platform] == true) platform,
|
||||
];
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class LinuxDoctorValidator extends DoctorValidator {
|
||||
|
||||
final Map<String, _VersionInfo?> installedVersions = <String, _VersionInfo?>{
|
||||
// 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),
|
||||
};
|
||||
|
||||
|
@ -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')),
|
||||
// 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,
|
||||
);
|
||||
|
@ -737,7 +737,7 @@ void main() {
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[
|
||||
for (FlutterView view in views) view.toJson(),
|
||||
for (final FlutterView view in views) view.toJson(),
|
||||
],
|
||||
},
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user