Skip to content

Run swiftformat via mint run #6261

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 11 commits into from
Aug 12, 2020
Merged

Run swiftformat via mint run #6261

merged 11 commits into from
Aug 12, 2020

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented Aug 12, 2020

This avoids users needing to bootstrap manually and avoids permission problems with installation in /usr/local.

This avoids users needing to bootstrap manually and avoids permission
problems with installation in /usr/local.
@wilhuff
Copy link
Contributor Author

wilhuff commented Aug 12, 2020

I expect check to fail because I've introduced an intentional formatting error. I'll fix that once I see the failure.

scripts/style.sh Outdated
function swiftformat() {
mint run swiftformat "$@"
}

system=$(uname -s)
if [[ "$system" == "Darwin" ]]; then
version=$(swiftformat --version)
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and the below) can probably be omitted as well, since the swiftformat version will be enforced by the Mintfile. Maybe instead they can be replaced by a check for a local Mint installation?

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'd prefer to leave the version log in because it makes it easier to directly see in CI logs what happened. The comment about not checking the version is also useful because it contrasts with clang-format, which we do rigorously check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, looking at the check failure this CL induced, the first run of mint run swiftformat installs it and that turns out to be this version check. It gives output like this:

Found: clang-format version 10.0.1 
Found: 🌱 Cloning SwiftFormat 0.45.5
🌱 Resolving package
🌱 Building package
🌱 Installed SwiftFormat 0.45.5
🌱 Running swiftformat 0.45.5...
0.45.5

... which is a little ridiculous. I've removed the whole section now since this will be obvious enough.

Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

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

Thanks!

scripts/style.sh Outdated
system=$(uname -s)
if [[ "$system" == "Darwin" ]]; then
version=$(swiftformat --version)
# Log the version in non-interactive use as it can be useful in travis logs.
# A version check is not requried because `mint bootstrap` ensures the
Copy link
Member

Choose a reason for hiding this comment

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

typo: required

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.

README.md Outdated
@@ -137,16 +137,15 @@ See [HeadersImports.md](HeadersImports.md).
### Code Formatting

To ensure that the code is formatted consistently, run the script
[./scripts/style.sh](https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/style.sh)
[./scripts/check.sh](https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/check.sh)
before creating a PR.

Travis will verify that any code changes are done in a style compliant way. Install
Copy link
Member

Choose a reason for hiding this comment

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

s/Travis/Git Hub Actions/

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 (though as GitHub Actions).

brew install clang-format

clang-format -version
Copy link
Member

Choose a reason for hiding this comment

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

I think having the -version command for clang-format at least was helpful for debugging purposes - I imagine we can get rid of the swiftformat one since we know where it comes from at least. Any reason you removed the clang-format one otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

style.sh already logs the version used. This is duplicative.

scripts/style.sh Outdated
system=$(uname -s)
if [[ "$system" == "Darwin" ]]; then
version=$(swiftformat --version)
# Log the version in non-interactive use as it can be useful in travis logs.
# A version check is not requried because `mint bootstrap` ensures the
Copy link
Member

Choose a reason for hiding this comment

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

s/requried/required/`

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.

scripts/style.sh Outdated
# /usr/local.
export MINT_PATH=Mint

function swiftformat() {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we only use this twice, and it may be less obvious if a developer goes to run this locally. Any objection to just changing the swiftformat to mint run swiftformat in the script below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No objection. Inlined.

Note that by hand use of swiftformat is not really something anyone can reasonably do. You need to pass a bunch of command-line options to control the style we use. Now you also need to set MINT_PATH. As a result, if you want to format a file without running all the checks you should just run style.sh.

Copy link
Member

Choose a reason for hiding this comment

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

Yep that totally makes sense, I just realized that's exactly what I do.

The output of mint run includes details on which versions it is
installing so there's no ambiguity in CI logs.
Copy link
Member

@ryanwilson ryanwilson left a comment

Choose a reason for hiding this comment

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

Nice improvement, thanks!

@wilhuff wilhuff merged commit feeee48 into master Aug 12, 2020
@wilhuff wilhuff deleted the wilhuff/swift-format branch August 12, 2020 21:50
@firebase firebase locked and limited conversation to collaborators Sep 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants