-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
feat: Arbitrary format options for localizations generation (#102983) #167029
Conversation
Asking for your opinion @matanlurey. Thank you for maintaining ;D |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
packages/flutter_tools/lib/src/localizations/localizations_utils.dart
Outdated
Show resolved
Hide resolved
'--enable-experiment', | ||
]); | ||
|
||
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n')); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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?
@matanlurey can you take a quick look as a second reviewer? |
There was a problem hiding this 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:
- Why is running
dart format
afterflutter gen-l10n
insufficient? - Why do formatter arguments need to be specified in this PR?
I created #167982 for better reproduction and discussion.
Because the mechanism for
Because app / project developers might decide to have further options applied to their general formatting (such as |
@@ -15,6 +15,7 @@ import 'stock_strings_en.dart'; | |||
import 'stock_strings_es.dart'; | |||
|
|||
// ignore_for_file: type=lint | |||
// dart format on |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
Ok, I agree we should fix this. In this PR I'd like to see:
With those two changes, I'll LGTM. |
There was a problem hiding this 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.
…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
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! |
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 thedart format
rules.This PR:
dart format
.no-format
dart format
command to allow customized formattingCloses #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.