Add swift-format GitHub Action, config, and pre-commit hook#142
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
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.
.swiftlint.yml
Outdated
|
|
||
| file_length: | ||
| warning: 500 | ||
| error: 500 |
There was a problem hiding this comment.
The file_length rule sets warning and error to the same threshold (500), which effectively removes the warning tier and can make violations immediately error-level. Consider setting warning < error (e.g., 500/700) or omitting warning if you want a single threshold.
| error: 500 | |
| error: 700 |
There was a problem hiding this comment.
this does make sense. Let's make error 700. We can scale both of these numbers back later on as we get a handle on where the long files are.
- 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>
.swiftlint.yml
Outdated
|
|
||
| file_length: | ||
| warning: 500 | ||
| error: 500 |
There was a problem hiding this comment.
this does make sense. Let's make error 700. We can scale both of these numbers back later on as we get a handle on where the long files are.
|
@watkyn That file doesn't exist anymore, we deleted it because we don't need the SwiftLint stuff and have switched over to swift-format in this PR :D |
right! |
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.