Avoid scanning hidden dependency folders by accident
Also published in our Blogger archive.
Direct answer
Hidden directories can dominate a simple scan even though they are not project source. This example filters exact path components .git and .cache, leaving src/main.py visible. Using Path.parts avoids a substring rule that might discard an unrelated directory whose name merely contains “cache.”
The edge case is an accidental traversal of metadata or tool caches that produces noisy findings and wastes time. The second assertion makes the skipped count visible; an exclusion is part of the scanner’s scope, not an invisible optimization.
The two names are not a complete exclusion policy. Virtual environments, dependency managers, and build outputs may need separately documented entries. Skipping a directory also means the scanner has no evidence about its contents, so a report should not turn that absence into a clean result.
Complete example
from pathlib import Path
paths = [Path(".git/config"), Path(".cache/item"), Path("src/main.py")]
ignored = {".git", ".cache"}
kept = [str(path) for path in paths if not any(part in ignored for part in path.parts)]
assert kept == ["src/main.py"]
assert len(paths) - len(kept) == 2
print("kept=1 hidden_ignored=2")
Expected stdout:
kept=1 hidden_ignored=2
Sources
Prepared with AI assistance. The example uses synthetic data; its stated limits apply.