Skip to content

Honor excluded paths for projects under /private-symlinked directories - #6783

Merged
SimplyDanny merged 1 commit into
realm:mainfrom
tumata:fix/exclude-paths-under-private
Jun 22, 2026
Merged

SimplyDanny merged 1 commit into
realm:mainfrom
tumata:fix/exclude-paths-under-private

Conversation

@tumata

@tumata tumata commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6782.

excluded paths are silently ignored and the files get linted anyway when the linted project's real path is located under a /private-symlinked directory. On macOS that includes anything under /tmp, /var, and /var/folders (firmlinks to /private/tmp, /private/var, …), so it commonly affects CI workspaces and mktemp directories. This is a regression introduced in 0.64.0.

Root cause

Exclusion matchers/prefixes are built from excludedPaths, whose URLs are produced by String.url(), which applies .standardizedFileURL. On macOS, standardization strips a leading /private (so /private/var/x → /var/x).

The file paths to be linted, however, come from FileManager's directory enumerator, which yields paths that keep the /private prefix (/private/var/x/...).

So Excluder.excludes(path:) compares /private/... file paths against /... patterns, and the FilenameMatcher / prefix check never matches. Under /Users there is no /private to strip, which is why the bug looks machine-dependent.

Fix

In Excluder.excludes(path:), compare each candidate against the path both with and without a leading /private prefix, using string operations only. This bridges the discrepancy without touching the filesystem, and unlike standardizing every candidate it leaves matching behavior for non-/private paths exactly as it was.

Performance

An earlier iteration of this fix standardized every candidate via standardizedFileURL, which stats each path and regressed linting performance noticeably. The current string-only approach avoids that. Measured with tools/oss-check's command (lint --no-cache --enable-all-rules, 5-run average) on the performance corpus:

avg vs main
main 0.18 s N/A
standardizedFileURL approach 0.28 s +55%
this PR (string-only) 0.20 s +10% (within noise)

Same violation count in all cases.

Test

Added ConfigurationTests.testExcludedPathsUnderSymlinkedDirectory, which creates a small project under the system temporary directory (resolves under /private/var/folders/… on macOS) and asserts the excluded file is not linted. Verified it fails without the fix (the excluded file leaks into the lintable set) and passes with it. The full FileSystemAccessTests suite passes.

@tumata

tumata commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@SimplyDanny please take a look at your earliest convenience. This is a bit of a blocker for us, because we use homebrew to install SwiftLint on our CI and are unable to pin to a specific version. All I can do for now is disable the lint checks on our repos, which is not ideal. Thanks!

@SwiftLintBot

SwiftLintBot commented Jun 22, 2026 •

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in the same binary size as when built on main.
📖 Linting Aerial with this PR took 0.63 s vs 0.64 s on main (1% faster).
📖 Linting Alamofire with this PR took 0.93 s vs 0.95 s on main (2% faster).
📖 Linting Brave with this PR took 6.03 s vs 5.97 s on main (1% slower).
📖 Linting DuckDuckGo with this PR took 26.27 s vs 26.26 s on main (0% slower).
📖 Linting Firefox with this PR took 10.43 s vs 10.34 s on main (0% slower).
📖 Linting Kickstarter with this PR took 7.49 s vs 7.53 s on main (0% faster).
📖 Linting Moya with this PR took 0.36 s vs 0.36 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 2.34 s vs 2.35 s on main (0% faster).
📖 Linting Nimble with this PR took 0.54 s vs 0.59 s on main (8% faster).
📖 Linting PocketCasts with this PR took 6.94 s vs 6.9 s on main (0% slower).
📖 Linting Quick with this PR took 0.34 s vs 0.33 s on main (3% slower).
📖 Linting Realm with this PR took 2.49 s vs 2.52 s on main (1% faster).
📖 Linting Sourcery with this PR took 1.49 s vs 1.48 s on main (0% slower).
📖 Linting Swift with this PR took 4.28 s vs 4.28 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.16 s vs 0.16 s on main (0% slower).
📖 Linting VLC with this PR took 1.1 s vs 1.12 s on main (1% faster).
📖 Linting Wire with this PR took 15.32 s vs 15.26 s on main (0% slower).
📖 Linting WordPress with this PR took 9.92 s vs 9.96 s on main (0% faster).

Generated by 🚫 Danger

@SimplyDanny

Copy link
Copy Markdown
Collaborator

This apparently causes a slowdown in one of the OSS repositories intended to focus exactly on exclude performance:

Linting SwiftLintPerformanceTests with this PR took 0.23 s vs 0.16 s on main (43% slower).

If we found a way that would roughly align with the numbers from main, it would be great. I'll need some time to think about it further.

@tumata

tumata commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@SimplyDanny I've pushed a different approach for this. Instead of standardizing every path (which stats the filesystem and regressed performance), it just matches the candidate with and without the /private prefix using plain string comparison, so it's back within noise of main while still fixing the exclusion.

Let's wait and see if Danger is happier.

EDIT:
image

Exclusion matchers and prefixes are derived from standardized URLs (via
`String.url()`), which on macOS strips a leading `/private` from paths under
firmlinks such as `/tmp` and `/var`. The directory enumerator, however, yields
file paths that keep the `/private` prefix, so the `FilenameMatcher`/prefix
comparison never matched and excluded files (e.g. generated code) were linted
in CI workspaces and `mktemp` directories.

Compare each candidate against the path both with and without the `/private`
prefix using string operations only, so both sides agree without the per-file
`stat` that standardizing every candidate would incur.
@SimplyDanny
SimplyDanny enabled auto-merge (squash) June 22, 2026 21:05
@SimplyDanny
SimplyDanny merged commit 105980b into realm:main Jun 22, 2026
19 checks passed
@tumata

tumata commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for merging the changes @SimplyDanny. Would you have a target date for patch release?

@SimplyDanny

Copy link
Copy Markdown
Collaborator

Thank you for merging the changes @SimplyDanny. Would you have a target date for patch release?

There you go. Homebrew will be ready in a bit as well.

@tumata

tumata commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Brew finally updated, and I was able to successfully test end to end.
Thank you for your prompt help in getting this PR merged @SimplyDanny! 🙏

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.

excluded paths ignored when project is under /private (e.g. /tmp, mktemp, CI workspaces) — regression in 0.64.0

3 participants