enable lint prefer_final_in_for_each (#47724)

This commit is contained in:
Alexandre Ardhuin
2020-01-07 16:32:04 +01:00
committed by GitHub
parent fa337f5922
commit 4f9b6cf017
369 changed files with 1219 additions and 1220 deletions

View File

@@ -146,7 +146,7 @@ void generate(String commit) {
initialize();
final List<SampleInfo> samples = <SampleInfo>[];
for (FileSystemEntity entity in sampleDirectory.listSync()) {
for (final FileSystemEntity entity in sampleDirectory.listSync()) {
if (entity is File && entity.path.endsWith('.dart')) {
final SampleInfo sample = SampleInfo(entity, commit);
if (sample.initialize()) // skip files that lack the Sample Catalog comment
@@ -175,7 +175,7 @@ void generate(String commit) {
);
// Write the sample app files, like animated_list.md
for (SampleInfo sample in samples) {
for (final SampleInfo sample in samples) {
writeExpandedTemplate(
outputFile(sample.sourceName + '.md'),
inputFile('bin', 'sample_page.md.template').readAsStringSync(),
@@ -188,13 +188,13 @@ void generate(String commit) {
// that feature one class. For example AnimatedList_index.md would only
// include samples that had AnimatedList in their "Classes:" list.
final Map<String, List<SampleInfo>> classToSamples = <String, List<SampleInfo>>{};
for (SampleInfo sample in samples) {
for (String className in sample.highlightedClasses) {
for (final SampleInfo sample in samples) {
for (final String className in sample.highlightedClasses) {
classToSamples[className] ??= <SampleInfo>[];
classToSamples[className].add(sample);
}
}
for (String className in classToSamples.keys) {
for (final String className in classToSamples.keys) {
final Iterable<String> entries = classToSamples[className].map<String>((SampleInfo sample) {
return expandTemplate(entryTemplate, sample.commentValues);
});
@@ -238,7 +238,7 @@ void generate(String commit) {
// For now, the website's index.json file must be updated by hand.
logMessage('The following entries must appear in _data/catalog/widgets.json');
for (String className in classToSamples.keys)
for (final String className in classToSamples.keys)
logMessage('"sample": "${className}_index"');
}

View File

@@ -13,11 +13,11 @@ void main() {
await tester.pump();
// Initially only the top level EntryItems (the "chapters") are present.
for (Entry chapter in expansion_tile_sample.data) {
for (final Entry chapter in expansion_tile_sample.data) {
expect(find.text(chapter.title), findsOneWidget);
for (Entry section in chapter.children) {
for (final Entry section in chapter.children) {
expect(find.text(section.title), findsNothing);
for (Entry item in section.children)
for (final Entry item in section.children)
expect(find.text(item.title), findsNothing);
}
}
@@ -34,15 +34,15 @@ void main() {
// Expand the chapters. Now the chapter and sections, but not the
// items, should be present.
for (Entry chapter in expansion_tile_sample.data.reversed)
for (final Entry chapter in expansion_tile_sample.data.reversed)
await tapEntry(chapter.title);
for (Entry chapter in expansion_tile_sample.data) {
for (final Entry chapter in expansion_tile_sample.data) {
expect(find.text(chapter.title), findsOneWidget);
for (Entry section in chapter.children) {
for (final Entry section in chapter.children) {
expect(find.text(section.title), findsOneWidget);
await scrollUpOneEntry();
for (Entry item in section.children)
for (final Entry item in section.children)
expect(find.text(item.title), findsNothing);
}
await scrollUpOneEntry();
@@ -53,8 +53,8 @@ void main() {
await tester.pumpAndSettle();
// Expand the sections. Now Widgets for all three levels should be present.
for (Entry chapter in expansion_tile_sample.data) {
for (Entry section in chapter.children) {
for (final Entry chapter in expansion_tile_sample.data) {
for (final Entry section in chapter.children) {
await tapEntry(section.title);
await scrollUpOneEntry();
}
@@ -65,11 +65,11 @@ void main() {
// Working in reverse order, so we don't need to do anymore scrolling,
// check that everything is visible and close the sections and
// chapters as we go up.
for (Entry chapter in expansion_tile_sample.data.reversed) {
for (final Entry chapter in expansion_tile_sample.data.reversed) {
expect(find.text(chapter.title), findsOneWidget);
for (Entry section in chapter.children.reversed) {
for (final Entry section in chapter.children.reversed) {
expect(find.text(section.title), findsOneWidget);
for (Entry item in section.children.reversed)
for (final Entry item in section.children.reversed)
expect(find.text(item.title), findsOneWidget);
await tapEntry(section.title); // close the section
}
@@ -77,11 +77,11 @@ void main() {
}
// Finally only the top level EntryItems (the "chapters") are present.
for (Entry chapter in expansion_tile_sample.data) {
for (final Entry chapter in expansion_tile_sample.data) {
expect(find.text(chapter.title), findsOneWidget);
for (Entry section in chapter.children) {
for (final Entry section in chapter.children) {
expect(find.text(section.title), findsNothing);
for (Entry item in section.children)
for (final Entry item in section.children)
expect(find.text(item.title), findsNothing);
}
}

View File

@@ -158,14 +158,14 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
@override
void dispose() {
for (NavigationIconView view in _navigationViews)
for (final NavigationIconView view in _navigationViews)
view.controller.dispose();
super.dispose();
}
Widget _buildTransitionsStack() {
final List<FadeTransition> transitions = <FadeTransition>[
for (NavigationIconView view in _navigationViews) view.transition(_type, context),
for (final NavigationIconView view in _navigationViews) view.transition(_type, context),
];
// We want to have the newly animating (fading in) views on top.

View File

@@ -260,7 +260,7 @@ class _ChipDemoState extends State<ChipDemo> {
Set<String> allowedActions = <String>{};
if (_selectedMaterial != null && _selectedMaterial.isNotEmpty) {
for (String tool in _selectedTools) {
for (final String tool in _selectedTools) {
allowedActions.addAll(_toolActions[tool]);
}
allowedActions = allowedActions.intersection(_materialActions[_selectedMaterial]);

View File

@@ -135,7 +135,7 @@ class DessertDataSource extends DataTableSource {
int get selectedRowCount => _selectedCount;
void _selectAll(bool checked) {
for (Dessert dessert in _desserts)
for (final Dessert dessert in _desserts)
dessert.selected = checked;
_selectedCount = checked ? _desserts.length : 0;
notifyListeners();

View File

@@ -476,7 +476,7 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
return;
}
for (int product in difference) {
for (final int product in difference) {
if (_internalList.length < _list.length) {
_list.remove(product);
} else if (_internalList.length > _list.length) {

View File

@@ -294,8 +294,7 @@ class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
final Connectivity connectivity = Connectivity();
ConnectivityResult previousResult = await connectivity.checkConnectivity();
yield previousResult;
await for (ConnectivityResult result
in connectivity.onConnectivityChanged) {
await for (final ConnectivityResult result in connectivity.onConnectivityChanged) {
if (result != previousResult) {
yield result;
previousResult = result;

View File

@@ -27,7 +27,7 @@ Future<void> _parseExampleCode(AssetBundle bundle) async {
List<String> codeBlock;
String codeTag;
for (String line in lines) {
for (final String line in lines) {
if (codeBlock == null) {
// Outside a block.
if (line.startsWith(_kStartTag)) {

View File

@@ -94,7 +94,7 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
final List<TextSpan> formattedText = <TextSpan>[];
int currentPosition = 0;
for (_HighlightSpan span in _spans) {
for (final _HighlightSpan span in _spans) {
if (currentPosition != span.start)
formattedText.add(TextSpan(text: _src.substring(currentPosition, span.start)));

View File

@@ -61,10 +61,10 @@ Future<void> main() async {
print('Starting app...');
runApp(const GalleryApp(testMode: true));
final _LiveWidgetController controller = _LiveWidgetController(WidgetsBinding.instance);
for (GalleryDemoCategory category in kAllGalleryDemoCategories) {
for (final GalleryDemoCategory category in kAllGalleryDemoCategories) {
print('Tapping "${category.name}" section...');
await controller.tap(find.text(category.name));
for (GalleryDemo demo in kGalleryCategoryToDemos[category]) {
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]) {
final Finder demoItem = find.text(demo.title);
print('Scrolling to "${demo.title}"...');
await controller.scrollIntoView(demoItem, alignment: 0.5);

View File

@@ -42,7 +42,7 @@ void verifyToStringOutput(String name, String route, String testString) {
final List<String> lines = testString.split('\n');
if (!testString.endsWith('\n'))
reportToStringError(name, route, lines.length, lines, 'does not end with a line feed');
for (String line in lines) {
for (final String line in lines) {
lineNumber += 1;
if (line == '' && lineNumber != lines.length) {
reportToStringError(name, route, lineNumber, lines, 'found empty line');
@@ -157,11 +157,11 @@ Future<void> smokeGallery(WidgetTester tester) async {
expect(find.text(kGalleryTitle), findsOneWidget);
for (GalleryDemoCategory category in kAllGalleryDemoCategories) {
for (final GalleryDemoCategory category in kAllGalleryDemoCategories) {
await Scrollable.ensureVisible(tester.element(find.text(category.name)), alignment: 0.5);
await tester.tap(find.text(category.name));
await tester.pumpAndSettle();
for (GalleryDemo demo in kGalleryCategoryToDemos[category]) {
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]) {
await Scrollable.ensureVisible(tester.element(find.text(demo.title)), alignment: 0.0);
await smokeDemo(tester, demo);
tester.binding.debugAssertNoTransientCallbacks('A transient callback was still active after running $demo');

View File

@@ -69,7 +69,7 @@ Future<void> saveDurationsHistogram(List<Map<String, dynamic>> events, String ou
int frameStart;
// Save the duration of the first frame after each 'Start Transition' event.
for (Map<String, dynamic> event in events) {
for (final Map<String, dynamic> event in events) {
final String eventName = event['name'] as String;
if (eventName == 'Start Transition') {
assert(startEvent == null);
@@ -143,7 +143,7 @@ Future<void> runDemos(List<String> demos, FlutterDriver driver) async {
final SerializableFinder demoList = find.byValueKey('GalleryDemoList');
String currentDemoCategory;
for (String demo in demos) {
for (final String demo in demos) {
if (kSkippedDemos.contains(demo))
continue;

View File

@@ -79,7 +79,7 @@ void beginFrame(Duration timeStamp) {
void handlePointerDataPacket(ui.PointerDataPacket packet) {
// The pointer packet contains a number of pointer movements, which we iterate
// through and process.
for (ui.PointerData datum in packet.data) {
for (final ui.PointerData datum in packet.data) {
if (datum.change == ui.PointerChange.down) {
// If the pointer went down, we change the color of the circle to blue.
color = const ui.Color(0xFF0000FF);

View File

@@ -94,7 +94,7 @@ class RenderDots extends RenderBox {
canvas.drawRect(offset & size, Paint()..color = const Color(0xFFFFFFFF));
// We iterate through our model and paint each dot.
for (Dot dot in _dots.values)
for (final Dot dot in _dots.values)
dot.paint(canvas, offset);
}
}

View File

@@ -31,7 +31,7 @@ class RenderDots extends RenderConstrainedBox {
canvas.drawRect(offset & size, Paint()..color = const Color(0xFF0000FF));
final Paint paint = Paint()..color = const Color(0xFF00FF00);
for (Offset point in _dots.values)
for (final Offset point in _dots.values)
canvas.drawCircle(point, 50.0, paint);
super.paint(context, offset);

View File

@@ -56,7 +56,7 @@ class StockData extends ChangeNotifier {
bool get loading => _httpClient != null;
void add(List<dynamic> data) {
for (List<dynamic> fields in data.cast<List<dynamic>>()) {
for (final List<dynamic> fields in data.cast<List<dynamic>>()) {
final Stock stock = Stock.fromFields(fields.cast<String>());
_symbols.add(stock.symbol);
_stocks[stock.symbol] = stock;