@helfy/helfy-lint

中文文档
0.2.0发布于 2026/11/01MITTypeScriptESM + CJS零依赖

Architecture and standard-decorator ESLint rules plus a Prettier formatter for Helfy .hf templates

原始使用文档
文档目录6 节
  1. ESLint
  2. Type-checked layer dependencies
  3. Build-time checks
  4. Prettier for .hf
  5. Roadmap
  6. License

@helfy/helfy-lint

Current release: 0.2.0. See release notes.

ESLint rules and a Prettier plugin for Helfy apps. The rules enforce the layer model: @Store holds state, @Service does infrastructure work, @UseCase orchestrates both, @View renders.

npm install -D @helfy/helfy-lint eslint @typescript-eslint/parser

ESLint

// eslint.config.mjs
import helfy from "@helfy/helfy-lint";
import tsParser from "@typescript-eslint/parser";

export default [
  {
    files: ["src/**/*.ts"],
    languageOptions: { parser: tsParser },
    ...helfy.configs.recommended,
  },
];
RuleIn recommended
helfy/store/no-inject — no @inject / @useCtx / @useForm on @Storeerror
helfy/store/no-ctor-params — @Store has an empty constructorerror
helfy/store/no-effect — no @effect on @Storeerror
helfy/store/computed-only-on-getter — @computed only on getterserror
helfy/store/no-http-calls — no HTTP, storage or timer I/O in @Storeerror
helfy/service/no-state, no-computed, no-effect — no reactivity in @Serviceerror
helfy/service/no-field-inject — dependencies through the constructorerror
helfy/use-case/no-reactive-decorators — no @state / @computed / @effect in @UseCaseerror
helfy/use-case/no-field-inject — dependencies through the constructorerror
helfy/layers/no-store-imports-service, no-store-imports-use-case, no-service-imports-use-caseerror
helfy/view/no-ctor-di — @View takes dependencies with @inject, not the constructorerror
helfy/context/no-ctor-di — @Context / @Form constructors receive props onlyerror
helfy/view/no-destructure-props — props destructuring outside tracked methods and direct prop snapshots in field initializerswarn
helfy/decorators/no-ref-state — no @ref together with @state on one fielderror
helfy/decorators/synchronous-effect — no async or generator @effect methodswarn
helfy/imports/no-deep-helfy-imports — no @helfy/helfy/dist/...error
helfy/imports/no-unknown-helfy-subpath — only documented @helfy/helfy/* entrieserror

Decorator checks resolve named import aliases and namespace imports from Helfy, respect lexical shadowing, and ignore decorators imported from other libraries. Bare decorator names remain supported when no local binding exists. Re-exports through application barrels are not resolved.

Layer and Store HTTP import checks also cover exported classes and class expressions. Layer classification still uses import paths and names rather than a TypeScript dependency graph. Public-subpath checks include dynamic imports with string literals.

view/no-destructure-props allows destructuring directly inside synchronous @effect methods and @computed getters, where reads are tracked. It warns about direct field snapshots such as title = this.props.title; use a getter or @computed instead. It does not follow aliases or perform data-flow analysis.

@useForm is context injection (it delegates to @useCtx) and is also forbidden on Service and UseCase fields. The effect runtime tracks synchronous reads and ignores method return values. Read dependencies before starting async work and handle promise rejection explicitly. synchronous-effect checks declared async/generator methods; it does not infer promises returned by ordinary methods.

Type-checked layer dependencies

For projects with a tsconfig.json, use the optional preset:

export default [
  {
    files: ["src/**/*.ts"],
    ...helfy.configs["recommended-type-checked"],
    languageOptions: {
      parser: tsParser,
      parserOptions: { projectService: true },
    },
  },
];

This preset replaces the three heuristic layers/* rules with helfy/layers/no-invalid-dependencies (error). It uses TypeScript symbol identities to detect Store → Service/UseCase and Service → UseCase imports, including aliases, default exports, class expressions, re-export barrels and accessed namespace members. Type-only imports are allowed; names such as ThingService alone do not determine a class's layer. A file containing a layer class is checked as a whole, as with the heuristic rules.

The typed rule checks static value imports and namespace member accesses, not dynamic imports or a transitive dependency graph. It requires parser services (projectService: true or project: "./tsconfig.json"); it is not enabled by the ordinary recommended preset. TypeScript is a peer dependency. Other decorator rules keep the local import resolution described above.

Build-time checks

@helfy/helfy/compiler/helfy-ts-loader already fails the build on the rules that are never valid (store/no-inject, store/no-effect, store/no-ctor-params, service/no-state, service/no-computed, service/no-effect, service/no-field-inject, use-case/no-reactive-decorators, use-case/no-field-inject, decorators/no-ref-state, imports/no-deep-helfy-imports); this package is not needed for that. ESLint remains the single source for editor and CI diagnostics.

The Context/Form constructor, synchronous-effect and typed dependency checks are ESLint-only. Build-time checks resolve local import aliases, namespace imports and lexical shadowing within the current file; they do not load a TypeScript project or follow re-export barrels. Deep import checks include re-exports and literal import(). Compiler tests compare the compile-fail rule catalog, messages and representative diagnostics with ESLint.

Prettier for .hf

Semantic .hf checks belong to helfy-check in the language-server package, rather than ESLint. In this repository run npm run check:templates after installing that package's dependencies. It checks syntax and types using the editor's virtual documents and returns a failing exit code for errors. See the CI setup and CLI options.

// prettier.config.cjs
module.exports = {
  plugins: [require.resolve("@helfy/helfy-lint/prettier")],
  overrides: [{ files: "*.hf", options: { parser: "helfy-hf" } }],
};

The formatter is the one the Helfy language server uses. A file with syntax errors is left as is.

Roadmap

Future linting work and priorities: roadmap.

License

MIT

版本与发布记录

@helfy/helfy-lint 共发布 4 个版本,首次发布于 2026/10/27;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.2.0latest2026/11/012 天前
0.1.12026/10/277 天前
0.1.02026/10/277 天前
0.0.0-stage2026/10/277 天前

关于 @helfy/helfy-lint 的常见问题

@helfy/helfy-lint 是什么?

架构和标准装饰器ESLint规则加上Helfy的更漂亮的格式化器。高频模板

如何安装 @helfy/helfy-lint?

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

@helfy/helfy-lint 支持 TypeScript 吗?

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

@helfy/helfy-lint 支持 ESM 还是 CommonJS?

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

@helfy/helfy-lint 需要什么版本的 Node.js?

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

@helfy/helfy-lint 可以商用吗?

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

@helfy/helfy-lint 还在维护吗?

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