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

オープン
#414 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
56/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
backend, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
TypeScript
スター
0
フォーク
0
平均マージ
38分
マージ済み PR(30日)
96

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Rule-Of-Code/RoC のほかの issue

Rule-Of-Code/RoC の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。