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

[tool] Add a way to opt a file out of formatting #4292

Merged
merged 1 commit into from
Sep 1, 2021

Conversation

Hixie
Copy link
Contributor

@Hixie Hixie commented Aug 31, 2021

Per discussion on Discord, this adds a way to opt-out of the formatting.

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 relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@google-cla google-cla bot added the cla: yes label Aug 31, 2021
@Hixie Hixie changed the title [tool] Add a way to opt a file out of Dart formatting [tool] Add a way to opt a file out of formatting Aug 31, 2021
@Hixie
Copy link
Contributor Author

Hixie commented Aug 31, 2021

I made this apply to all files rather than just Dart, mostly because it was easier to plug into the code where File objects were still around. I considered pushing the File-to-String conversion lower down the codepaths, but that ended up being pretty invasive and not obviously better. I also considered just having the Dart code go back from String to Files but that ended up being pretty ugly too.

@Hixie Hixie force-pushed the format branch 2 times, most recently from b105647 to 596b516 Compare August 31, 2021 07:06
return files
.where((File file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I made this apply to all files rather than just Dart, mostly because it was easier to plug into the code where File objects were still around.

I would much rather this apply only to Dart, as this is strictly worse than clang-format off for clang-format-formatted files because the latter will prevent people with editors that are configured to auto-format from accidentally formatting the file when editing it. (I really, really wish dartfmt would support this for the same reason.)

What's the issue with just adding a file.basename.endsWith('.dart') check inside this lambda?

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 seemed weird to have this code know about file extensions too, but i'm happy to add it if you like

@@ -10,6 +10,8 @@
`--no-push-flags`. Releases now always tag and push.
- **Breaking change**: `publish`'s `--package` flag has been replaced with the
`--packages` flag used by most other packages.
- Formatting now skips files that contain a line that exactly
matches the string `// This file is hand-formatted`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The period needs to be inside the `s; it's part of the string being searched for.

// consider it included. It should get filtered out later when we
// deal with file extensions. (We want the formatters to see the
// files that we can't read, in case they have opinions about such
// things as character encodings, etc.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use "we" in comments. go/avoidwe has the full explanation; the short version is that even within just this last sentence "we" is actually two completely different concepts, which makes it difficult to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please update the style guide to mention this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since i added the check for the extension, i was able to remove all this error handling logic and thus the comment is gone too

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still want me to add this to the style guide? I'm happy to do so, but it's also a position that not everyone agrees with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't feel strongly about it (but then I get a guilty pleasure in writing sentences that use the same pronoun to mean different people), but if there's an argument to be made that it makes things clearer, we should document it somewhere people can see it.

@Hixie Hixie force-pushed the format branch 3 times, most recently from 0e63075 to 1a5a4a2 Compare August 31, 2021 19:24
@Hixie
Copy link
Contributor Author

Hixie commented Aug 31, 2021

PTAL

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM modulo adding a version change.

@@ -12,6 +12,8 @@
`--packages` flag used by most other packages.
- **Breaking change** Passing both `--run-on-changed-packages` and `--packages`
is now an error; previously it the former would be ignored.
- Formatting now skips files that contain a line that exactly
matches the string `// This file is hand-formatted.`.
Copy link
Contributor

Choose a reason for hiding this comment

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

This got merged into the wrong section, it needs to be in a new one since 0.6.0 is published.

You should actually do a version bump in this PR since in order to use it in flutter/packages it'll need to be published (and then the flutter/packages pin rolled to pick it up)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, and it should be changed to "skips Dart 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.

Done.

// was added because Hixie hurts when dealing with what dartfmt does to
// artisanally-formatted Dart, while Stuart gets really frustrated when
// dealing with PRs from newer contributors who don't know how to make Dart
// readable. After much discussion, it was decided that files in the plugins
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣 Well, I did ask.

(I was just thinking something like "Allow package maintainers to opt out of Dart autoformatting in order to use Flutter's manual formatting style instead.", but this certainly works.)

@Hixie Hixie added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Sep 1, 2021
@fluttergithubbot fluttergithubbot merged commit bafc4ee into flutter:master Sep 1, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 1, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 2, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 7, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 9, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants