Skip to content

Add --strict-baseline flag to fail lint when baselined violations are fixed#6614

Open
swizzlr wants to merge 1 commit intorealm:mainfrom
swizzlr:strict-baseline
Open

Add --strict-baseline flag to fail lint when baselined violations are fixed#6614
swizzlr wants to merge 1 commit intorealm:mainfrom
swizzlr:strict-baseline

Conversation

@swizzlr
Copy link
Copy Markdown

@swizzlr swizzlr commented Apr 20, 2026

Summary

Closes #6511.

Adds a new --strict-baseline command-line flag and matching
strict_baseline configuration key. When enabled, SwiftLint compares
the 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

  • New --strict-baseline flag on swiftlint lint / swiftlint analyze
    via LintOrAnalyzeArguments.
  • New strict_baseline YAML key wired through Configuration,
    Configuration+Parsing, and Configuration+Merging.
  • LintOrAnalyzeCommand now retains the loaded baseline and, after
    collection, diffs it against the current run via the existing
    Baseline.compare primitive. Each fixed baselined violation is
    surfaced as a fixed_baseline_violation error at the original
    location.
  • README and CHANGELOG updated.

Test plan

  • swift test --filter BaselineTests
  • swift test --filter LintOrAnalyzeOptions
  • Manual end-to-end: recorded a baseline against a file with
    trailing-semicolon warnings, then removed the semicolons and
    re-ran with --baseline baseline.json --strict-baseline. Exit
    code 2 and per-violation errors as expected. Without
    --strict-baseline, exit code 0.
  • swift build clean.

@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Apr 20, 2026

19 Messages
📖 Building this branch resulted in a binary size of 27622.34 KiB vs 27621.7 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.83 s vs 0.83 s on main (0% slower).
📖 Linting Alamofire with this PR took 1.08 s vs 1.05 s on main (2% slower).
📖 Linting Brave with this PR took 7.38 s vs 7.4 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 28.55 s vs 28.55 s on main (0% slower).
📖 Linting Firefox with this PR took 12.33 s vs 12.35 s on main (0% faster).
📖 Linting Kickstarter with this PR took 8.53 s vs 8.55 s on main (0% faster).
📖 Linting Moya with this PR took 0.47 s vs 0.46 s on main (2% slower).
📖 Linting NetNewsWire with this PR took 2.87 s vs 2.91 s on main (1% faster).
📖 Linting Nimble with this PR took 0.67 s vs 0.68 s on main (1% faster).
📖 Linting PocketCasts with this PR took 8.02 s vs 7.91 s on main (1% slower).
📖 Linting Quick with this PR took 0.46 s vs 0.46 s on main (0% slower).
📖 Linting Realm with this PR took 3.03 s vs 3.05 s on main (0% faster).
📖 Linting Sourcery with this PR took 1.91 s vs 1.87 s on main (2% slower).
📖 Linting Swift with this PR took 4.8 s vs 4.8 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.33 s vs 0.36 s on main (8% faster).
📖 Linting VLC with this PR took 1.26 s vs 1.23 s on main (2% slower).
📖 Linting Wire with this PR took 19.17 s vs 19.2 s on main (0% faster).
📖 Linting WordPress with this PR took 12.95 s vs 12.96 s on main (0% faster).

Generated by 🚫 Danger

Comment on lines +297 to +305
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
"""
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimplyDanny is there a more idomatic way to say "baseline is no longer valid"?

@swizzlr swizzlr marked this pull request as ready for review April 20, 2026 21:05
… 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
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.

Linting should fail when baseline violations are fixed

2 participants