Add --strict-baseline flag to fail lint when baselined violations are fixed#6614
Add --strict-baseline flag to fail lint when baselined violations are fixed#6614swizzlr wants to merge 1 commit into
Conversation
Generated by 🚫 Danger |
| return StyleViolation( | ||
| ruleDescription: description, | ||
| severity: .error, | ||
| location: violation.location, | ||
| reason: """ | ||
| Violation previously recorded in the baseline for '\(violation.ruleIdentifier)' is no longer \ | ||
| detected. Regenerate the baseline to acknowledge this fix | ||
| """ | ||
| ) |
There was a problem hiding this comment.
@SimplyDanny is there a more idomatic way to say "baseline is no longer valid"?
There was a problem hiding this comment.
baseline is "stale" perhaps, but that still doesn't feel quite right.
… fixed Adds a new `--strict-baseline` command-line flag and matching `strict_baseline` configuration key. When enabled, SwiftLint compares the stored baseline against the current run and reports an error for each violation recorded in the baseline that is no longer detected, encouraging users to regenerate the baseline after fixes. Fixes realm#6511
ea41fb4 to
070968f
Compare
| @Flag(help: """ | ||
| Fail linting if violations previously recorded in the baseline are no longer \ | ||
| detected. Encourages keeping the baseline up-to-date by regenerating it \ | ||
| once baselined violations have been fixed. |
There was a problem hiding this comment.
This feels a little verbose. Fail linting when violations recorded in the baseline are no longer detected. might enough here (lifted from the strictBaseline property doc comment).
| return numberOfWarningViolations >= warningThreshold | ||
| } | ||
|
|
||
| private static func createFixedBaselineViolation(fromBaseline violation: StyleViolation) -> StyleViolation { |
There was a problem hiding this comment.
So reporting these as violations is very convenient, but the fixed_baseline_violation "pseudo-rule" is not really a rule - for example, I can't // swiftlint:disable fixed_baseline_violation at the top of a file (and fixed_baseline_violation isn't easily matched up to strict_baseline).
I wonder if these should be reported as Issue's instead, something like
Issue.fixedBaselineViolation(violation).print()
Summary
Closes #6511.
Adds a new
--strict-baselinecommand-line flag and matchingstrict_baselineconfiguration key. When enabled, SwiftLint comparesthe stored baseline against violations detected in the current run and
reports an error for each baselined violation that is no longer
detected, encouraging the baseline to be regenerated once violations
have been fixed. This brings SwiftLint's baseline behaviour in line
with other linters.
Behaviour is opt-in and off by default, preserving backwards
compatibility.
Details
--strict-baselineflag onswiftlint lint/swiftlint analyzevia
LintOrAnalyzeArguments.strict_baselineYAML key wired throughConfiguration,Configuration+Parsing, andConfiguration+Merging.LintOrAnalyzeCommandnow retains the loaded baseline and, aftercollection, diffs it against the current run via the existing
Baseline.compareprimitive. Each fixed baselined violation issurfaced as a
fixed_baseline_violationerror at the originallocation.
Test plan
swift test --filter BaselineTestsswift test --filter LintOrAnalyzeOptionstrailing-semicolon warnings, then removed the semicolons and
re-ran with
--baseline baseline.json --strict-baseline. Exitcode
2and per-violation errors as expected. Without--strict-baseline, exit code0.swift buildclean.