Skip to content

Commit bf9ce1d

Browse files
authored
Enable the avoid_final_parameters lint. (#185216)
`avoid_final_parameters` lint fires when using a `final` modifier in any parameter list. This is a preparatory lint that helps us migrate to Dart 3.13. All violations from this lint will become compile-time errors in Dart 3.13 when the primary constructors feature ships. Fixes: dart-lang/sdk#62590 **Related to breaking changes:** There should be nothing that breaks from adding this lint. Function types with `final` are already a compile-time error and any customers overriding a method with a `final` parameter won't break their code. ``` // Framework code class C { void m(int x) { ... } // Removed var here. } ``` ``` // ... // User code class B implements C { void m(final int x) { ... } // Will still work. } ``` This change should be test exempt. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent c1deae0 commit bf9ce1d

23 files changed

Lines changed: 57 additions & 57 deletions

File tree

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ linter:
5555
- avoid_equals_and_hash_code_on_mutable_classes
5656
- avoid_escaping_inner_quotes
5757
- avoid_field_initializers_in_const_classes
58-
# - avoid_final_parameters # incompatible with prefer_final_parameters
58+
# TODO(kallentu): Remove this lint once the Dart SDK in Flutter is on version 3.13.
59+
- avoid_final_parameters
5960
- avoid_function_literals_in_foreach_calls
6061
# - avoid_futureor_void # not yet tested
6162
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558

dev/benchmarks/complex_layout/test/measure_scroll_smoothness.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import 'package:integration_test/integration_test.dart';
1515
/// Generates the [PointerEvent] to simulate a drag operation from
1616
/// `center - totalMove/2` to `center + totalMove/2`.
1717
Iterable<PointerEvent> dragInputEvents(
18-
final Duration epoch,
19-
final Offset center, {
20-
final Offset totalMove = const Offset(0, -400),
21-
final Duration totalTime = const Duration(milliseconds: 2000),
22-
final double frequency = 90,
18+
Duration epoch,
19+
Offset center, {
20+
Offset totalMove = const Offset(0, -400),
21+
Duration totalTime = const Duration(milliseconds: 2000),
22+
double frequency = 90,
2323
}) sync* {
2424
final Offset startLocation = center - totalMove / 2;
2525
// The issue is about 120Hz input on 90Hz refresh rate device.

dev/bots/suite_runners/run_test_harness_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Future<void> _validateEngineRevision() async {
175175
}
176176
final String actualVersion;
177177
try {
178-
actualVersion = result.flattenedStderr!.split('\n').firstWhere((final String line) {
178+
actualVersion = result.flattenedStderr!.split('\n').firstWhere((String line) {
179179
return line.startsWith('Flutter Engine Version:');
180180
});
181181
} on StateError {

engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,7 @@ class EditableTextGeometry {
27162716
assert(encodedGeometry.containsKey('transform'));
27172717

27182718
final transformList = List<double>.from(
2719-
encodedGeometry.readList('transform').map((final dynamic e) => (e as num).toDouble()),
2719+
encodedGeometry.readList('transform').map((dynamic e) => (e as num).toDouble()),
27202720
);
27212721
return EditableTextGeometry(
27222722
width: encodedGeometry.readDouble('width'),

engine/src/flutter/lib/web_ui/test/common/matchers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class HtmlPatternMatcher extends Matcher {
257257
final html.Element pattern;
258258

259259
@override
260-
bool matches(final Object? object, Map<Object?, Object?> matchState) {
260+
bool matches(Object? object, Map<Object?, Object?> matchState) {
261261
// TODO(srujzs): Replace this with `!object.isJSAny` once we have that API
262262
// in `dart:js_interop`.
263263
// https://github.com/dart-lang/sdk/issues/56905

engine/src/flutter/lib/web_ui/test/ui/scene_builder_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ ui.Picture drawPicture(void Function(ui.Canvas) drawCommands) {
663663
return recorder.endRecording();
664664
}
665665

666-
ui.Scene backdropBlurWithTileMode(ui.TileMode? tileMode, final double rectSize, final int count) {
666+
ui.Scene backdropBlurWithTileMode(ui.TileMode? tileMode, double rectSize, int count) {
667667
final double imgSize = rectSize * count;
668668

669669
const white = ui.Color(0xFFFFFFFF);

engine/src/flutter/shell/platform/windows/fixtures/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,10 @@ Future<void> sendSemanticsTreeInfo() async {
421421

422422
final Iterable<ui.FlutterView> views = ui.PlatformDispatcher.instance.views;
423423
final ui.FlutterView view1 = views.firstWhere(
424-
(final ui.FlutterView view) => view != ui.PlatformDispatcher.instance.implicitView,
424+
(ui.FlutterView view) => view != ui.PlatformDispatcher.instance.implicitView,
425425
);
426426
final ui.FlutterView view2 = views.firstWhere(
427-
(final ui.FlutterView view) =>
428-
view != view1 && view != ui.PlatformDispatcher.instance.implicitView,
427+
(ui.FlutterView view) => view != view1 && view != ui.PlatformDispatcher.instance.implicitView,
429428
);
430429

431430
ui.SemanticsUpdate createSemanticsUpdate(int nodeId) {

examples/image_list/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
154154
});
155155
}
156156

157-
Widget createImage(final int index, final Completer<bool> completer) {
157+
Widget createImage(int index, Completer<bool> completer) {
158158
return Image.network(
159159
'https://localhost:${widget.port}/${_counter * images + index}',
160160
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {

examples/multiple_windows/lib/app/popup_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class _PopupButtonState extends State<PopupButton> {
3232
super.dispose();
3333
}
3434

35-
void _onPressed(final WindowRegistry windowRegistry, final WindowSettings windowSettings) {
35+
void _onPressed(WindowRegistry windowRegistry, WindowSettings windowSettings) {
3636
// Toggle popup visibility.
3737
if (_popupWindowEntry != null) {
3838
_popupWindowEntry!.controller.destroy();

examples/multiple_windows/lib/app/tooltip_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class _TooltipButtonState extends State<TooltipButton> {
3232
super.dispose();
3333
}
3434

35-
void _onPressed(final WindowRegistry windowRegistry, final WindowSettings windowSettings) {
35+
void _onPressed(WindowRegistry windowRegistry, WindowSettings windowSettings) {
3636
// Toggle tooltip visibility.
3737
if (_tooltipEntry != null) {
3838
_tooltipEntry!.controller.destroy();

0 commit comments

Comments
 (0)