Skip to content

Fix ignore pattern handling#3

Open
NiveditJain wants to merge 2 commits into
LarsenCundric:mainfrom
NiveditJain:fix-ignore-pattern-handling
Open

Fix ignore pattern handling#3
NiveditJain wants to merge 2 commits into
LarsenCundric:mainfrom
NiveditJain:fix-ignore-pattern-handling

Conversation

@NiveditJain
Copy link
Copy Markdown

Summary

  • fix --ignore glob handling so patterns like ~/.vscode-server/** are parsed safely
  • support absolute paths, scan-root-relative paths, bare directory names, ~, *, ?, and **
  • apply ignore patterns in watch mode as well as normal scans
  • skip ignored child directories before adding them to the traversal queue
  • safely ignore invalid config entries instead of crashing
  • document --ignore usage and config support in the README
  • preserve root-project bloat detection when running dev-purge inside a project

Why this is needed

I run dev-purge from a cron job, so ignore rules need to be reliable and non-interactive-safe. If an ignore pattern from CLI/config is malformed, unsupported, or interpreted too narrowly, the scheduled cleanup can either scan paths that should be excluded or fail unexpectedly. This makes folder exclusion predictable for automated runs.

Ignore examples now supported

dev-purge --ignore node_modules
dev-purge --ignore ./legacy-app
dev-purge --ignore '~/Library/Caches/**'

Config file:

{
  ignore: [~/.vscode-server/**, ./vendor]
}

Checks

  • node --check src/scanner.js
  • node --check src/index.js
  • fixture-tested no ignore, absolute glob, relative dir, relative exact path, relative glob, bare directory name, and relative scan root argument
  • verified npm start -- --dry-run --depth 0 -s 0 --ignore node_modules excludes root node_modules

NiveditJain and others added 2 commits May 5, 2026 11:33
Adds a repeatable --ignore CLI option and support for ~/.config/dev-purge/config.json with an ignore array. Patterns are glob-like (supports ~ and **). Scanner respects ignore patterns when discovering projects and bloat dirs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@LarsenCundric
Copy link
Copy Markdown
Owner

Nice fix, ship after one tweak. Notes:

P1 — getFlagValues skips values starting with - (src/index.js:45)
--ignore -tmp is silently dropped and --ignore --legacy swallows the next flag. The single-value getFlagValue doesn't do this — should be consistent. Either accept any next token, or only skip when the next token is in flagsWithValues.

P2 — Move config read inside run()
Top-level await readFile(cfgPath, ...) runs before any flag parsing. If XDG_CONFIG_HOME points at a slow/hung mount, --help hangs. Defer to runtime.

P2 — Guard empty pattern after expandHome
Add if (!expanded) return null; so a stray ~ that expands to "" (rare embedded envs) can't become an accidental match.

P3 — Warn on invalid config entries
cfg.ignore = ["~/.cache", 42] silently drops the 42. For cron-driven use you wanted predictable behavior — a console.warn on rejected patterns helps debug bad configs.

P3 — Note case-sensitivity in README
Bare-name matcher is case-sensitive, which is correct but surprising on macOS HFS+. One-line README note.

Nice catches in this PR

  • **/-prefix glob handling is correct (consumes a path segment, not just chars)
  • The trailing ** "base regex" so foo/** also matches foo — thoughtful
  • The bundled bugfix for root-of-project bloat (canCollectBloatAtDir) is a real fix

LGTM after P1.

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