@alxwlw/repo-rules

中文文档
1.9.2发布于 2026/11/04MITES Module零依赖构建来源已验证近 30 天下载 2462

Whole-repo lint rules from the alxwlw defect corpus — long files, unjustified suppressions, skipped/focused tests, Number(x) || , removed assertions — with a shrink-only baseline.

原始使用文档
文档目录5 节
  1. Rules
  2. Baseline
  3. Configuration
  4. Limits
  5. CI

@alxwlw/repo-rules

Whole-repository checks that came out of a defect corpus: each one is a class of defect that already cost a review round. They run in CI and locally, on Node ≥ 20, with no dependencies.

pnpm add -D @alxwlw/repo-rules
pnpm exec repo-rules baseline --init   # once: record what is already there
pnpm exec repo-rules check             # every run: nothing new, nothing stale
pnpm exec repo-rules diff --base origin/main
repo-rules [-C <dir>] check [--json]
repo-rules [-C <dir>] diff [--base <ref>] [--json]
repo-rules [-C <dir>] baseline [--init] [--allow-grow]

-C <dir> runs in that directory (any place inside the repository). --json prints { violations, stale, notes } instead of text lines. --help prints the usage; a missing or unknown command prints it on stderr and exits 2.

Rules

RuleFlags
max-linesa tracked text file over 800 lines (plans, lockfiles, JSON, snapshots, generated and vendored files excluded)
suppression-reasoneslint-disable* / oxlint-disable* / solhint-disable* without -- reason; @ts-expect-error / @ts-ignore without trailing text; biome-ignore without text after :; Python # noqa / # type: ignore without -- reason
focused-skipped-testsin JS/TS test files: .only( on any line (the scan is line-based, see Limits); .skip( / .todo( / xit( / xdescribe( / xtest( without a -- reason comment on the line or the comment line above. .skipIf / .runIf and Playwright's test.skip(condition, reason) are fine
number-or-defaultin non-test JS/TS files: Number(…), Number.parseInt(…), Number.parseFloat(…), parseInt(…), parseFloat(…) followed by || <non-zero literal>: a real 0 silently becomes the default
removed-assertions (diff)a test file whose diff removes more expect( / assert… than it adds; an assertion inside a comment counts as neither removed nor added (comments recognised: //, /* … */ on the line, a line starting with *; # in Python; an unclosed /* and a line starting with * hide the rest of the line, including code after a */). exclude (* or removed-assertions) applies. A Tests-Removed: <reason> commit trailer in the range accepts it

A reason is at least three non-space characters.

Baseline

.repo-rules-baseline.json records the violations that already exist: line count per long file, hit count per file for the other rules. check fails when a file goes over its entry, and also when an entry is higher than reality (stale), so a fixed place cannot be reused by a new one. baseline only lowers entries; raising one takes --allow-grow, which shows in the PR diff.

Configuration

Optional .repo-rules.json:

{
    "maxLines": 800,
    "exclude": { "*": ["public/vendor/**"], "max-lines": ["docs/*.html"] },
    "testGlobs": [
        "**/*.{test,spec}.*",
        "**/__tests__/**",
        "**/test/**",
        "**/tests/**",
        "**/*.t.sol",
        "**/test_*.py",
        "**/*_test.py"
    ]
}

testGlobs replaces the default list, shown in full above; it does not add to it. exclude takes * or a rule name — the four rules above and removed-assertions.

Limits

  • Comments are found by a line heuristic, not a parser: a quote inside a regex literal or JSX text can hide a directive later on that line.
  • <!-- --> comments in .vue and .svelte files are not read.
  • number-or-default misses || .5, and a ||= default applied to a variable that holds a Number(…) result.
  • removed-assertions does not see a test disabled by a rename with no content change (for example a.test.ts → a.test.ts.off).
  • removed-assertions reads a line inside a multi-line /* … */ block that does not start with * (for example a re-indented one) as code.
  • Assertions moved into a helper count as removed; the Tests-Removed trailer is the way out.
  • The scan is line-based and does not know whether a line sits inside a string or a template literal, so .only( or .skip( inside a fixture string is flagged.

CI

- uses: actions/checkout@v5
  with:
    fetch-depth: 0 # diff needs the merge-base
- run: pnpm exec repo-rules check
- run: pnpm exec repo-rules diff # base = origin/$GITHUB_BASE_REF in a pull_request job, skipped otherwise

Exit codes: 0 clean, 1 violations or stale baseline, 2 error (never read as clean).

版本与发布记录

@alxwlw/repo-rules 共发布 10 个版本,首次发布于 2026/10/12;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.2latest2026/11/043 天前
1.9.12026/11/035 天前
1.9.02026/10/299 天前
1.8.02026/10/2612 天前
1.7.12026/10/2216 天前
1.7.02026/10/2216 天前

其他发布通道:bootstrap → 0.0.0-bootstrap.0。

关于 @alxwlw/repo-rules 的常见问题

@alxwlw/repo-rules 是什么?

Whole-repo lint rules from the alxwlw defect corpus — long files, unjustified suppressions, skipped/focused tests, Number(x) || , removed assertions — with a shrink-only baseline.

如何安装 @alxwlw/repo-rules?

在项目目录运行 npm install @alxwlw/repo-rules,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 repo-rules,可以用 npx repo-rules 直接运行。

@alxwlw/repo-rules 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/alxwlw__repo-rules 是否存在。

@alxwlw/repo-rules 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alxwlw/repo-rules 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alxwlw/repo-rules 可以商用吗?

@alxwlw/repo-rules 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alxwlw/repo-rules 的下载量有多少?

根据 npm 官方下载统计,@alxwlw/repo-rules 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,462 次,日均约 82 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alxwlw/repo-rules 还在维护吗?

最新版本 1.9.2 发布于 2026/11/04(3 天前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/10/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。