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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ ZipBuilder/Packages
ZipBuilder/*.xcodeproj
ZipBuilder/Package.resolved

# Mint package manager
Mint

# IntelliJ
.idea
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`clang-format` and `swiftformat`:
GitHub Actions will verify that any code changes are done in a style compliant
way. Install `clang-format` and `mint`:

```
brew install clang-format
brew install mint
mint install [email protected]
```

### Running Unit Tests
Expand Down
11 changes: 4 additions & 7 deletions scripts/setup_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ if ! git rev-parse origin/master >& /dev/null; then
git fetch origin
fi

# Setup mint which installs a versioned swiftformat.
set -x
brew install mint
mint bootstrap --link

# mint installs tools from Mintfile on demand.
brew install clang-format
brew install mint

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.

swiftformat -version
# Explicitly mint bootstrap to show its version in the "Setup check" GHA phase
mint bootstrap
30 changes: 13 additions & 17 deletions scripts/style.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

# Copyright 2017 Google
# Copyright 2017 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -55,22 +58,12 @@ case "$version" in
;;
esac

# Ensure that tools in `Mintfile` are installed locally to avoid permissions
# problems that would otherwise arise from the default of installing in
# /usr/local.
export MINT_PATH=Mint

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.
if [[ ! -t 1 ]]; then
echo "Found: $version"
fi
version="${version/*version /}"
# Ensure the swiftformat version is 0.45.5 (as of 2020-08-09)
# Update Mintfile and run command below to update.
if [[ "$version" != 0.45.5 ]]; then
echo "Version $version installed. Please install swiftformat 0.45.5"
echo "brew install mint; mint install nicklockwood/[email protected]"
exit 1
fi
fi

# Joins the given arguments with the separator given as the first argument.
function join() {
Expand Down Expand Up @@ -162,6 +155,9 @@ s%^./%%
# Sources pulled in by travis bundler, with and without a leading slash
\%^/?vendor/bundle/% d

# Sources pulled in by the Mint package manager
\%^Mint% d

# Auth Sample is not subject to formatting
\%^(FirebaseAuth/Tests/Sample)/% d

Expand All @@ -185,7 +181,7 @@ for f in $files; do
# Match output that says:
# 1/1 files would have been formatted. (with --dryrun)
# 1/1 files formatted. (without --dryrun)
swiftformat "${swift_options[@]}" "$f" 2>&1 | grep '^1/1 files' > /dev/null
mint run swiftformat "${swift_options[@]}" "$f" 2>&1 | grep '^1/1 files' > /dev/null
else
false
fi
Expand Down