ignores: a Windows-style, absolute, ./-prefixed or trailing-slash ignores.global entry silently matches nothing
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 56/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
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 内容生成。
描述
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 wholevendortree 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
- Normalise ignore patterns the way include patterns already are (
\→/; strip a leading./; make an absolute pattern under the project root project-relative; expand a baredir/todir/**). One shared helper for both sides. - Report an
ignores.globalentry 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. - A regression test per form in the table above, on Windows-style and POSIX-style paths.
- 主要语言
- TypeScript
- 星标
- 0
- 派生
- 0
- 平均合并
- 38 分钟
- 30 天内合并 PR
- 96
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Rule-Of-Code/RoC 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
Rule-Of-Code/RoC#436 ·
维护者通常 1 天内回复
-
bug
难度 5/5 一周以上 新手友好度 35/100
Rule-Of-Code/RoC#439 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 49/100
Rule-Of-Code/RoC#438 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 53/100
Rule-Of-Code/RoC#437 ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 74/100
Rule-Of-Code/RoC#435 ·
维护者通常 1 天内回复
相似的 Issue
-
ready-for-agent
难度 1/5 1 小时以内 新手友好度 86/100
LucasSantana-Dev/Lucky#3257 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
XiaomiMiMo/MiMo-Code#2849 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
danielmiessler/LifeOS#2894 ·
维护者通常 5 天内回复
-
enhancement frontend good first issue help wanted testing-infrastructure
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
enhancement follow-up
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复