Skip to content

FENCE-2852: Make .swiftlint-baseline.json diffs readable via git clean filter#614

Merged
stevepopovich merged 3 commits into
masterfrom
swiftlint-baseline-readable-diffs
Jun 5, 2026
Merged

FENCE-2852: Make .swiftlint-baseline.json diffs readable via git clean filter#614
stevepopovich merged 3 commits into
masterfrom
swiftlint-baseline-readable-diffs

Conversation

@stevepopovich

@stevepopovich stevepopovich commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Problem

Every change to .swiftlint-baseline.json shows up in git as one giant unreadable line, because SwiftLint serializes the baseline as minified single-line JSON. The file is only ever read (via --baseline in make lint-swift, make lint-swift-fix, and CI), and SwiftLint parses it with a JSON decoder — so whitespace is irrelevant to SwiftLint and a pretty-printed file is accepted identically.

A one-time reformat wouldn't survive the next swiftlint --write-baseline regeneration, which would revert it to one line.

Is this worth the merge?

Fix

Add a git clean filter that pretty-prints the baseline with jq -S . (sorted keys → deterministic) whenever it's staged. Git always stores and diffs a readable version regardless of how SwiftLint wrote the working copy. As a bonus, a regeneration that changes no violations produces no diff at all (git runs both sides through the clean filter before comparing).

  • .gitattributes — bind .swiftlint-baseline.json to a swiftlint-baseline filter
  • bootstrap.sh — install jq and configure the clean filter (clean-only, non-required so an unconfigured clone gracefully falls back to today's behavior)
  • AGENTS.md (CLAUDE.md symlinks to it) — document the filter and the make bootstrap requirement
  • .swiftlint-baseline.json — one-time reformat (pretty, sorted keys)

Notes

  • This PR's baseline diff is the one-time large reformat (~1,472 lines). Every change after this lands as a clean, minimal diff.
  • The filter only takes effect for a teammate after they run make bootstrap once, just installs jq on the user's machine. Until then they fall back to the current one-line behavior — no errors.

SwiftLint writes the baseline as one minified line, so every change to it
shows up as a single unreadable git diff line. SwiftLint only ever reads the
file (via --baseline) with a JSON decoder, so formatting is irrelevant to it.

Add a git clean filter that pretty-prints the baseline with `jq -S .` on
stage, so git always stores and diffs a readable, sorted-key version
regardless of how SwiftLint wrote the working copy. A regeneration that
changes no violations now produces no diff at all.

- .gitattributes: bind the baseline to a swiftlint-baseline filter
- bootstrap.sh: install jq and configure the (non-required) clean filter
- AGENTS.md: document the filter and the `make bootstrap` requirement
- .swiftlint-baseline.json: one-time reformat (pretty, sorted keys)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@stevepopovich stevepopovich marked this pull request as ready for review June 4, 2026 14:45
@stevepopovich stevepopovich changed the title Make .swiftlint-baseline.json diffs readable via git clean filter FENCE-2852: Make .swiftlint-baseline.json diffs readable via git clean filter Jun 4, 2026
@stevepopovich stevepopovich merged commit 152d86d into master Jun 5, 2026
2 checks passed
@stevepopovich stevepopovich deleted the swiftlint-baseline-readable-diffs branch June 5, 2026 13:35
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