ignores: a Windows-style, absolute, ./-prefixed or trailing-slash ignores.global entry silently matches nothing

Aperta
#414 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, testing

Direzione di ricerca

Start in src/utils/file-filter-utils.ts, especially FileFilterUtils.shouldIgnoreFile and the include pattern handling around the lines shown in the issue. Compare how ignore and include patterns are normalized, then inspect the existing tests for file filtering and audit output. Done means the listed path forms behave as expected and regression tests cover them; the suggested unmatched-entry warning adds additional audit behavior to consider.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Version: 7.29.1 (npm latest, 5fc54afe). The same code is on develop (efee761).
Area: ignores.global matching (FileFilterUtils.shouldIgnoreFile, src/utils/file-filter-utils.ts)

What happens

An ignores.global entry written as a Windows path, an absolute path, with a ./ prefix or with a trailing slash matches nothing, and RoC says nothing about it. The files it was meant to exclude are still judged. The same forms work in includes.global.

// src/utils/file-filter-utils.ts (7.29.1 = develop)
189    filePath = filePath.replace(/\\/g, '/');           // the PATH is normalised …
193    const ignorePath = FileFilterUtils.projectRelative(filePath);
205      if (minimatch(ignorePath, pattern)) {             // … the PATTERN is used raw

326      const pattern = rawPattern.replace(/\\/g, '/');   // includes: the pattern IS normalised,
327      return pattern.includes('*') ? [pattern] : [pattern, `${pattern.replace(/\/$/, '')}/**`];  // and a bare dir expands to its tree

minimatch reads \ in a pattern as an escape, so vendor\** can never match vendor/lib.js. An absolute pattern never matches the project-relative path it is compared with. ./vendor/** and vendor/ do not match vendor/lib.js either. The include side handles exactly these forms: it normalises slashes and expands a bare directory. The ignore side does neither.

The config validator does not catch it, by its own documented limit: "It validates only keys under laws.severity / laws.notApplicable / laws.enabled; a typo in any other config section (thresholds, ignores, project) is not checked."

Reproduction

One synthetic project: package.json (no test setup), src/app.ts, src/util/helper.ts and nine other source files, plus vendor/lib.js. It is committed to git and audited with ruleofcode audit --mode full --json, once per ruleofcode.config.json. Windows 11, Node 24.16. The observable is Test Coverage Constitutional Standard, which counts the source files it judges ("N source files lack corresponding test files").

ignores.global source files judged vendor/lib.js excluded?
none 11 —
["vendor/**"] 10 yes
["**/vendor/**"] 10 yes
["./vendor/**"] 11 no
["vendor/"] 11 no
["vendor\\**"] (Windows separator) 11 no
["vendor\\lib.js"] 11 no
["<absolute project path>/vendor/**"] 11 no
["<absolute project path with backslashes>\\vendor\\**"] 11 no
["VENDOR/**"] 11 no (case; see below)

For comparison: includes.global: ["src\\**"] gives the same result as ["src/**"], because the include side normalises it.

The runs were also instrumented. A preload records every minimatch(path, pattern) call made from ruleofcode/dist:

  • vendor/**: 54 matches out of 2890 calls. They come through the directory probe ${dirPath}/test.ts (vendor/test.ts, line 225), so the whole vendor tree is skipped.
  • vendor\**, ./vendor/**, vendor/ and both absolute forms: 0 matches out of 2924 calls each.

No warning is printed on stdout or stderr.

What I ruled out

  • Not a cache effect: the cache was deleted before every run.
  • Not the project type or the law selection: 77 laws ran in every variant, and only the ignore entry differs.
  • The other laws that change between variants (Absolute Zero Tolerance Doctrine, Code Documentation Standards) change only because the absolute project path differs between the fixture folders. That path is part of their messages.
  • VENDOR/**: matching is case-sensitive on both the include and the ignore side. On a case-insensitive file system this may surprise people, but I am not claiming it is a defect.
  • Measured only on Windows. On Linux and macOS the absolute and ./ cases should behave the same, because the code path does not depend on the OS. The backslash case is Windows-specific in practice. Not measured there.

Why it matters

An ignore that does nothing is invisible. The user believes vendored or generated code is excluded, and the audit keeps judging it (or reporting it) with no hint that the entry is dead. The opposite mistake is already handled: an empty or non-matching laws.enabled allowlist refuses to report compliance. A dead ignore entry gets no such treatment.

This also matters for the glob 10 → 14 / minimatch 9 → 11 upgrade (#21). Today's ignore results depend on how minimatch treats \ and ./ in patterns, so the upgrade should be measured against a fixed, explicit normalisation rather than whatever the library happens to do.

Suggested direction

  1. Normalise ignore patterns the way include patterns already are (\ → /; strip a leading ./; make an absolute pattern under the project root project-relative; expand a bare dir/ to dir/**). One shared helper for both sides.
  2. Report an ignores.global entry that matched no file during the run as a warning in the audit output ("ignores.global 'vendor\**' matched nothing — check the separator"), in the spirit of the dead-waiver notice.
  3. A regression test per form in the table above, on Windows-style and POSIX-style paths.
Lingua principale
TypeScript
Stelle
0
Fork
0
Merge medio
38m
PR unite (30g)
96

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Rule-Of-Code/RoC

Tutte le issue di Rule-Of-Code/RoC

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.