Don't scan sibling files of a concrete @source inside an auto source root - #20406
Don't scan sibling files of a concrete @source inside an auto source root#20406benjamincanac wants to merge 3 commits into
@source inside an auto source root#20406Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe scanner now checks whether automatic directory walks can reach restricted pattern bases. It accounts for default-ignored directories and ancestor 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/oxide/src/scanner/sources.rs (1)
756-793: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider adding a unit test for the non-repository
cwdboundary.The new tests cover the repository case, where
.gitstops the ancestor walk. Thecwdboundary branch inis_ignored_by_gitignore(lines 340-346) is not covered by a unit test for the restricted-pattern path. A test with no.gitmarker and a.gitignoreabove the boundary would pin that behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8a64208f-33ba-4e9e-8a50-2b040de51569
📒 Files selected for processing (3)
CHANGELOG.mdcrates/oxide/src/scanner/sources.rscrates/oxide/tests/scanner.rs
Confidence Score: 4/5The PR is not yet safe to merge because nested re-inclusions can still cause an explicitly sourced file to be omitted. The new nearest-whitelist return can classify a nested source base as reachable even when an outer ignored parent is pruned before the walker can apply the deeper re-inclusion, leaving the previously reported scanning failure outstanding. Files Needing Attention: crates/oxide/src/scanner/sources.rs Reviews (2): Last reviewed commit: "Honor nested `.gitignore` re-includes wh..." | Re-trigger Greptile |
Summary
A concrete file
@sourcethat sits inside an auto detection root scans the file's entire parent directory:With the project root as an auto source, every sibling of
button.tsis scanned and their classes end up in the output. The same directive works correctly when it points outside the root (since #20263).This is the remaining half of #20255.
expand_restricted_patternsskips the*+!<pattern>restriction when the pattern's base is inside an unrestricted root, because everything under that root is walked anyway. But that's not true when the base hides behind a directory the auto walk prunes, likenode_modulesor a git-ignored folder. In that case the pattern's own walk root is the only thing reaching the file, and its ignore rules are just:so all the siblings are walked and included too.
To fix this, an auto root only counts as covering a pattern base when its walk actually reaches it: the path down to the base doesn't cross a default-ignored directory and the base isn't git-ignored. The git-ignored check reuses the ancestor
.gitignorewalk (and cache) that already promotes auto sources to external sources. External roots and**patterns still cover everything under them, and patterns in ordinary subdirectories behave like before, restricting those would hide siblings the auto source should pick up.The
.gitignorewalk now follows git's precedence: the nearest.gitignorewith a definitive answer wins, so a directory re-included by a deeper!dirpattern is not treated as ignored. Because that walk is shared, re-included directory sources also stay auto sources instead of being promoted to external ones.For context, I ran into this in Nuxt UI: we emit per-component
@sourcelines intonode_modules/.nuxt-ui, and the narrowed list produced byte-identical CSS to sourcing the whole directory (nuxt/ui#6731).Test plan
node_modulesand behind a git-ignored directory (both failed before with the sibling's candidates included), and a re-included directory where the siblings must stay.expand_restricted_patterns, including a control for patterns in ordinary covered subdirectories.cargo test --workspacepasses,cargo fmt --checkclean, no new clippy warnings.@tailwindcss/viteon Vite 8 by patching the built oxide binary into a reproduction project: a file@sourceinside the root now only ships that file's classes; whole-directory sources and auto detection are unchanged.🤖 Generated with Claude Code