@aurelienbbn/oxlint-plugin-cloudflare

中文文档
0.1.2发布于 2026/10/14MITTypeScriptES Module构建来源已验证近 30 天下载 2069

Custom oxlint rules for Cloudflare Workers, Durable Objects, and Workflows.

原始使用文档
文档目录3 节
  1. What fires
  2. Registered contract inventory
  3. Credited concepts

@aurelienbbn/oxlint-plugin-cloudflare

npm downloads CI license node

7 oxlint rules for Cloudflare Workers, Durable Objects, and Workflows: bugs that type-check and pass wrangler deploy, then fail under real traffic.

[!NOTE] Release candidate. No consumer has calibrated it yet.

pnpm add -D @aurelienbbn/oxlint-plugin-cloudflare oxlint   # oxlint >=1.82.0 <2.0.0
{
  "jsPlugins": ["@aurelienbbn/oxlint-plugin-cloudflare"],
  "rules": {
    "cloudflare/no-module-scope-request-state": "error",
    "cloudflare/no-interpolated-sql": "error",
    "cloudflare/workflow-deterministic-steps": "error",
    "cloudflare/no-detached-execution-context-method": "error",
    "cloudflare/durable-object-init-concurrency": "error",
    "cloudflare/mysql2-disable-eval": "error",
    "cloudflare/timing-safe-secret-compare": "error"
  }
}

No preset. One autofix: mysql2-disable-eval adds disableEval: true to an options object literal; every other rule reports only.

What fires

const client = new Client(env.HYPERDRIVE.connectionString); // ❌ no-module-scope-request-state
export default {
  async fetch(request, env, ctx) {
    const { waitUntil } = ctx; // ❌ no-detached-execution-context-method: throws "Illegal invocation"
    await env.DB.prepare(`SELECT * FROM users WHERE id = ${id}`).first(); // ❌ no-interpolated-sql
    await env.DB.prepare("SELECT * FROM users WHERE id = ?").bind(id).first(); // ✅
  },
};

class Sync extends WorkflowEntrypoint {
  async run(event, step) {
    await step.do(`sync ${Date.now()}`, async () => {}); // ❌ workflow-deterministic-steps: never replays from cache
    const id = await step.do("make id", async () => crypto.randomUUID()); // ✅
  }
}
Exact triggers and scope per rule
Rule❌ Fires onMatched / ⏭️ skipped
no-module-scope-request-statea TCP client built at module scope (pg Client/Pool, postgres(), mysql2 createConnection/createPool/createPoolCluster, drizzle from node-postgres/postgres-js/mysql2); a module-scope variable assigned, updated, deleted from, or mutated by push/set/add/... inside any functionWorker modules only: importing cloudflare:workers, or default-exporting a handler object. ⏭️ class fields (Durable Object instance state), Drizzle D1/HTTP drivers, Prisma (safety depends on the adapter), helper modules that aren't Worker modules
no-interpolated-sqla template literal or + concatenation with a runtime value as the SQL of env.X.prepare / env.X.exec (also this.env, c.env, a const db = env.X alias) or <x>.sql.exec / sql.exec; a const holding such SQL⏭️ interpolated literals and const literals (table names), tagged templates such as this.sql`...`
workflow-deterministic-stepsDate.now(), Math.random(), performance.now(), crypto.randomUUID(), crypto.getRandomValues(), argument-less new Date() in a step.do / sleep / sleepUntil / waitForEvent name, or anywhere in run() outside a step.do callbackrun(event, step) of a class extending WorkflowEntrypoint from cloudflare:workers. ⏭️ Promise.race / Promise.any (not checked), steps passed to helper functions
no-detached-execution-context-methodwaitUntil / passThroughOnException destructured (including in parameters), or read without a call and stored, passed, returned, or placed in an object/array⏭️ .bind(ctx), .call(ctx), optional calls, truthiness checks, the standalone waitUntil export of cloudflare:workers
durable-object-init-concurrencyin a DurableObject constructor: fetch, async storage.get/put/list/delete/transaction/alarm calls, an async IIFE, or this.<asyncMethod>(), outside a callback; inside any blockConcurrencyWhile callback: fetch or an I/O method on an env binding⏭️ synchronous storage.sql.exec and storage.kv, callbacks that run later. env.MY_DO.get(id) inside the callback is reported although it only builds a stub
mysql2-disable-evalan options object literal for mysql2 createConnection / createPool / createPoolCluster without disableEval, or with a value other than literal trueWorker modules, or options reading env.X (not process.env). ⏭️ options with spreads, options passed by identifier or URI. Fix inserts disableEval: true only when the property is absent
timing-safe-secret-compare=== / !== / == / != where one side is, or is a template embedding, env.<NAME> with NAME matching SECRET, TOKEN, PASSWORD, PASSPHRASE, API_KEY, PRIVATE_KEY, SIGNING_KEY, SIGNATURE, CREDENTIAL⏭️ comparisons with undefined, null, "", typeof; process.env
Not shipped, and who owns it
ConcernOwner
unawaited promises, RPC calls, and stepstyped typescript/no-floating-promises in the strict preset
stale or hand-written Env typeswrangler types --check; a hand-written Env has no sound syntactic trigger
Date.now() in alarms❌ no rule: setAlarm(Date.now() + n) is the correct idiom
product choice (KV vs D1 vs DO, Queues vs Workflows)Cloudflare's workers-best-practices and durable-objects skills
raw SQL outside Cloudflare receiverseslint-plugin-sql no-unsafe-query

Credit: every rule independently implements guidance from Cloudflare's developer documentation (Workers best practices, Rules of Durable Objects, Rules of Workflows, D1, Durable Object SQLite storage, Hyperdrive driver pages); no documentation text or code copied.

Registered contract inventory

Generated from package exports by pnpm catalog. Rule-specific options and limitations are described above and in the source tests.

Rule/checkTrigger or review scope
durable-object-init-concurrencyRequire async work in a DurableObject constructor (storage reads, fetch, async methods or IIFEs) to run inside ctx.blockConcurrencyWhile(), and forbid fetch or binding calls inside a blockConcurrencyWhile() callback.
mysql2-disable-evalRequire disableEval: true in object-literal options passed to mysql2 createConnection / createPool / createPoolCluster in Worker code.
no-detached-execution-context-methodForbid destructuring waitUntil / passThroughOnException from an execution context, or passing, storing, or returning them without their receiver.
no-interpolated-sqlForbid template-literal interpolation or string concatenation of runtime values into SQL passed to D1 prepare()/exec() or Durable Object sql.exec(); bind parameters instead.
no-module-scope-request-stateForbid per-request state at Worker module scope: TCP database clients (pg, postgres, mysql2, their Drizzle drivers) built at module scope, and module-scope variables assigned or mutated from inside a function.
timing-safe-secret-compareForbid ===, !==, == and != comparisons against secret-named env values (SECRET, TOKEN, PASSWORD, API_KEY, SIGNATURE, ...); compare with crypto.subtle.timingSafeEqual().
workflow-deterministic-stepsForbid Date.now(), Math.random(), performance.now(), crypto.randomUUID(), crypto.getRandomValues() and new Date() in Workflow step names, or anywhere in WorkflowEntrypoint.run() outside a step.do() callback.

Credited concepts

版本与发布记录

@aurelienbbn/oxlint-plugin-cloudflare 共发布 3 个版本,首次发布于 2026/09/25;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.2latest2026/10/1424 天前
0.1.12026/09/251 个月前
0.1.02026/09/251 个月前

关于 @aurelienbbn/oxlint-plugin-cloudflare 的常见问题

@aurelienbbn/oxlint-plugin-cloudflare 是什么?

Custom oxlint rules for Cloudflare Workers, Durable Objects, and Workflows.

如何安装 @aurelienbbn/oxlint-plugin-cloudflare?

在项目目录运行 npm install @aurelienbbn/oxlint-plugin-cloudflare,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:oxlint(>=1.82.0 <2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aurelienbbn/oxlint-plugin-cloudflare 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aurelienbbn/oxlint-plugin-cloudflare 支持 ESM 还是 CommonJS?

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

@aurelienbbn/oxlint-plugin-cloudflare 需要什么版本的 Node.js?

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

@aurelienbbn/oxlint-plugin-cloudflare 可以商用吗?

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

@aurelienbbn/oxlint-plugin-cloudflare 的下载量有多少?

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

@aurelienbbn/oxlint-plugin-cloudflare 还在维护吗?

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