Add --pretty-baseline flag for reviewable baseline diffs#6615
Open
swizzlr wants to merge 1 commit into
Open
Conversation
c39879a to
25cae6f
Compare
Generated by 🚫 Danger |
Introduces a `--pretty-baseline` flag (plus `pretty_baseline` configuration key) that writes baseline files as pretty-printed JSON with sorted keys and unescaped slashes. Violations have always been sorted by file and location, so the complete opt-in output is deterministic across runs and produces stable, human-reviewable diffs whenever the baseline is regenerated. The default output is unchanged, so existing baselines remain byte-identical. `--pretty-baseline` without `--write-baseline` is rejected at argument-parse time.
25cae6f to
0f06940
Compare
Collaborator
|
This seems quite nice - the original format was optimized for size over readability - having the option to choose is good. Is it possible to add a |
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.
Summary
Adds an opt-in
--pretty-baselineflag (plus matchingpretty_baselineconfiguration key) that writes baseline files aspretty-printed JSON with sorted keys and unescaped forward slashes.
Violations have always been sorted by file and location, so the
complete opt-in output is deterministic across runs and produces
stable, human-reviewable diffs whenever a baseline is regenerated.
Default behaviour is unchanged — existing baselines remain
byte-identical, so this change is fully backwards compatible.
Motivation: the default baseline is emitted as a single minified line
with escaped slashes and (in compact mode) non-deterministic key
order. That makes it nearly impossible to review updates in a PR, and
trivial changes can reorder unrelated entries. With
--pretty-baseline,regenerating a baseline after fixing a few violations produces a
minimal, readable diff.
Details
--pretty-baselineflag onswiftlint lint/swiftlint analyzevia
LintOrAnalyzeArguments, threaded throughLintOrAnalyzeOptionsand
LintOrAnalyzeCommandtoBaseline.write(toPath:pretty:).pretty_baselineYAML key wired throughConfiguration,Configuration+Parsing, andConfiguration+Merging.Baseline.write(toPath:pretty:)defaults topretty: false, so theexisting default output is preserved exactly.
--pretty-baselinewithout--write-baselineis rejected atargument-parse time via a
validate()method onLintOrAnalyzeArguments.BaselineTestsassert both the default (compact,one-line) and the opt-in (pretty, multiline, sorted) output using the
existing
withExampleFileCreatedhelper.Test plan
swift test --filter BaselineTests— all 8 cases pass, includinga new snapshot test asserting the exact pretty-printed output and
a companion test asserting the default remains compact.
swift test --filter LintOrAnalyzeOptionsTests.--write-baselinealone(single-line output preserved) and with
--write-baseline X.json --pretty-baseline(pretty, sorted,unescaped slashes).
swiftlint --pretty-baselinewithout--write-baselineprints a validation error.