-
Notifications
You must be signed in to change notification settings - Fork 6k
[et] Adds a format command #50747
[et] Adds a format command #50747
Conversation
ci/bin/format.dart
Outdated
| error('Found ${incorrect.length} python file${plural ? 's' : ''}' | ||
| ' which ${plural ? 'were' : 'was'} formatted incorrectly:'); | ||
| incorrect.forEach(stderr.writeln); | ||
| stdout.writeln('To fix, run:'); |
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.
Should we recommend the --fix flag too? Perhaps:
| stdout.writeln('To fix, run:'); | |
| stdout.writeln('To fix, run `dart ci/bin/format.dart --fix` or:'); |
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.
Alternatively:
| stdout.writeln('To fix, run:'); | |
| stdout.writeln('To fix, run `et format` or:'); |
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.
Good idea. Done.
| // run the program under ci/bin/format.dart. Instead, format.dart should be | ||
| // moved under the engine_tool package and invoked by a function call. The file | ||
| // ci/bin/format.dart should be split up so that each of its `FormatCheckers` is | ||
| // in a seprate file under src/formatters, and they should be unit-tested. |
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.
| // in a seprate file under src/formatters, and they should be unit-tested. | |
| // in a separate file under src/formatters, and they should be unit-tested. |
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.
Done.
| // run the program under ci/bin/format.dart. Instead, format.dart should be | ||
| // moved under the engine_tool package and invoked by a function call. The file | ||
| // ci/bin/format.dart should be split up so that each of its `FormatCheckers` is | ||
| // in a seprate file under src/formatters, and they should be unit-tested. |
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.
Should we tag this with a TODO that links to flutter/flutter#132807?
Completely up to you, I don't mind either ways.
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.
Good idea. Done.
|
|
||
| /// The 'format' command. | ||
| final class FormatCommand extends CommandBase { | ||
| /// Constructs the 'query' command. |
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.
This comment and the comment above on the class declaration aren't particularly helpful. I'd consider removing them. See: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-useless-documentation
| /// Constructs the 'query' command. | |
| /// Constructs the 'format' command. |
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.
Done.
| const String allFlag = 'all'; | ||
| const String builderFlag = 'builder'; | ||
| const String fixFlag = 'fix'; | ||
| const String printDiffsFlag = 'print-diffs'; |
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.
Could you expand on the value of putting all flags in a single file? I imagine this will grow organically over time until it becomes unwieldy. It also hurts readability since in format_command.dart we can't see that printDiffsFlag is print-diffs.
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.
The desire is to have flags named consistently across subcommands, while letting the subcommand flag help messages describe what they mean for the particular subcommand. Open to suggestions on a different way to achieve that.
| String get name => 'format'; | ||
|
|
||
| @override | ||
| String get description => 'Fixes formatting.'; |
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.
Consider:
| String get description => 'Fixes formatting.'; | |
| String get description => 'Format source code 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.
Done with slightly different wording.
| ..addFlag( | ||
| fixFlag, | ||
| abbr: 'f', | ||
| help: 'Fixes formatting.', |
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.
Consider:
| help: 'Fixes formatting.', | |
| help: 'Updates source code files with formatted content.', |
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.
Done with slightly different wording.
| Future<int> run() async { | ||
| final bool all = argResults![allFlag]! as bool; | ||
| final bool fix = argResults![fixFlag]! as bool; | ||
| final bool printDiffs = argResults![printDiffsFlag]! as bool; |
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.
Currently if I want to see the diffs without updating files I need to do:
et --no-fix --print-diffs
Would it make sense to make print diffs default to the negation of fix? And make fix default to the negation of print diffs?
For example:
et format # Updates files, no diff
et format --no-fix # Shows diff, does not update files
et format --print-diffs # Shows diff, does not update 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.
Why not just one flag "--dry-run" and drop "--no-fix" and "--print-diffs" ?
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.
Went with --dry-run.
f5222b5 to
888dbd6
Compare
…143816) flutter/engine@7002504...efc6994 2024-02-21 zanderso@users.noreply.github.com Make global builds uniquely named per platform (flutter/engine#50764) 2024-02-21 zanderso@users.noreply.github.com [et] Adds a format command (flutter/engine#50747) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jimgraham@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This PR changes the format check on CI to use the command added in #50747. Additionally, while making this change, I noticed that the CI check was not checking the formatting of all files, and that as a result, files were present in the repo with incorrect formatting. I have fixed the formatting and fixed the check to always check all files.
For flutter/flutter#132807