feat(cli): add --exclude flag to skip paths from scan and ci#690
Merged
Conversation
New helpers for the --exclude flag: - validateExcludePatterns: normalizes repo-relative prefixes, rejects absolute paths, traversal components, backslashes, null bytes, and patterns longer than 512 chars. - isExcluded: case-sensitive prefix-boundary match (rules matches rules/foo but not rulesx/foo). Also threads ExcludePatterns through ProgressCallbacks into getFiles, applying the filter at the walk layer so excluded paths are never parsed or counted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Registers StringArray flag --exclude on both scan and ci. Reads, validates, and passes the cleaned patterns to graph.Initialize via ProgressCallbacks.ExcludePatterns so excluded paths are skipped at the file-walk layer before parsing begins. Validation runs before any I/O: absolute prefixes, traversal components (..), backslashes, null bytes, and oversized patterns all return a clear error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
Pathfinder Report✅ No security findings on the changed files. This pull request is clean. Powered by Code Pathfinder. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #690 +/- ##
==========================================
+ Coverage 85.43% 85.44% +0.01%
==========================================
Files 187 188 +1
Lines 27278 27333 +55
==========================================
+ Hits 23305 23355 +50
- Misses 3082 3086 +4
- Partials 891 892 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
… path - validateExcludePatterns now silently drops exact duplicates (after normalization) so repeated --exclude flags don't bloat the per-file check; preserves first-occurrence order. Adds three dedup tests. - getFiles dropped its defensive 'filepath.Rel error → relPath = path' branch (unreachable: filepath.Walk guarantees the path is rooted at directory, so Rel never fails). New test covers excluding an individual file (non-directory) so the file-level skip path is exercised. Brings patch coverage on new code to 100%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
--exclude(repeatableStringArray) flag to bothpathfinder scanandpathfinder ci. Each value is a repo-relative path prefix; files whose path starts with any prefix are skipped at the file-walk layer, so they are never parsed or counted.sast-engine/cmd/exclude.gowithvalidateExcludePatterns(normalize + reject dangerous inputs) andisExcluded(prefix-boundary match withrulesmatchingrules/foobut notrulesx/foo).ExcludePatternsthroughgraph.ProgressCallbacksintograph.Initialize/getFiles, so exclusion happens before any I/O or AST work begins.Test plan
exclude_test.go,scan_test.go,ci_test.go,utils_test.gocovering: empty list, single prefix, multiple, nested prefix, exact dir match, boundary semantics (rulesvsrulesx), trailing slash normalization, case sensitivity, unicode...traversal, backslashes, null bytes, length > 512 all return a clear error.go test ./... -count=1passes on all 30 packages (2113 tests total).go vet ./...clean.golangci-lint run ./...clean (v2.9.0).Security notes
Validation rules applied by
validateExcludePatternsbefore any filesystem access:/..path componentGo does not shell-expand these patterns (no
glob, noos/exec), but inputs are rejected anyway to enforce a clean repo-relative contract and prevent confusion.🤖 Generated with Claude Code