Skip to content
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

Use swift-format for Swift file formatting #261

Merged
merged 7 commits into from
Feb 20, 2025

Conversation

jasikpark
Copy link
Contributor

@jasikpark jasikpark commented Feb 20, 2025

Try 3 of #254, #256

This adds a script called swift-format.sh that ignores the files listed in .swiftformatignore while that feature is being added into swiftlang/swift-format.

swift-format is shipped with XCode 16 and is included in the Github macos runners. There's a menuitem in XCode that allows formatting the file you're viewing. A good blog post is at: https://calebhearth.com/swift-format-github-action

Under Editor -> Structure -> Format with swift-format:

image

This script has been vendored from swiftlang/github-workflows and adds a comment mentioning where it was vendored from and which edits have been made to it differing from the original source.

A quirk is that this script relies on the ignore file being at the top level, so it's a bit brittle. We could honestly just hardcode the ignore value in the script, but 🤷

#263 will enable the format check and format all swift code, then a PR after that will git blame ignore the formatting PR.

Testing

To test, you can run ./swift-format.sh from the root of the repo and see that swift code is formatted. To test the "check" run ./swift-format.sh check and see that there is a git diff outputted and that the exit code was unsuccessful.

You may also see a failed run at https://github.com/DefinedNet/mobile_nebula/actions/runs/13444683597/job/37567211304?pr=261 while it still exists.

Refs:

@jasikpark jasikpark requested a review from IanVS February 20, 2025 20:50
@jasikpark jasikpark marked this pull request as ready for review February 20, 2025 20:51
@jasikpark jasikpark force-pushed the use-swift-format-script-for-formatting branch 2 times, most recently from 0fc8938 to 597eb27 Compare February 20, 2025 21:07
@jasikpark jasikpark merged commit 4d34083 into main Feb 20, 2025
4 checks passed
@jasikpark jasikpark deleted the use-swift-format-script-for-formatting branch February 20, 2025 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants