Skip to content

feat: gitignore filtering for rule context and respectGitignore frontmatter opt-out#321

Merged
rhuanbarreto merged 7 commits into
mainfrom
feat/respect-gitignore
May 18, 2026
Merged

feat: gitignore filtering for rule context and respectGitignore frontmatter opt-out#321
rhuanbarreto merged 7 commits into
mainfrom
feat/respect-gitignore

Conversation

@rhuanbarreto

@rhuanbarreto rhuanbarreto commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ctx.glob() and ctx.grepFiles() now exclude .gitignored files by default, closing the consistency gap with ctx.scopedFiles which already filtered them
  • New respectGitignore optional boolean field in ADR frontmatter (defaults to true) — set to false to opt out and include gitignored files (e.g., rules that inspect build output)
  • Empty files: [] treated same as omitted — both fall back to scanning all project files
  • Two user-facing warnings emitted from resolveScopedFiles() itself (not just the runner):
    • respectGitignore: false without a files scope — warns about scanning everything including node_modules/
    • Explicit files patterns that match only gitignored files — suggests setting respectGitignore: false

Changed files

Core (3 files):

  • src/formats/adr.ts — Added respectGitignore to AdrFrontmatterSchema
  • src/engine/git-files.tsresolveScopedFiles() accepts { respectGitignore, adrId } options; warnings for misconfigured gitignore settings; empty files array fallback
  • src/engine/runner.ts — Passes trackedFiles to createRuleContext(); ctx.glob() and ctx.grepFiles() filter by tracked files; threads adrId to resolveScopedFiles()

Tests (3 files):

  • tests/engine/git-files.test.ts — 6 new tests: gitignore filtering, opt-out, empty array fallback, both warnings, adrId label
  • tests/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 positives

Docs (10 files, EN + PT-BR):

  • reference/adr-schema.mdx — Added respectGitignore field documentation
  • reference/rule-api.mdx — Added gitignore note to glob() and grepFiles() methods
  • guides/writing-adrs.mdx — Added respectGitignore usage in scoping section
  • guides/writing-rules.mdx — Added gitignore note to ctx.glob() and ctx.grepFiles()
  • concepts/adrs.mdx — Added respectGitignore to frontmatter table

Test plan

  • bun test tests/engine/git-files.test.ts — 14 tests pass
  • bun test tests/engine/runner-gitignore.test.ts — 7 tests pass
  • bun run validate — full pipeline green (845 tests, 27/27 ADR checks, lint, typecheck, format, knip, build)

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

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

View logs

rhuanbarreto and others added 7 commits May 18, 2026 20:54
…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>
@rhuanbarreto rhuanbarreto force-pushed the feat/respect-gitignore branch from ad6913d to f0d6f3c Compare May 18, 2026 18:55
@rhuanbarreto rhuanbarreto changed the title feat: add respectGitignore frontmatter field and gitignore filtering for ctx.glob/ctx.grepFiles feat: gitignore filtering for rule context and respectGitignore frontmatter opt-out May 18, 2026
@rhuanbarreto rhuanbarreto enabled auto-merge (squash) May 18, 2026 18:55
@rhuanbarreto rhuanbarreto disabled auto-merge May 18, 2026 19:04
@rhuanbarreto rhuanbarreto merged commit 97f1ebb into main May 18, 2026
12 of 16 checks passed
@rhuanbarreto rhuanbarreto deleted the feat/respect-gitignore branch May 18, 2026 19:05
@archgatebot archgatebot Bot mentioned this pull request May 18, 2026
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.

1 participant