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

@@ -215,7 +215,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
children.add(child);
return true;
});
for (SemanticsNode child in children) {
for (final SemanticsNode child in children) {
result += await evaluateNode(child);
}
if (_shouldSkipNode(data)) {
@@ -348,7 +348,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
class _ContrastReport {
factory _ContrastReport(List<int> colors) {
final Map<int, int> colorHistogram = <int, int>{};
for (int color in colors) {
for (final int color in colors) {
colorHistogram[color] = (colorHistogram[color] ?? 0) + 1;
}
if (colorHistogram.length == 1) {
@@ -358,7 +358,7 @@ class _ContrastReport {
// to determine the lighter and darker color, partition the colors
// by lightness and then choose the mode from each group.
double averageLightness = 0.0;
for (int color in colorHistogram.keys) {
for (final int color in colorHistogram.keys) {
final HSLColor hslColor = HSLColor.fromColor(Color(color));
averageLightness += hslColor.lightness * colorHistogram[color];
}
@@ -369,7 +369,7 @@ class _ContrastReport {
int lightCount = 0;
int darkCount = 0;
// Find the most frequently occurring light and dark color.
for (MapEntry<int, int> entry in colorHistogram.entries) {
for (final MapEntry<int, int> entry in colorHistogram.entries) {
final HSLColor color = HSLColor.fromColor(Color(entry.key));
final int count = entry.value;
if (color.lightness <= averageLightness && count > darkCount) {

View File

@@ -1119,7 +1119,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}
debugPrint('Pending timers:');
for (String timerInfo in _currentFakeAsync.pendingTimersDebugInfo) {
for (final String timerInfo in _currentFakeAsync.pendingTimersDebugInfo) {
final int firstLineEnd = timerInfo.indexOf('\n');
assert(firstLineEnd != -1);
@@ -1657,7 +1657,7 @@ class _LiveTestRenderView extends RenderView {
..strokeWidth = radius / 10.0
..style = PaintingStyle.stroke;
bool dirty = false;
for (int pointer in _pointers.keys) {
for (final int pointer in _pointers.keys) {
final _LiveTestPointerRecord record = _pointers[pointer];
paint.color = record.color.withOpacity(record.decay < 0 ? (record.decay / (_kPointerDecay - 1)) : 1.0);
canvas.drawPath(path.shift(record.position), paint);

View File

@@ -57,7 +57,7 @@ class KeyEventSimulator {
map = kLinuxToPhysicalKey;
break;
}
for (int code in map.keys) {
for (final int code in map.keys) {
if (key.debugName == map[code].debugName) {
scanCode = code;
break;
@@ -84,7 +84,7 @@ class KeyEventSimulator {
map = kGlfwToLogicalKey;
break;
}
for (int code in map.keys) {
for (final int code in map.keys) {
if (key.debugName == map[code].debugName) {
keyCode = code;
break;

View File

@@ -719,7 +719,7 @@ class _AncestorFinder extends Finder {
@override
Iterable<Element> get allCandidates {
final List<Element> candidates = <Element>[];
for (Element root in descendant.evaluate()) {
for (final Element root in descendant.evaluate()) {
final List<Element> ancestors = <Element>[];
if (matchRoot)
ancestors.add(root);

View File

@@ -1184,7 +1184,7 @@ class _IsMethodCall extends Matcher {
bool _deepEqualsMap(Map<dynamic, dynamic> a, Map<dynamic, dynamic> b) {
if (a.length != b.length)
return false;
for (dynamic key in a.keys) {
for (final dynamic key in a.keys) {
if (!b.containsKey(key) || !_deepEquals(a[key], b[key]))
return false;
}
@@ -1782,7 +1782,7 @@ class _MatchesSemanticsData extends Matcher {
description.add(' with custom hints: $hintOverrides');
if (children != null) {
description.add(' with children:\n');
for (_MatchesSemanticsData child in children.cast<_MatchesSemanticsData>())
for (final _MatchesSemanticsData child in children.cast<_MatchesSemanticsData>())
child.describe(description);
}
return description;
@@ -1824,11 +1824,11 @@ class _MatchesSemanticsData extends Matcher {
return failWithDescription(matchState, 'maxValueLength was: ${data.maxValueLength}');
if (actions != null) {
int actionBits = 0;
for (SemanticsAction action in actions)
for (final SemanticsAction action in actions)
actionBits |= action.index;
if (actionBits != data.actions) {
final List<String> actionSummary = <String>[
for (SemanticsAction action in SemanticsAction.values.values)
for (final SemanticsAction action in SemanticsAction.values.values)
if ((data.actions & action.index) != 0)
describeEnum(action),
];
@@ -1858,11 +1858,11 @@ class _MatchesSemanticsData extends Matcher {
}
if (flags != null) {
int flagBits = 0;
for (SemanticsFlag flag in flags)
for (final SemanticsFlag flag in flags)
flagBits |= flag.index;
if (flagBits != data.flags) {
final List<String> flagSummary = <String>[
for (SemanticsFlag flag in SemanticsFlag.values.values)
for (final SemanticsFlag flag in SemanticsFlag.values.values)
if ((data.flags & flag.index) != 0)
describeEnum(flag),
];

View File

@@ -274,7 +274,7 @@ class TestAsyncUtils {
ErrorSummary('Asynchronous call to guarded function leaked.'),
ErrorHint('You must use "await" with all Future-returning test APIs.')
];
for (_AsyncScope scope in _scopeStack) {
for (final _AsyncScope scope in _scopeStack) {
final _StackEntry guarder = _findResponsibleMethod(scope.creationStack, 'guard', information);
if (guarder != null) {
information.add(ErrorDescription(

View File

@@ -54,7 +54,7 @@ Future<void> _runGroup(Suite suiteConfig, Group group, List<Group> parents, _Rep
setUpAllSucceeded = liveTest.state.result.isPassing;
}
if (setUpAllSucceeded) {
for (GroupEntry entry in group.entries) {
for (final GroupEntry entry in group.entries) {
if (entry is Group) {
await _runGroup(suiteConfig, entry, parents, reporter);
} else if (entry.metadata.skip) {
@@ -502,7 +502,7 @@ String _prefixLines(String text, String prefix, { String first, String last, Str
}
final StringBuffer buffer = StringBuffer('$first${lines.first}\n');
// Write out all but the first and last lines with [prefix].
for (String line in lines.skip(1).take(lines.length - 2)) {
for (final String line in lines.skip(1).take(lines.length - 2)) {
buffer.writeln('$prefix$line');
}
buffer.write('$last${lines.last}');

View File

@@ -117,7 +117,7 @@ void testWidgets(
assert(variant.values.isNotEmpty, 'There must be at least on value to test in the testing variant');
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
final WidgetTester tester = WidgetTester._(binding);
for (dynamic value in variant.values) {
for (final dynamic value in variant.values) {
final String variationDescription = variant.describeValue(value);
final String combinedDescription = variationDescription.isNotEmpty ? '$description ($variationDescription)' : description;
test(
@@ -629,7 +629,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
int numberOfTypes = 0;
int totalNumber = 0;
debugPrint('Some possible finders for the widgets at ${binding.globalToLocal(event.position)}:');
for (Element element in candidates) {
for (final Element element in candidates) {
if (totalNumber > 13) // an arbitrary number of finders that feels useful without being overwhelming
break;
totalNumber += 1; // optimistically assume we'll be able to describe it
@@ -755,7 +755,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
void verifyTickersWereDisposed([ String when = 'when none should have been' ]) {
assert(when != null);
if (_tickers != null) {
for (Ticker ticker in _tickers) {
for (final Ticker ticker in _tickers) {
if (ticker.isActive) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A Ticker was active $when.'),

View File

@@ -25,7 +25,7 @@ void main() {
focusNode.requestFocus();
await tester.idle();
for (String platform in platforms) {
for (final String platform in platforms) {
await tester.sendKeyEvent(LogicalKeyboardKey.shiftLeft, platform: platform);
await tester.sendKeyEvent(LogicalKeyboardKey.shift, platform: platform);
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyA, platform: platform);

View File

@@ -530,9 +530,9 @@ void main() {
int actions = 0;
int flags = 0;
const CustomSemanticsAction action = CustomSemanticsAction(label: 'test');
for (int index in SemanticsAction.values.keys)
for (final int index in SemanticsAction.values.keys)
actions |= index;
for (int index in SemanticsFlag.values.keys)
for (final int index in SemanticsFlag.values.keys)
// TODO(mdebbar): Remove this if after https://github.com/flutter/engine/pull/9894
if (SemanticsFlag.values[index] != SemanticsFlag.isMultiline)
flags |= index;

View File

@@ -20,7 +20,7 @@ void testConfig(
test(description, () {
expect(actualStringValue, expectedStringValue);
for (Type key in otherExpectedValues.keys) {
for (final Type key in otherExpectedValues.keys) {
expect(otherActualValues[key], otherExpectedValues[key]);
}
});