Add swift-format GitHub Action, config, and pre-commit hook#142
Draft
Add swift-format GitHub Action, config, and pre-commit hook#142
Conversation
Co-authored-by: jjpritzl <108085430+jjpritzl@users.noreply.github.com> Agent-Logs-Url: https://github.com/jamf/PPPC-Utility/sessions/1f5e71ff-f5b8-4e2c-8b0e-bc262951f2fd
Copilot
AI
changed the title
[WIP] Add Github action to run SwiftFormat
Add swift-format GitHub Action, config, and pre-commit hook
Mar 25, 2026
There was a problem hiding this comment.
Pull request overview
Adds Apple’s built-in swift-format to the repository to enforce consistent Swift formatting locally (pre-commit) and in CI, complementing the existing SwiftLint workflow.
Changes:
- Add
.swift-formatconfiguration (line length + indentation rules). - Add a GitHub Actions workflow to run
xcrun swift-format linton PRs. - Add a pre-commit hook and document how to install it in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
.swift-format |
Defines swift-format formatting configuration used by local/CI runs. |
.github/workflows/swift-format.yml |
Adds CI linting step using xcrun swift-format lint --strict. |
git-hooks/pre-commit.swift-format |
Formats only staged .swift files and re-stages them. |
README.md |
Documents developer workflow for installing the pre-commit hook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…op rules These rules conflict with existing codebase conventions (Logger constants, enum-style variable names, and forEach usage patterns). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
One-time bulk format using xcrun swift-format --in-place -r -p . This commit contains only formatting changes — no logic or functional changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Disable opening_brace rule in .swiftlint.yml (conflicts with swift-format's multiline condition brace placement) - Set multiElementCollectionTrailingCommas to false in .swift-format to avoid trailing comma conflicts with SwiftLint - Remove trailing commas added by swift-format - Remove superfluous swiftlint:disable file_length comment - Fix function_body_length violations caused by array expansion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TCCProfileViewController.swift exceeds the default 400-line limit after swift-format expanded multi-line arrays. Raising the threshold avoids needing inline swiftlint:disable comments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use NUL-delimited output (git diff -z) with xargs -0 to safely handle filenames containing spaces, tabs, or newlines. Pass -- before the file list to prevent paths beginning with - from being interpreted as options. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 34 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (4)
Source/View Controllers/TCCProfileViewController.swift:1
- This file previously disabled SwiftLint
file_lengthand that suppression was removed in this PR. With.swiftlint.ymlnow enforcingfile_lengtherror at 500 lines, this is likely to fail CI if the file remains over the limit. Either restore the per-file suppression (if acceptable), refactor/split the view controller into smaller components, or raise thefile_length.errorthreshold to avoid breaking the existing SwiftLint workflow.
git-hooks/pre-commit.swift-format:1 - The hook excludes renamed files (
--diff-filter=ACMomitsR), so a renamed Swift file (especially one renamed+modified) may skip formatting and then fail the CIswift-format lint --strictcheck. Consider includingRin the diff-filter (e.g.,ACMR) and avoiding newline round-tripping by keeping the file list null-delimited end-to-end (stream directly fromgit diff -zintoxargs -0).
git-hooks/pre-commit.swift-format:1 - The hook excludes renamed files (
--diff-filter=ACMomitsR), so a renamed Swift file (especially one renamed+modified) may skip formatting and then fail the CIswift-format lint --strictcheck. Consider includingRin the diff-filter (e.g.,ACMR) and avoiding newline round-tripping by keeping the file list null-delimited end-to-end (stream directly fromgit diff -zintoxargs -0).
git-hooks/pre-commit.swift-format:1 - The hook excludes renamed files (
--diff-filter=ACMomitsR), so a renamed Swift file (especially one renamed+modified) may skip formatting and then fail the CIswift-format lint --strictcheck. Consider includingRin the diff-filter (e.g.,ACMR) and avoiding newline round-tripping by keeping the file list null-delimited end-to-end (stream directly fromgit diff -zintoxargs -0).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Delete .swiftlint.yml config - Delete .github/workflows/swiftlint.yml GitHub Action - Remove SwiftLint build phase from Xcode project - Remove all inline swiftlint:disable/enable comments from Swift files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Apple's built-in
swift-format(viaxcrun swift-format) for code formatting, complementing the existing SwiftLint workflow..swift-format— Config: 200-char line length, 4-space indentation.github/workflows/swift-format.yml— CI lint check on PRs (xcrun swift-format lint --strict -r -p .), runs onmacos-latestgit-hooks/pre-commit.swift-format— Formats only staged.swiftfiles and re-stages themREADME.md— Added "Development" section with hook install instructionsPre-commit hook install
Rollout note
Before the CI check will pass, the existing codebase needs a one-time formatting pass committed separately:
xcrun swift-format --in-place -r -p .This should be a dedicated formatting-only commit to keep
git blameclean.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.