Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Arbitrary format options for localizations generation (#102983) #167029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 30, 2025

Conversation

Gustl22
Copy link
Contributor

@Gustl22 Gustl22 commented Apr 12, 2025

Migration of Localization Generation Option 1 breaks dart format . --set-exit-if-changed checks (as commonly used in pipelines), as the generated file does not comply the dart format rules.

This PR:

  • Formats the generated localization files by default
    • In contrast to this comment I don't see it as breaking as the files are generated dynamically on every change and there's no need in migrating them. Also any tests should not fail as either the format was done manually afterwards anyways, or the formatting was not checked at all (in third party apps / libraries) as the output had not a correct format in any use case of checking via dart format.
  • Add tests for no-format
  • Add option to add arbitrary arguments to the dart format command to allow customized formatting

Closes #167982
Contributes to: #102983 (comment)

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

Pre-launch Checklist

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

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 12, 2025
@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 12, 2025

Asking for your opinion @matanlurey. Thank you for maintaining ;D

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Overall, this looks good, but I have a few comments after my first review pass.

@@ -15,6 +15,7 @@ import 'stock_strings_en.dart';
import 'stock_strings_es.dart';

// ignore_for_file: type=lint
// dart format on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason we want to write this comment to i18n generated files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the implementation, so no there's no particular reason. So we can remove this line, if format: true.
But we still need // dart format off if format: false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just get rid of format: false, it doesn't provide any value at this point.

That is, in this PR, I don't think we should add any // dart format x comments, and we should just concentrate on making format: true the default, and stop respecting format: false entirely.

'--enable-experiment',
]);

final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace the test cases which check for files with the following pattern:

// `exists` is part of package:file_testing
expect(fileSystemEntity, exists);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the optimization, but not sure, if this is something to be changed in this PR, the mechanism is used in other methods in this testing file also. So this should be something refactored in general. Should I create an issue for that?

@bkonyi bkonyi requested a review from matanlurey April 28, 2025 13:30
@bkonyi
Copy link
Contributor

bkonyi commented Apr 28, 2025

@matanlurey can you take a quick look as a second reviewer?

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see an issue filed first (not a comment buried in an issue) describing what problem this is solving, and work arounds exist (if any), before moving forward here. Some questions I'd need answered before moving forward:

  1. Why is running dart format after flutter gen-l10n insufficient?
  2. Why do formatter arguments need to be specified in this PR?

@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 29, 2025

I created #167982 for better reproduction and discussion.

Why is running dart format after flutter gen-l10n insufficient?

Because the mechanism for dart format --set-exit-if-changed wouldn't work any more. There's no point in checking the format in a CI (e.g. on a PR), if all files are formatted before checking them.

Why do formatter arguments need to be specified in this PR?

Because app / project developers might decide to have further options applied to their general formatting (such as -l 120 or --indent or --enable-experiment) which cannot be reflected when formatting the generated files. Thus they are formatted different than checking with dart format --set-exit-if-changed [my-format-options]

@Gustl22 Gustl22 requested review from bkonyi and matanlurey April 29, 2025 09:14
@@ -15,6 +15,7 @@ import 'stock_strings_en.dart';
import 'stock_strings_es.dart';

// ignore_for_file: type=lint
// dart format on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just get rid of format: false, it doesn't provide any value at this point.

That is, in this PR, I don't think we should add any // dart format x comments, and we should just concentrate on making format: true the default, and stop respecting format: false entirely.

@@ -200,6 +200,10 @@ class GenerateLocalizationsCommand extends FlutterCommand {
help:
'When specified, the "dart format" command is run after generating the localization files.',
);
argParser.addMultiOption(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add this.

All of the options that are important to dart format can now be specified by the user:

https://dart.dev/tools/dart-format#configuring-formatter-page-width

@matanlurey
Copy link
Contributor

Ok, I agree we should fix this. In this PR I'd like to see:

  • Removal of the code around format: false (there is no reason to do this)
  • Removal of the option to provide format arguments (should be done via analysis_options, see above)

With those two changes, I'll LGTM.

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Approval.

I'd also like to cherrypick this to the beta branch once it lands.

@matanlurey matanlurey added this pull request to the merge queue Apr 30, 2025
Merged via the queue into flutter:master with commit 45f431f Apr 30, 2025
142 checks passed
@matanlurey matanlurey added the cp: beta cherry pick this pull request to beta release candidate branch label Apr 30, 2025
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Apr 30, 2025
…102983) (flutter#167029)

Migration of Localization Generation [Option
1](https://docs.flutter.dev/release/breaking-changes/flutter-generate-i10n-source#migration-guide)
breaks `dart format . --set-exit-if-changed` checks (as commonly used in
pipelines), as the generated file does not comply the `dart format`
rules.

This PR:
- Formats the generated localization files by default
- In contrast to [this
comment](flutter#109171 (comment))
I don't see it as breaking as the files are generated dynamically on
every change and there's no need in migrating them. Also any tests
should not fail as either the format was done manually afterwards
anyways, or the formatting was not checked at all (in third party apps /
libraries) as the output had not a correct format in any use case of
checking via `dart format`.
- Add tests for `no-format`
- Add option to add arbitrary arguments to the `dart format` command to
allow customized formatting

Closes flutter#167982
Contributes to:
flutter#102983 (comment)

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

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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
@Gustl22
Copy link
Contributor Author

Gustl22 commented Apr 30, 2025

Thank you for your proposals, didn't know about the format settings in analysis_options.yml. It might be helpful to link them in the migration guide, I can do that, if desired.

Unfortunately I didn't had the opportunity to change the PR title and description so it matches the actual changes. Hope this doesn't raise confusion.

Thank you for reviewing and picking up the change!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cp: beta cherry pick this pull request to beta release candidate branch tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration to Localized messages generated into source break CI pipeline
3 participants