Skip to content

Commit

Permalink
Enable prefer_final_in_for_each lint for consistency (#7866)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored May 31, 2024
1 parent abcdb96 commit 5dbdf76
Show file tree
Hide file tree
Showing 105 changed files with 220 additions and 219 deletions.
1 change: 1 addition & 0 deletions packages/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ linter:
- prefer_contains
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_foreach
# - prefer_function_declarations_over_variables # not yet tested
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools_app/lib/src/framework/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class DevToolsAppBar extends StatelessWidget {
isScrollable: true,
labelPadding: EdgeInsets.zero,
tabs: [
for (var screen in visibleScreens)
for (final screen in visibleScreens)
Padding(
padding: const EdgeInsets.symmetric(horizontal: tabBarSpacing),
child: screen.buildTab(context),
),
// We need to include a widget in the tab bar for the overflow screens
// because the [_tabController] expects a length equal to the total
// number of screens, hidden or not.
for (var _ in overflowScreens) const SizedBox.shrink(),
for (final _ in overflowScreens) const SizedBox.shrink(),
],
);

Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/framework/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class DevToolsScaffoldState extends State<DevToolsScaffold>
Widget build(BuildContext context) {
// Build the screens for each tab and wrap them in the appropriate styling.
final tabBodies = [
for (var screen in widget.screens)
for (final screen in widget.screens)
Align(
alignment: Alignment.topLeft,
child: FocusScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class AppSizeController {
int totalByteSize = 0;

// Given a child, build its subtree.
for (Map<String, dynamic> child in rawChildren) {
for (final Map<String, dynamic> child in rawChildren) {
final childTreemapNode = showDiff
? generateDiffTree(child, diffTreeType!)
: generateTree(child);
Expand Down Expand Up @@ -721,7 +721,7 @@ class AppSizeController {
}
final childrenMap = <String, TreemapNode>{};

for (TreemapNode child in children) {
for (final child in children) {
childrenMap[child.name] = child;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class DominatorTreeNode extends TreeNode<DominatorTreeNode> {

factory DominatorTreeNode.from(CallGraphNode cgNode) {
final domNode = DominatorTreeNode._(cgNode);
for (var dominated in cgNode.dominated) {
for (final dominated in cgNode.dominated) {
domNode.addChild(DominatorTreeNode.from(dominated));
}
return domNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ class BreakpointManager with DisposerMixin {

final positions = <SourcePosition>[];

for (SourceReportRange range in report.ranges!) {
for (final range in report.ranges!) {
final possibleBreakpoints = range.possibleBreakpoints;
if (possibleBreakpoints != null) {
for (int tokenPos in possibleBreakpoints) {
for (final tokenPos in possibleBreakpoints) {
positions.add(SourcePosition.calculatePosition(script, tokenPos));
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ class BreakpointManager with DisposerMixin {
case EventKind.kBreakpointResolved:
final breakpoint = event.breakpoint!;
_breakpoints.value = [
for (var b in _breakpoints.value)
for (final b in _breakpoints.value)
if (b != event.breakpoint) b,
breakpoint,
];
Expand Down Expand Up @@ -393,12 +393,12 @@ class BreakpointManager with DisposerMixin {
final breakpoint = event.breakpoint;

_breakpoints.value = [
for (var b in _breakpoints.value)
for (final b in _breakpoints.value)
if (b != breakpoint) b,
];

_breakpointsWithLocation.value = [
for (var b in _breakpointsWithLocation.value)
for (final b in _breakpointsWithLocation.value)
if (b.breakpoint != breakpoint) b,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class BreakOnExceptionsControl extends StatelessWidget {
},
isDense: true,
items: [
for (var mode in ExceptionMode.modes)
for (final mode in ExceptionMode.modes)
DropdownMenuItem<ExceptionMode>(
value: mode,
child: Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ class FileNode extends TreeNode<FileNode> {
// The name of this node is not exposed to users.
final root = FileNode('<root>');

for (var script in scripts) {
for (final script in scripts) {
final directoryParts = ScriptRefUtils.splitDirectoryParts(script);

FileNode node = root;

for (var name in directoryParts) {
for (final name in directoryParts) {
node = node._getCreateChild(name);
}

Expand All @@ -294,7 +294,7 @@ class FileNode extends TreeNode<FileNode> {
void _trimChildrenAsMapEntries() {
_childrenAsMap.clear();

for (var child in children) {
for (final child in children) {
child._trimChildrenAsMapEntries();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class VMServiceObjectNode extends TreeNode<VMServiceObjectNode> {
void _trimChildrenAsMapEntries() {
_childrenAsMap.clear();

for (var child in children) {
for (final child in children) {
child._trimChildrenAsMapEntries();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DeepLinksController extends DisposableController
@visibleForTesting
List<LinkData> linkDatasByPath(List<LinkData> linkdatas) {
final linkDatasByPath = <String, LinkData>{};
for (var linkData in linkdatas) {
for (final linkData in linkdatas) {
final previousRecord = linkDatasByPath[linkData.path];
linkDatasByPath[linkData.path] = LinkData(
domain: linkData.domain,
Expand Down Expand Up @@ -185,7 +185,7 @@ class DeepLinksController extends DisposableController
@visibleForTesting
List<LinkData> linkDatasByDomain(List<LinkData> linkdatas) {
final linkDatasByDomain = <String, LinkData>{};
for (var linkData in linkdatas) {
for (final linkData in linkdatas) {
if (linkData.domain.isNullOrEmpty) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DeepLinksServices {
required String? localFingerprint,
}) async {
final domainErrors = <String, List<DomainError>>{
for (var domain in domains) domain: <DomainError>[],
for (final domain in domains) domain: <DomainError>[],
};

// The request can take 1000 domains at most, make a few calls in serial with a batch of _domainBatchSize.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ List<double> computeRenderSizes({
// and we can just divide the size evenly
// but it should be at least as big as [smallestRenderSize]
final renderSize = math.max(smallestRenderSize, maxSizeAvailable / n);
return [for (var _ in sizes) renderSize];
return [for (final _ in sizes) renderSize];
}

List<double> transformToRenderSize(double largestRenderSize) => [
for (var s in sizes)
for (final s in sizes)
(s - smallestSize) *
(largestRenderSize - smallestRenderSize) /
(largestSize - smallestSize) +
Expand All @@ -84,7 +84,7 @@ List<double> computeRenderSizes({
if (useMaxSizeAvailable && sum(renderSizes) < maxSizeAvailable) {
largestRenderSize = (maxSizeAvailable - n * smallestRenderSize) *
(largestSize - smallestSize) /
sum([for (var s in sizes) s - smallestSize]) +
sum([for (final s in sizes) s - smallestSize]) +
smallestRenderSize;
renderSizes = transformToRenderSize(largestRenderSize);
}
Expand All @@ -108,7 +108,7 @@ class LayoutProperties {
(child) => LayoutProperties(child, copyLevel: copyLevel - 1),
)
.toList(growable: false) {
for (var child in children) {
for (final child in children) {
child.parent = this;
}
}
Expand All @@ -123,7 +123,7 @@ class LayoutProperties {
required this.size,
required this.flexFit,
}) {
for (var child in children) {
for (final child in children) {
child.parent = this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ class InspectorTreeController extends DisposableController
// Method defined to avoid a direct Flutter dependency.
void setState(VoidCallback fn) {
fn();
for (var client in _clients) {
for (final client in _clients) {
client.onChanged();
}
}

void requestFocus() {
for (var client in _clients) {
for (final client in _clients) {
client.requestFocus();
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ class InspectorTreeController extends DisposableController
}

void scrollToRect(Rect targetRect) {
for (var client in _clients) {
for (final client in _clients) {
client.scrollToRect(targetRect);
}
}
Expand Down Expand Up @@ -499,7 +499,7 @@ class InspectorTreeController extends DisposableController
void animateToTargets(List<InspectorTreeNode> targets) {
Rect? targetRect;

for (InspectorTreeNode target in targets) {
for (final target in targets) {
final row = getRowForNode(target);
if (row != null) {
final rowRect = getBoundingBox(row);
Expand Down Expand Up @@ -582,7 +582,7 @@ class InspectorTreeController extends DisposableController
}
final inlineProperties = parent.inlineProperties;

for (RemoteDiagnosticsNode property in inlineProperties) {
for (final property in inlineProperties) {
appendChild(
treeNode,
setupInspectorTreeNode(
Expand All @@ -596,7 +596,7 @@ class InspectorTreeController extends DisposableController
);
}
if (children != null) {
for (RemoteDiagnosticsNode child in children) {
for (final child in children) {
appendChild(
treeNode,
setupInspectorTreeNode(
Expand Down Expand Up @@ -1133,7 +1133,7 @@ class _RowPainter extends CustomPainter {

final InspectorTreeNode node = row.node;
final bool showExpandCollapse = node.showExpandCollapse;
for (int tick in row.ticks) {
for (final int tick in row.ticks) {
currentX = _controller.getDepthIndent(tick) - inspectorColumnWidth * 0.5;
// Draw a vertical line for each tick identifying a connection between
// an ancestor of this node and some other node in the tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BoxLayoutExplorerWidgetState extends LayoutExplorerWidgetState<
final length = sizes.length;
double total = 1.0; // This isn't set to zero to avoid divide by zero bugs.
final fractions = minFractions.toList();
for (var size in sizes) {
for (final size in sizes) {
if (size != null) {
total += math.max(0, size);
}
Expand All @@ -157,7 +157,7 @@ class BoxLayoutExplorerWidgetState extends LayoutExplorerWidgetState<
}
}
final output = <double>[];
for (var fraction in fractions) {
for (final fraction in fractions) {
output.add(fraction * availableSize);
}
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class FlexLayoutExplorerWidgetState extends LayoutExplorerWidgetState<
: colorScheme.crossAxisColor,
selectedItemBuilder: (context) {
return [
for (var alignment in alignmentEnumEntries)
for (final alignment in alignmentEnumEntries)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down Expand Up @@ -190,7 +190,7 @@ class FlexLayoutExplorerWidgetState extends LayoutExplorerWidgetState<
];
},
items: [
for (var alignment in alignmentEnumEntries)
for (final alignment in alignmentEnumEntries)
DropdownMenuItem(
value: alignment,
child: Container(
Expand Down Expand Up @@ -510,7 +510,7 @@ class _VisualizeFlexChildrenState extends State<VisualizeFlexChildren> {
}

final freeSpacesWidgets = [
for (var renderProperties in [
for (final renderProperties in [
...mainAxisSpaces,
...crossAxisSpaces,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ List<double> computeRenderSizes({
// and we can just divide the size evenly
// but it should be at least as big as [smallestRenderSize]
final renderSize = math.max(smallestRenderSize, maxSizeAvailable / n);
return [for (var _ in sizes) renderSize];
return [for (final _ in sizes) renderSize];
}

List<double> transformToRenderSize(double largestRenderSize) => [
for (var s in sizes)
for (final s in sizes)
(s - smallestSize) *
(largestRenderSize - smallestRenderSize) /
(largestSize - smallestSize) +
Expand All @@ -84,7 +84,7 @@ List<double> computeRenderSizes({
if (useMaxSizeAvailable && sum(renderSizes) < maxSizeAvailable) {
largestRenderSize = (maxSizeAvailable - n * smallestRenderSize) *
(largestSize - smallestSize) /
sum([for (var s in sizes) s - smallestSize]) +
sum([for (final s in sizes) s - smallestSize]) +
smallestRenderSize;
renderSizes = transformToRenderSize(largestRenderSize);
}
Expand All @@ -108,7 +108,7 @@ class LayoutProperties {
(child) => LayoutProperties(child, copyLevel: copyLevel - 1),
)
.toList(growable: false) {
for (var child in children) {
for (final child in children) {
child.parent = this;
}
}
Expand All @@ -123,7 +123,7 @@ class LayoutProperties {
required this.size,
required this.flexFit,
}) {
for (var child in children) {
for (final child in children) {
child.parent = this;
}
}
Expand Down
Loading

0 comments on commit 5dbdf76

Please sign in to comment.