JS 边界
破坏你的建筑 不只是你的语法.
一个用于JavaScript和TypeScript项目的ESLint插件. 分类您的文件, 为谁写政策, 并获得一个 ESLint 错误, 当一个边界被越过 。 在你的IDE,在CI, 没有新的运行.
联合国 jsbounders.dev (英语) • 妇女 快开始
安装
npm install --save-dev eslint eslint-plugin-boundaries
如何运作
从文件夹树到三个编辑中执行的架构.
1. 对文件和要素进行分类
元素描述符匹配文件夹 。 文件描述符自己匹配文件,所以文件可以是 component (单位:千美元) test 同时。 你只需要其中之一开始.
settings: {
"boundaries/elements": [
{ type: "helper", pattern: "helpers/*" },
{ type: "component", pattern: "components/*/*" },
{ type: "module", pattern: "modules/*" },
],
"boundaries/files": [
{ pattern: "**/*.spec.js", category: "test" },
],
}
2. 撰写保险单
选择默认, 然后通过元素类型、 文件类别、 模块来源和依赖类型的任何组合允许或不允许 。 抓取的路径碎片让一个政策覆盖整个元素家族.
"boundaries/dependencies": [2, {
default: "disallow",
policies: [
{ from: { element: { type: "component" } },
allow: { to: { element: { type: "helper" } } } },
{ from: { element: { type: "module" } },
allow: { to: { element: { types: ["component", "helper"] } } } },
{ disallow: { to: { file: { categories: "test" } } },
message: "Never import test files from {{ from.element.types.[0] }}s" },
],
}]
3. 读取您写入导入错误
违规是普通的ESLint出错:编辑器出错,CI故障,有两边元素类型的模板化消息. 又有三条规则捕捉到您架构外的文件,未知的依赖性和被忽略的文件.
src/helpers/format/index.js
1:22 error There is no policy allowing dependencies from
elements of type "helper" to elements of type "component"
boundaries/dependencies
✖ 1 problem (1 error, 0 warnings)
这个 快速开始 把这些片段拼凑在一起 eslint.config.js。 。 。 .
软件包
这个存储库拥有JS边界包:
| 软件包 | 说明 |
|---|---|
eslint-plugin-boundaries | ESLint 插件,也作为 @boundaries/eslint-plugin。 。 。 . |
@boundaries/elements | 实体描述符和匹配符 @boundaries 工具. |
@boundaries/config | 规范并验证插件的设置和规则选项,不使用ESLint. |
@boundaries/policies | 评价插件的依赖政策及其信息,不使用ESLint. |
捐款
感谢所有报告问题、建议改进或 输入代码为了参与其中, 打开一个问题,加入 讨论情况 或读取 提供指南。 。 。 .
许可证
麻省理工学院 紫外线