Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@zanderso
Copy link
Member

@zanderso zanderso commented Feb 18, 2024

error('Found ${incorrect.length} python file${plural ? 's' : ''}'
' which ${plural ? 'were' : 'was'} formatted incorrectly:');
incorrect.forEach(stderr.writeln);
stdout.writeln('To fix, run:');
Copy link
Member

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:

Suggested change
stdout.writeln('To fix, run:');
stdout.writeln('To fix, run `dart ci/bin/format.dart --fix` or:');

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively:

Suggested change
stdout.writeln('To fix, run:');
stdout.writeln('To fix, run `et format` or:');

Copy link
Member Author

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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.

Copy link
Member Author

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.
Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

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

Suggested change
/// Constructs the 'query' command.
/// Constructs the 'format' command.

Copy link
Member Author

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';
Copy link
Member

@loic-sharma loic-sharma Feb 20, 2024

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.

Copy link
Member Author

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.';
Copy link
Member

Choose a reason for hiding this comment

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

Consider:

Suggested change
String get description => 'Fixes formatting.';
String get description => 'Format source code files.';

Copy link
Member Author

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.',
Copy link
Member

Choose a reason for hiding this comment

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

Consider:

Suggested change
help: 'Fixes formatting.',
help: 'Updates source code files with formatted content.',

Copy link
Member Author

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;
Copy link
Member

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

Copy link
Contributor

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" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with --dry-run.

@zanderso zanderso force-pushed the et-format branch 3 times, most recently from f5222b5 to 888dbd6 Compare February 20, 2024 21:05
@zanderso zanderso removed the request for review from liamappelbe February 20, 2024 23:22
@zanderso zanderso merged commit 3116c41 into flutter:main Feb 21, 2024
@zanderso zanderso deleted the et-format branch February 21, 2024 03:40
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 21, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 21, 2024
…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
zanderso added a commit that referenced this pull request Feb 21, 2024
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants