landmines README

项目的 README,来自 github.com/interfere-inc/landmines。合并为一个 markdown 文件:README.md。

landmines

Oxlint rules that keep AI-written code honest.

Coding agents are fast, and they optimise for green checks. Left alone, they mock the thing under test, sleep until a race usually goes their way, retry the flake, raise the timeout, and narrate the diff in comments. Every one of those passes CI. None of them is true.

landmines makes the honest path the only one that lints. Each rule fails with a message that tells the agent (or the human) what to do instead, so the fix lands in the same loop that tripped it.

Built and used in production at Interfere.

Install

bun add -d oxlint @interfere/landmines

Extend the recommended configuration in .oxlintrc.json:

{
  "extends": ["./node_modules/@interfere/landmines/configs/recommended.json"]
}

Or register only the plugins you want:

{
  "jsPlugins": [
    { "name": "landmines-testing", "specifier": "@interfere/landmines/testing" }
  ],
  "rules": {
    "landmines-testing/no-test-doubles": "error"
  }
}

Requires Oxlint 1.81 or later and Node 22.18 or later.

Rules

landmines-testing

Tests that can't lie.

Rule What it stops
no-test-doubles Replacing dependency behaviour in tests: module mocks, vi.fn(impl), stubbed globals, patched prototypes, hand-written bindings and fake responses. Use the real implementation and MSW for the network. Observation-only spies are allowed.
strict-msw Starting MSW without onUnhandledFrame: "error" (msw 3) or onUnhandledRequest: "error" (msw 2), so unmocked requests reach the network.
no-fixed-sleep Awaiting a fixed real-time delay in a test or hook. Await the operation or a signal it emits.
no-unsignaled-poll expect.poll and vi.waitFor on request recorders and spy state, which race a deadline instead of awaiting an event.
no-flake-masking Test retries and raised timeouts, per test or in Vitest config. A test that passes on rerun is a flake to fix.

no-fixed-sleep, strict-msw and no-flake-masking accept a per-file allowlist with an exact count, so you can adopt them in an existing codebase and ratchet down:

{
  "landmines-testing/no-flake-masking": [
    "error",
    { "allow": { "src/legacy/slow.test.ts": 2 } }
  ]
}

The rule reports when a file has fewer violations than its allowance, so the list only shrinks.

no-fixed-sleep also reports sleeps in callbacks that run while the test waits, such as act(async () => …) or .then(async () => …). Callbacks passed to other calls, like page.route handlers, are left alone. Pass runNow to replace the default callee names (act, waitFor, then, catch, finally, step), matched against a call's function or method name:

{
  "landmines-testing/no-fixed-sleep": [
    "error",
    {
      "runNow": ["act", "waitFor", "then", "catch", "finally", "step", "within"]
    }
  ]
}

landmines-style

Rule What it stops
no-comments Prose comments. Allowed: functional directives (oxlint-disable, @ts-expect-error, /* @__PURE__ */, licence headers…), single-line // WARNING: comments for dangerous recurring footguns (configurable with allow), and TSDoc on exported public API. Rationale belongs in the PR.

Pass publicApi (regular expressions matched against the file path) to allow TSDoc only in your published packages:

{
  "landmines-style/no-comments": ["error", { "publicApi": ["/packages/sdk/"] }]
}

Pass allow to choose which single-line comment prefixes are kept. It defaults to ["WARNING"]; add "SAFETY" to keep the // SAFETY: comments that anti-slop's require-safety-comment-for-type-assertion requires:

{
  "landmines-style/no-comments": ["error", { "allow": ["WARNING", "SAFETY"] }]
}

landmines-structure

Rule What it stops
colocated-tests Tests detached from the implementation they import. Tests live beside their subject or in its local tests/ directory.
test-file-names .spec.ts, .tests.ts, helpers.ts, mocks.ts and friends. Use .test.ts, .fixture.ts and .test-utils.ts.
package-exports Unrestricted source exports such as "./*": "./src/*.ts". Declare explicit entrypoints or named public namespaces in package.json.

landmines-types

Rule What it stops
no-explicit-return-types Annotated return types on implementations. Let them be inferred; pin a contract with satisfies where it matters.

Pairs well with

Contributing

bun install
bun run lint && bun run typecheck && bun run test

Add a changeset with bun changeset for any user-facing change.

License

MIT

landmines (interfere-inc/landmines)

正在搜索数据库…

这是什么?一组 Oxlint 规则(一个 lint 插件),用于阻止 AI 编程代理伪造通过检查的结果:模拟(mock)测试、固定时长的 sleep 等待、自动重试不稳定的测试、调大超时时间,以及复述代码差异的注释。
它是测试运行器还是代码检查工具?都不是。它本身只是一个 Oxlint 插件,Oxlint 会在你现有的代码检查步骤中运行这些规则。规则分为测试、风格、结构和类型四类。
我该如何在项目中启用它?在 .oxlintrc.json 中扩展推荐配置,或只注册你需要的插件,然后照常运行 Oxlint。
我首先需要哪些版本?Oxlint 1.81 或更高版本,以及 Node 22.18 或更高版本。
AI 编程代理为什么需要这些规则?代理会追求通过检查,所以放任不管时,它们会模拟被测代码、睡眠等待以便竞态条件大概率朝有利方向发展、重试不稳定的测试并调大超时时间。这些做法都能让 CI 通过,但结果并不真实。
规则失败时会怎样?错误信息会说明应该怎么改,让代理或人类在同一个循环中直接修复问题,而不是绕过它。
能否把 TSDoc 限制在已发布的包中?可以。publicApi 选项接受与文件路径匹配的正则表达式,因此 TSDoc 只允许在你已发布的包中使用。
大小
0.1 MB
星标
593
时长
21天
提交 · 90 天