@helfy / helfy-lint
当前版本: 0.2.0. 看到 发布说明.
ESLint规则和一个漂亮的插件 Helfy 应用程序。规则强制执行
层模型: @Store 拥有状态, @Service 基础设施有用吗? @UseCase 协调两者, @View
呈现。
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,
},
];
| 规则 | 在 recommended |
|---|---|
helfy/store/no-inject ——不 @inject / @useCtx / @useForm 在 @Store | 错误 |
helfy/store/no-ctor-params - - - - - - @Store 有一个空构造函数 | 错误 |
helfy/store/no-effect ——不 @effect 在 @Store | 错误 |
helfy/store/computed-only-on-getter - - - - - - @computed 只在getter上 | 错误 |
helfy/store/no-http-calls -没有HTTP,存储或定时器I/O @Store | 错误 |
helfy/service/no-state, no-computed, no-effect -没有反应性 @Service | 错误 |
helfy/service/no-field-inject -通过构造函数的依赖关系 | 错误 |
helfy/use-case/no-reactive-decorators ——不 @state / @computed / @effect 在 @UseCase | 错误 |
helfy/use-case/no-field-inject -通过构造函数的依赖关系 | 错误 |
helfy/layers/no-store-imports-service, no-store-imports-use-case, no-service-imports-use-case | 错误 |
helfy/view/no-ctor-di - - - - - - @View 的依赖项 @inject,而不是构造函数 | 错误 |
helfy/context/no-ctor-di - - - - - - @Context / @Form 构造函数只接受道具 | 错误 |
helfy/view/no-destructure-props -在跟踪方法之外解构props,并在字段初始化器中直接创建props快照 | 警告 |
helfy/decorators/no-ref-state ——不 @ref 一起 @state 在一个领域 | 错误 |
helfy/decorators/synchronous-effect -没有异步或发电机 @effect 方法 | 警告 |
helfy/imports/no-deep-helfy-imports ——不 @helfy/helfy/dist/... | 错误 |
helfy/imports/no-unknown-helfy-subpath -仅记录 @helfy/helfy/* 条目 | 错误 |
Decorator检查从Helfy解析命名的导入别名和命名空间导入,尊重词法遮蔽, 并且忽略从其他库导入的装饰器。当没有本地的 绑定的存在。不解析通过应用程序桶的再导出。
层和存储HTTP导入检查还包括导出的类和类表达式。层分类 仍然使用导入路径和名称,而不是TypeScript依赖关系图。公共子路径检查包括 带有字符串字面值的动态导入。
view/no-destructure-props 允许直接在同步内部解构 @effect 方法和 @computed
getter,用于跟踪读取。它警告直接字段快照,例如 title = this.props.title;
使用getter或 @computed 代替。它不跟踪别名或执行数据流分析。
@useForm 上下文注入(它委托给 @useCtx),也禁止在Service和UseCase字段上使用。
效果运行时跟踪同步读取并忽略方法返回值。开始前阅读依赖项
Async工作并显式处理承诺拒绝。 synchronous-effect 检查声明的async/generator方法;
它不推断普通方法返回的承诺。
类型检查的层依赖关系
对于具有 tsconfig.json,使用可选预设:
export default [
{
files: ["src/**/*.ts"],
...helfy.configs["recommended-type-checked"],
languageOptions: {
parser: tsParser,
parserOptions: { projectService: true },
},
},
];
这个预设取代了三个启发式 layers/* 规则与 helfy/layers/no-invalid-dependencies (error)。
它使用TypeScript符号标识来检测Store→Service/UseCase和Service→UseCase导入,包括
别名、默认导出、类表达式、重新导出桶和访问的命名空间成员。类型只进口
被允许;名称如 ThingService 单独不能决定一个类的层。包含层类的文件
作为一个整体进行检查,就像启发式规则一样。
类型化规则检查静态值导入和名称空间成员访问,而不是动态导入或传递
依赖图。它需要解析器服务(projectService: true 或者 project: "./tsconfig.json"); 事实并非如此
由普通启用 recommended 预设。TypeScript是一个对等依赖。其他装饰器规则保留
如上所述的本地导入解析。
构建时检查
@helfy/helfy/compiler/helfy-ts-loader 已经在永远无效的规则上构建失败(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); 这个包是不需要的。ESLint仍然是编辑器和
CI诊断。
Context/Form构造函数、同步效果和类型化依赖检查只支持eslint。构建时检查
解析当前文件中的本地导入别名、命名空间导入和词法遮蔽;它们不加载
一个TypeScript项目或遵循再导出桶。深度进口检查包括再出口和文字 import().
编译器测试将编译失败规则目录、消息和代表性诊断与ESLint进行比较。
更漂亮的 .hf
语义 .hf 支票属于 helfy-check 在language-server包中,而不是ESLint。在这个
库运行 npm run check:templates 在安装该包的依赖项之后。它检查语法和
使用编辑器的虚拟文档进行键入,并为错误返回失败的退出代码。看到
CI设置和CLI选项.
// prettier.config.cjs
module.exports = {
plugins: [require.resolve("@helfy/helfy-lint/prettier")],
overrides: [{ files: "*.hf", options: { parser: "helfy-hf" } }],
};
格式器是Helfy语言服务器使用的格式器。有语法错误的文件将保持原样。
路线图
今后的检测工作和重点: 路线图.
许可证
麻省理工学院