Skip to content

feat: add --ignore-ext and --only-ext flags for extension filtering#13

Open
ericzakariasson wants to merge 4 commits into
mainfrom
feat/ignore-extensions
Open

feat: add --ignore-ext and --only-ext flags for extension filtering#13
ericzakariasson wants to merge 4 commits into
mainfrom
feat/ignore-extensions

Conversation

@ericzakariasson

@ericzakariasson ericzakariasson commented Feb 26, 2026

Copy link
Copy Markdown
Owner

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-ext and --only-ext flags (comma-delimited) and persisted config fields (ignored_extensions, only_extensions).

Applies these filters during scanning (downloads/large/old) through a new Config::should_skip_extension helper 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

ericzakariasson and others added 3 commits February 25, 2026 17:05
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
Comment thread src/cli.rs
@ericzakariasson

Copy link
Copy Markdown
Owner Author

@cursor push f9c9592

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_extension to trim surrounding whitespace before stripping leading dots and lowercasing, and added a test covering spaced extension inputs.
  • ✅ Fixed: Extension filtering inconsistently applied across file scanners
    • I added config.should_skip_extension(path) filtering in the duplicates scanner so --ignore-ext and --only-ext are consistently enforced there.

Create PR

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('.') {
You can send follow-ups to this agent here.

Comment thread src/config.rs

fn normalize_extension(ext: &str) -> String {
ext.trim_start_matches('.').to_lowercase()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

// Skip based on extension filters
if config.should_skip_extension(path) {
continue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Additional Locations (2)

Fix in Cursor Fix in Web

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.

2 participants