macos: lint Swift files using SwiftLint (#10860)

SwiftLint <https://realm.github.io/SwiftLint/> is both a linter and
formatting. It's a popular way to spot issues and enforce a consistent
style.

Our SwiftLint configuration lives in `macos/.swiftlint.yml`, where is is
automatically discovered. It's very configurable, and I made an initial
pass as some basic, weakly-opinionated rules. The "TODO" section lists
rules that currently have violations but can be easily (auto)fixed in
follow-up commits.

Our integration is CLI-based. Similar to our other support tools, we
expect developers to install `swiftlint` via nix or e.g. Homebrew. This
is documented in HACKING.md.

We also have an optional Xcode integration, for in-editor feedback. When
`swiftlint` is available, it's run as a script-based Build Phase.

SwiftLint supports an auto-fix mode (`--fix`). Agents are aware of this
via AGENTS.md.

The rules are enforced using a (nix-based) CI job.
This commit is contained in:
Mitchell Hashimoto
2026-02-19 13:34:22 -08:00
committed by GitHub
6 changed files with 156 additions and 0 deletions

View File

@@ -11,10 +11,25 @@ concurrency:
cancel-in-progress: true
jobs:
paths:
if: github.repository == 'ghostty-org/ghostty'
runs-on: namespace-profile-ghostty-xsm
outputs:
macos: ${{ steps.filter.outputs.macos }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
macos:
- 'macos/**'
required:
name: "Required Checks: Test"
runs-on: namespace-profile-ghostty-xsm
needs:
- paths
- build-bench
- build-dist
- build-examples
@@ -36,6 +51,7 @@ jobs:
- test-macos
- pinact
- prettier
- swiftlint
- alejandra
- typos
- shellcheck
@@ -927,6 +943,28 @@ jobs:
- name: prettier check
run: nix develop -c prettier --check .
swiftlint:
if: github.repository == 'ghostty-org/ghostty' && needs.paths.outputs.macos == 'true'
runs-on: namespace-profile-ghostty-macos-tahoe
needs: paths
timeout-minutes: 60
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# TODO(tahoe): https://github.com/NixOS/nix/issues/13342
- uses: DeterminateSystems/nix-installer-action@main
with:
determinate: true
- uses: cachix/cachix-action@3ba601ff5bbb07c7220846facfa2cd81eeee15a1 # v16
with:
name: ghostty
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
skipPush: true
useDaemon: false # sometimes fails on short jobs
- name: swiftlint check
run: nix develop -c swiftlint lint --strict macos
alejandra:
if: github.repository == 'ghostty-org/ghostty'
runs-on: namespace-profile-ghostty-xsm