FENCE-2852: Make .swiftlint-baseline.json diffs readable via git clean filter#614
Merged
Merged
Conversation
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>
alanjcharles14
approved these changes
Jun 4, 2026
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.
Problem
Every change to
.swiftlint-baseline.jsonshows 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--baselineinmake 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-baselineregeneration, 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.jsonto aswiftlint-baselinefilterbootstrap.sh— installjqand configure the clean filter (clean-only, non-requiredso an unconfigured clone gracefully falls back to today's behavior)AGENTS.md(CLAUDE.mdsymlinks to it) — document the filter and themake bootstraprequirement.swiftlint-baseline.json— one-time reformat (pretty, sorted keys)Notes
make bootstraponce, just installsjqon the user's machine. Until then they fall back to the current one-line behavior — no errors.