feat: gitignore filtering for rule context and respectGitignore frontmatter opt-out#321
Merged
Conversation
Deploying archgate-cli with
|
| Latest commit: |
f0d6f3c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b872efbf.archgate-cli.pages.dev |
| Branch Preview URL: | https://feat-respect-gitignore.archgate-cli.pages.dev |
…g for ctx.glob/ctx.grepFiles Close the gitignore filtering gap in the rule context: `ctx.glob()` and `ctx.grepFiles()` now exclude `.gitignore`d files by default, matching the existing behavior of `ctx.scopedFiles`. Add `respectGitignore` boolean field to ADR frontmatter schema to allow opting out when rules need to inspect ignored files (e.g., build output). Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
An empty `files: []` in ADR frontmatter now falls back to `["**/*"]` (scan all files), matching the behavior of omitting `files` entirely. Previously, an empty array yielded zero scoped files. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Emit a logWarn when an ADR sets respectGitignore: false but has no files patterns, since the fallback to **/* will scan everything on disk including node_modules/, .git/, etc. and may be very slow. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
When an ADR specifies explicit files patterns but scopedFiles resolves to zero results, do a second unfiltered scan. If files exist on disk but were all excluded by .gitignore, warn the user to set respectGitignore: false. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Extract gitignore-related runner tests into runner-gitignore.test.ts to stay under the 500-line max-lines lint rule. Add 3 new tests covering: - warns when respectGitignore is false without files scope - warns when file patterns match only gitignored files - does not warn when file patterns match tracked files Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
The warnings for misconfigured respectGitignore now live in resolveScopedFiles itself, so any caller gets them — not just runChecks. Add optional adrId to options for contextual warning messages. Add direct resolveScopedFiles tests for both warnings and the adrId label. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
ad6913d to
f0d6f3c
Compare
Merged
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
ctx.glob()andctx.grepFiles()now exclude.gitignored files by default, closing the consistency gap withctx.scopedFileswhich already filtered themrespectGitignoreoptional boolean field in ADR frontmatter (defaults totrue) — set tofalseto opt out and include gitignored files (e.g., rules that inspect build output)files: []treated same as omitted — both fall back to scanning all project filesresolveScopedFiles()itself (not just the runner):respectGitignore: falsewithout afilesscope — warns about scanning everything includingnode_modules/filespatterns that match only gitignored files — suggests settingrespectGitignore: falseChanged files
Core (3 files):
src/formats/adr.ts— AddedrespectGitignoretoAdrFrontmatterSchemasrc/engine/git-files.ts—resolveScopedFiles()accepts{ respectGitignore, adrId }options; warnings for misconfigured gitignore settings; emptyfilesarray fallbacksrc/engine/runner.ts— PassestrackedFilestocreateRuleContext();ctx.glob()andctx.grepFiles()filter by tracked files; threadsadrIdtoresolveScopedFiles()Tests (3 files):
tests/engine/git-files.test.ts— 6 new tests: gitignore filtering, opt-out, empty array fallback, both warnings, adrId labeltests/engine/runner.test.ts— Cleaned up (gitignore tests extracted)tests/engine/runner-gitignore.test.ts— 7 tests:ctx.glob()/ctx.grepFiles()gitignore behavior, warning coverage, no false positivesDocs (10 files, EN + PT-BR):
reference/adr-schema.mdx— AddedrespectGitignorefield documentationreference/rule-api.mdx— Added gitignore note toglob()andgrepFiles()methodsguides/writing-adrs.mdx— AddedrespectGitignoreusage in scoping sectionguides/writing-rules.mdx— Added gitignore note toctx.glob()andctx.grepFiles()concepts/adrs.mdx— AddedrespectGitignoreto frontmatter tableTest plan
bun test tests/engine/git-files.test.ts— 14 tests passbun test tests/engine/runner-gitignore.test.ts— 7 tests passbun run validate— full pipeline green (845 tests, 27/27 ADR checks, lint, typecheck, format, knip, build)