@boring-stack-pkg/eslint-plugin-elysia

中文文档
0.2.0发布于 2026/09/15MITTypeScriptESM + CJS近 30 天下载 2462

ESLint plugin enforcing architectural, type-safety, lifecycle, and performance patterns for Elysia.js applications.

原始使用文档
文档目录12 节
  1. Why
  2. Install
  3. Usage (flat config)
  4. Rules
  5. route-requires-schema
  6. require-plugin-name
  7. require-hooks-before-routes
  8. no-decorate-state-collision
  9. Design notes
  10. Development
  11. Release
  12. License

eslint-plugin-elysia

npm source

ESLint plugin enforcing architectural, type-safety, lifecycle, and performance patterns in Elysia.js applications.

Why

Elysia is a fluent, chain-based framework whose correctness depends on registration order, plugin naming, schema declaration, and idiomatic context destructuring. Most of those constraints aren't expressible in the type system — a missing schema, an unnamed plugin, a hook registered after a route, or a new Response() returned where Elysia would have serialized natively all type-check fine and silently misbehave at runtime.

This plugin pins those invariants down at lint time.

Install

pnpm add -D @boring-stack-pkg/eslint-plugin-elysia @typescript-eslint/parser

Usage (flat config)

// eslint.config.mjs
import tsParser from "@typescript-eslint/parser";
import elysia from "@boring-stack-pkg/eslint-plugin-elysia";

export default [
  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tsParser,
      parserOptions: { ecmaVersion: "latest", sourceType: "module" },
    },
    plugins: { elysia },
    rules: elysia.configs.recommended.rules,
  },
];

The recommended preset enables all twelve rules at "error". Override individual rules as needed:

rules: {
  ...elysia.configs.recommended.rules,
  "elysia/route-requires-tag": "warn",
  "elysia/prefer-static-services": "off",
  "elysia/no-direct-error-throw": [
    "error",
    { factoryName: "HttpErrors", factoryMethod: "make" }
  ]
}

Rules

RuleCategoryDescription
route-requires-schemaSchemaEvery route must declare at least one of body/query/params/response/headers/cookie.
route-requires-tagConventionEvery route must declare detail.tags for Swagger grouping.
no-direct-error-throwSafety (fixable)Disallow throw new Error(...); use a typed error factory.
portable-schema-typesSafetyIn *.schemas.ts, forbid t.Integer(), t.Tuple() and t.Union(x.map(...)), which the OpenAPI client cannot carry.
consistent-status-via-setConventionInside route handlers, set status via set.status = N, not new Response(body, { status }).
prefer-destructured-contextPerformanceDon't pass the full Elysia Context to controllers/services — destructure at the boundary.
require-plugin-nameLifecycleExported new Elysia(...) instances must declare { name: "..." } for runtime deduplication.
no-separate-model-interfacesConventionDisallow TS interfaces that duplicate a runtime schema's shape; use typeof Schema.static (or equivalent).
prefer-static-servicesPerformanceDon't new Service() inside route handlers when the class is stateless.
require-hooks-before-routesLifecycleGlobal hooks must register before any route on the same instance — Elysia's waterfall is order-sensitive.
prefer-throw-statusConventionInside route handlers, prefer throw status(...) over try/catch building manual responses.
prefer-direct-returnPerformanceReturn values directly; let Elysia serialize. Reserve new Response(...) for streams and custom headers.
no-decorate-state-collisionSafetyDisallow duplicate keys across .decorate() / .state() / .derive() / .resolve() on a single instance.

route-requires-schema

// ❌
new Elysia().post("/users", create);

// ✅
new Elysia().post("/users", create, {
  body: t.Object({ email: t.String() }),
  detail: { tags: ["Users"] },
});

require-plugin-name

// ❌
export const auth = new Elysia();

// ✅
export const auth = new Elysia({ name: "Auth.Plugin" });

require-hooks-before-routes

// ❌  onError will not fire for /health
new Elysia().get("/health", () => "ok").onError(handleError);

// ✅
new Elysia().onError(handleError).get("/health", () => "ok");

no-decorate-state-collision

// ❌  silent overwrite — second decorate("db", ...) wins
new Elysia({ name: "db" }).decorate("db", a).decorate("db", b);

// ✅
new Elysia({ name: "db" }).decorate("db", buildDb()).state("requestId", "");

For the full list of options and ❌/✅ snippets per rule, see docs/rules/.

Design notes

  • AST-only by design. No parserServices / type-checker dependency. Consumers don't need a parserOptions.project setup. Rules degrade gracefully where types could give more info — this is documented per-rule under "Limitations."
  • Family-aligned conventions. Mirrors eslint-plugin-module-boundaries and eslint-plugin-drizzle-conventions: same plugin export shape, same ESLintUtils.RuleCreator factory, same flat-config preset structure, same kebab-case rule ids.
  • Heuristic rules are explicit. Rules that can't be made precise without parser services (prefer-destructured-context, no-separate-model-interfaces, prefer-static-services, prefer-throw-status) document their limits in the rule docs.

Development

pnpm install
pnpm test
pnpm typecheck
pnpm build

Release

Tag a v* version locally and push the tag — .github/workflows/release.yml runs pnpm publish --access public with NPM_TOKEN.

License

MIT.

版本与发布记录

@boring-stack-pkg/eslint-plugin-elysia 共发布 3 个版本,首次发布于 2026/05/20;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.2.0latest2026/09/151 个月前
0.1.22026/05/255 个月前
0.1.12026/05/205 个月前

关于 @boring-stack-pkg/eslint-plugin-elysia 的常见问题

@boring-stack-pkg/eslint-plugin-elysia 是什么?

ESLint plugin enforcing architectural, type-safety, lifecycle, and performance patterns for Elysia.js applications.

如何安装 @boring-stack-pkg/eslint-plugin-elysia?

在项目目录运行 npm install @boring-stack-pkg/eslint-plugin-elysia,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(8.57.0 || ^9.0.0)、typescript(>=5.0.0)、@typescript-eslint/parser(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@boring-stack-pkg/eslint-plugin-elysia 支持 TypeScript 吗?

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

@boring-stack-pkg/eslint-plugin-elysia 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@boring-stack-pkg/eslint-plugin-elysia 需要什么版本的 Node.js?

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

@boring-stack-pkg/eslint-plugin-elysia 可以商用吗?

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

@boring-stack-pkg/eslint-plugin-elysia 的下载量有多少?

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

@boring-stack-pkg/eslint-plugin-elysia 还在维护吗?

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