feat: add --ignore-ext and --only-ext flags for extension filtering#13
feat: add --ignore-ext and --only-ext flags for extension filtering#13ericzakariasson wants to merge 4 commits into
Conversation
Adds two new CLI options for filtering scan results by file extension: - --ignore-ext: exclude files with specified extensions - --only-ext: only include files with specified extensions Both accept comma-separated values (e.g. --ignore-ext dmg,iso,pkg). Integrates with large files, old files, and downloads scanners. Also supports configuration via config.toml fields. Made-with: Cursor
Applied via @cursor push command
Applied via @cursor push command
Applied via @cursor push command
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Missing whitespace trim causes silent filter failures
- I updated
normalize_extensionto trim surrounding whitespace before stripping leading dots and lowercasing, and added a test covering spaced extension inputs.
- I updated
- ✅ Fixed: Extension filtering inconsistently applied across file scanners
- I added
config.should_skip_extension(path)filtering in the duplicates scanner so--ignore-extand--only-extare consistently enforced there.
- I added
Or push these changes by commenting:
@cursor push d9db976547
Preview (d9db976547)
diff --git a/src/config.rs b/src/config.rs
--- a/src/config.rs
+++ b/src/config.rs
@@ -348,7 +348,7 @@
}
fn normalize_extension(ext: &str) -> String {
- ext.trim_start_matches('.').to_lowercase()
+ ext.trim().trim_start_matches('.').to_lowercase()
}
#[cfg(test)]
@@ -373,6 +373,12 @@
}
#[test]
+ fn test_normalize_extension_trims_whitespace() {
+ assert_eq!(normalize_extension(" iso"), "iso");
+ assert_eq!(normalize_extension(" .DMG "), "dmg");
+ }
+
+ #[test]
fn test_is_excluded_plain_pattern() {
let mut config = Config::default();
config.excluded_paths = vec![".local/share/cursor-agent".to_string()];
diff --git a/src/scanner/duplicates.rs b/src/scanner/duplicates.rs
--- a/src/scanner/duplicates.rs
+++ b/src/scanner/duplicates.rs
@@ -102,6 +102,11 @@
continue;
}
+ // Skip based on extension filters
+ if config.should_skip_extension(path) {
+ continue;
+ }
+
// Skip hidden files
if let Some(name) = path.file_name() {
if name.to_string_lossy().starts_with('.') {|
|
||
| fn normalize_extension(ext: &str) -> String { | ||
| ext.trim_start_matches('.').to_lowercase() | ||
| } |
There was a problem hiding this comment.
Missing whitespace trim causes silent filter failures
Medium Severity · Logic Bug
normalize_extension only strips leading dots but doesn't trim whitespace. With clap's value_delimiter = ',', input like --ignore-ext "dmg, iso, pkg" produces ["dmg", " iso", " pkg"]. The leading space in " iso" survives normalization, so it never matches path.extension() which returns "iso" (no space). Extensions after the first one silently fail to filter. Adding .trim() before the dot-strip would fix this.
| // Skip based on extension filters | ||
| if config.should_skip_extension(path) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Extension filtering inconsistently applied across file scanners
Low Severity · Logic Bug
should_skip_extension is applied to downloads, large files, and old files scanners, but not to the duplicates scanner — which also iterates individual files. A user running duster scan --all --only-ext dmg would still see duplicate results for non-.dmg files, contradicting the documented behavior of "only include files with these extensions."



Note
Medium Risk
Changes scan inclusion/exclusion behavior across multiple scanners and affects scan caching keys; incorrect normalization or filter interaction could silently hide files from results.
Overview
Adds extension-based filtering to the CLI and config via new
--ignore-extand--only-extflags (comma-delimited) and persisted config fields (ignored_extensions,only_extensions).Applies these filters during scanning (downloads/large/old) through a new
Config::should_skip_extensionhelper and updates scan-cache fingerprinting so cached results are invalidated when extension filters change, while normalizing configured/CLI extensions for consistent matching.Written by Cursor Bugbot for commit 150f89e. This will update automatically on new commits. Configure here.
Made with Cursor