Skip to content

Conversation

@lsaudon
Copy link
Contributor

@lsaudon lsaudon commented Apr 18, 2023

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. You must list at least one issue.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

This PR is closed, i enable the rule and run dart fix --apply

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: internationalization Supporting other languages or locales. (aka i18n) a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 18, 2023
@christopherfujino
Copy link
Contributor

@lsaudon thank you for this massive contribution!

Unfortunately, you have merge conflicts on this PR. But, given the size, I think it might be infeasible to code review, and to keep up to date with upstream changes. The only way to land this kind of a migration might be to do it in smaller chunks before the lint is enabled. WDYT @goderbauer ?

@lsaudon
Copy link
Contributor Author

lsaudon commented Apr 21, 2023

I knew it was too big.
Indeed I can make by smaller part.

@justinmc
Copy link
Contributor

I just wanted to say I think I like the move to prefer_final_parameters. I was wondering why we didn't follow that.

I agree with @christopherfujino that you should split this up, maybe be library or something, and merge those PRs individually. Then enable the lint parameter at the end.

@christopherfujino
Copy link
Contributor

I just wanted to say I think I like the move to prefer_final_parameters. I was wondering why we didn't follow that.

I'm not opposed to this change, but it's unfortunate it adds so much verbosity, alas...

@justinmc
Copy link
Contributor

Yeah that is a good point. I think it's worth it even though I have to type final a lot more, but others may disagree.

@goderbauer
Copy link
Member

I do think this will be a worthwhile change. Landing it may be difficult given how many files this affects, which is one reason why we haven't done this earlier. Doing it in smaller chunks is a good idea. Another idea was to land something like this on a major holiday where traffic in the repo is low to avoid merge conflicts...

@goderbauer
Copy link
Member

Looks like you're already opening up smaller PRs. I am going to close this one then.

@goderbauer goderbauer closed this Apr 24, 2023
@goderbauer
Copy link
Member

but it's unfortunate it adds so much verbosity, alas...

I kinda wish Dart would have picked 'final' as the default and you had to specify something if you didn't want final since that seems to be less common... Oh well...

@zanderso
Copy link
Member

zanderso commented Apr 24, 2023

This seems to be adding a lot of verbosity to flutter tool code. What sort of errors does this catch? Do we make those mistakes in practice? I'm not convinced this is a positive change.

@jonahwilliams
Copy link
Contributor

I agree, this is a lot of churn that makes the resulting code substantially more verbose. I don't think the benefits outweigh the costs here, as I cannot recall any instances of accidentally assigning to a parameter

@Hixie
Copy link
Contributor

Hixie commented Apr 24, 2023

I use this in my personal projects (largely because I turn on all the lints by default and then only opt-out the ones that are just obviously wrong or mutually-exclusive) and I must admit I don't think this lint has ever really done me any good, and as others have said, it's pretty verbose. I think the cost/benefit on this one is pretty questionable. I never put the final in there until I try to compile, and then I just have to add "final"s everywhere, which is very tedious.

That said I'm happy to defer to the relevant code owners (@christopherfujino for the tool, @goderbauer for the framework, @stuartmorgan for the packages repo) in terms of whether we should actually do this. I just ask that we be consistent throughout the repo (and dart:ui, and ideally flutter/packages) about it.

@christopherfujino
Copy link
Contributor

Maybe what we really want is a lint that you should never re-assign an argument.

That said I'm happy to defer to the relevant code owners (@christopherfujino for the tool, @goderbauer for the framework, @stuartmorgan for the packages repo) in terms of whether we should actually do this. I just ask that we be consistent throughout the repo (and dart:ui, and ideally flutter/packages) about it.

My vote would be weakly against because of the cost to line lengths and readability.

@stuartmorgan-g
Copy link
Contributor

I'm relatively neutral on this; I don't love the verbosity, but I'm generally willing to trade verbosity for safety.

Do we make those mistakes in practice?

This seems like a key question. I haven't read through the 3k files changed here: @lsaudon How many instances were there (roughly) where you had to make a code change as a result of adding final to parameters?

I just ask that we be consistent throughout the repo (and dart:ui, and ideally flutter/packages) about it.

My policy for flutter/packages is that we deviate from flutter/flutter analysis options only where there is a compelling argument for why it should be different (e.g., sort_pub_dependencies is off for a specific reason in flutter/flutter that doesn't apply at all to flutter/packages, and we still have unnecessary_null_comparison: ignore in flutter/packages because packages don't all require Dart 3 so can still run in mixed mode). There's no good argument for a different choice here, so it'll stay consistent with flutter/flutter whichever way it goes.

@goderbauer
Copy link
Member

goderbauer commented Apr 25, 2023

Given the feedback, I am rather neutral on this one as well now. In the past, we have chosen a pretty verbose style for Flutter and this follows that style. We also require final for local variables, so also doing it for parameters seems consistent.

However, I can't recall any instances where this would have prevented a bug. So, if the general consensus is that it is too verbose let's not enforce it. We should update the comment in the analysis_options.yaml file to record our decision:

# - prefer_final_parameters # we should enable this one day when it can be auto-fixed (https://github.com/dart-lang/linter/issues/3104), see also parameter_assignments

@goderbauer
Copy link
Member

Maybe what we really want is a lint that you should never re-assign an argument.

That lint exists: https://dart-lang.github.io/linter/lints/parameter_assignments.html However, I believe that one is too strong because in many instances we do actually assign values to parameters on purpose.

@lsaudon lsaudon deleted the add_prefer_final_parameters branch April 25, 2023 09:46
auto-submit bot pushed a commit that referenced this pull request Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: internationalization Supporting other languages or locales. (aka i18n) a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants