Skip to content

Fix baseline matching in /private directories when excluded is non-empty - #6962

Open
Marve10s wants to merge 1 commit into
realm:mainfrom
Marve10s:fix/baseline-private-path-matching
Open

Marve10s wants to merge 1 commit into
realm:mainfrom
Marve10s:fix/baseline-private-path-matching

Conversation

@Marve10s

Copy link
Copy Markdown

Fixes #6909

On macOS, baselines stop matching entirely when the project lives under /private (for example /private/tmp/...) and the config has a non-empty excluded: list. Writing a baseline and immediately linting with it still reports every baselined violation. Removing excluded: makes the same baseline work.

The root cause is a path-spelling disagreement introduced with the URL-based locations in #6813. Baseline entries are written from Location.relativeDisplayPath, which keeps the /private cwd spelling. When reading, CodableLocation.location rebuilt the path through String.url(), and its standardizedFileURL resolves the /private symlink away. The decoded location's relative path could then no longer strip the /private cwd, so its key (var/folders/.../Sources/Foo.swift) never equalled the live violation's key (Sources/Foo.swift).

Decoding should be the inverse of encoding, and encoding does not normalize. This resolves the stored path against the current working directory without symlink standardization, while keeping two behaviors of the old helper: the directory-hint repair for working-directory overrides that were created without one, and lexical normalization via .standardized so absolute paths containing . or .. components still match as before. The shared String.url() and relativeDisplayPath helpers are untouched, so configuration paths and reporter display are unaffected.

The new BaselineTests cases build fixtures explicitly under /private/tmp and round-trip baselines through both /private and non-/private spellings (including through a symlinked directory), cover unhinted cwd overrides in the existing read/write test, and cover absolute stored paths with dot components.

One nearby pre-existing inconsistency is left alone: live file URLs are standardized on the no-exclusions discovery path but not on the enumerator path used with exclusions, so a baseline written before adding an excluded: entry can store a different key form. That predates this change and seems best handled separately from this regression.

@SwiftLintBot

Copy link
Copy Markdown
20 Messages
📖 Building this branch resulted in a binary size of 28755.98 KiB vs 28755.54 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.67 s vs 0.68 s on main (1% faster).
📖 Linting Alamofire with this PR took 0.96 s vs 0.97 s on main (1% faster).
📖 Linting Brave with this PR took 5.47 s vs 5.48 s on main (0% faster).
📖 Linting Brigade with this PR took 18.01 s vs 18.26 s on main (1% faster).
📖 Linting DuckDuckGo with this PR took 33.52 s vs 33.27 s on main (0% slower).
📖 Linting Firefox with this PR took 11.87 s vs 11.88 s on main (0% faster).
📖 Linting Kickstarter with this PR took 7.34 s vs 7.37 s on main (0% faster).
📖 Linting Moya with this PR took 0.38 s vs 0.38 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 2.58 s vs 2.59 s on main (0% faster).
📖 Linting Nimble with this PR took 0.55 s vs 0.56 s on main (1% faster).
📖 Linting PocketCasts with this PR took 7.42 s vs 7.46 s on main (0% faster).
📖 Linting Quick with this PR took 0.36 s vs 0.36 s on main (0% slower).
📖 Linting Realm with this PR took 2.99 s vs 2.97 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.65 s vs 1.56 s on main (5% slower).
📖 Linting Swift with this PR took 4.63 s vs 4.64 s on main (0% faster).
📖 Linting SwiftLintPerformanceTests with this PR took 0.18 s vs 0.18 s on main (0% slower).
📖 Linting VLC with this PR took 1.44 s vs 1.46 s on main (1% faster).
📖 Linting Wire with this PR took 16.59 s vs 16.6 s on main (0% faster).
📖 Linting WordPress with this PR took 10.68 s vs 10.68 s on main (0% slower).

Generated by 🚫 Danger

This branch has not been deployed

No deployments
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.

Baseline matching fails for every violation under /private when excluded: is non-empty (regression sibling of #6782)

2 participants