# @boundaries/eslint-plugin 中文文档

规范地址：https://npmcn.com/package/%40boundaries/eslint-plugin/

版本：7\.4\.2
npm 元数据更新时间：2026-11-05T11:50:25.110Z
中文译文更新时间：2026-11-08T12:32:57.952Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40boundaries/eslint-plugin
原文对照：https://npmcn.com/package/%40boundaries/eslint-plugin/?lang=original
项目主页：https://www.jsboundaries.dev/
源码仓库：https://github.com/javierbrea/eslint-plugin-boundaries

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：118 kB，69 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.18
- 运行依赖：6 个
- peer 依赖：eslint \>=6\.0\.0
- 首次发布：2025-11-10T10:15:55.616Z
- 最新版本发布：2026-11-05T11:50:24.914Z
- 近 30 天下载量：104827（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 23 个）

## 中文简介

Eslint 插件检查元素之间的架构边界

## 安装

```sh
npm install @boundaries/eslint-plugin
```

也可以使用：`pnpm add @boundaries/eslint-plugin`、`yarn add @boundaries/eslint-plugin`、`bun add @boundaries/eslint-plugin`

## README

[![License](https://img.shields.io/npm/l/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/blob/master/LICENSE) [![Build status](https://github.com/javierbrea/eslint-plugin-boundaries/actions/workflows/build.yml/badge.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/actions?query=workflow%3Abuild+branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/javierbrea/eslint-plugin-boundaries/badge.svg)](https://coveralls.io/github/javierbrea/eslint-plugin-boundaries) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=javierbrea_eslint-plugin-boundaries&metric=alert_status)](https://sonarcloud.io/dashboard?id=javierbrea_eslint-plugin-boundaries)

[![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-boundaries.svg)](https://www.npmjs.com/package/eslint-plugin-boundaries) [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/) [![Last commit](https://img.shields.io/github/last-commit/javierbrea/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/commits) [![Last release](https://img.shields.io/github/release-date/javierbrea/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/releases)

# JS 边界

**破坏你的建筑 不只是你的语法.**

一个用于JavaScript和TypeScript项目的ESLint插件. 分类您的文件, 为谁写政策, 并获得一个 ESLint 错误, 当一个边界被越过 。 在你的IDE,在CI, 没有新的运行.

**联合国 [jsbounders.dev (英语)](https://www.jsboundaries.dev/)** • 妇女 [快开始](https://www.jsboundaries.dev/docs/quick-start/)

## 安装

```bash
npm install --save-dev eslint eslint-plugin-boundaries
```

## 如何运作

从文件夹树到三个编辑中执行的架构.

### 1\. 对文件和要素进行分类

元素描述符匹配文件夹 。 文件描述符自己匹配文件,所以文件可以是 `component` (单位:千美元) `test` 同时。 你只需要其中之一开始.

```js
settings: {
  "boundaries/elements": [
    { type: "helper",    pattern: "helpers/*" },
    { type: "component", pattern: "components/*/*" },
    { type: "module",    pattern: "modules/*" },
  ],
  "boundaries/files": [
    { pattern: "**/*.spec.js", category: "test" },
  ],
}
```

### 2\. 撰写保险单

选择默认, 然后通过元素类型、 文件类别、 模块来源和依赖类型的任何组合允许或不允许 。 抓取的路径碎片让一个政策覆盖整个元素家族.

```js
"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故障,有两边元素类型的模板化消息. 又有三条规则捕捉到您架构外的文件,未知的依赖性和被忽略的文件.

```text
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)
```

这个 [快速开始](https://www.jsboundaries.dev/docs/quick-start/) 把这些片段拼凑在一起 `eslint.config.js`。 。 。 .

## 软件包

这个存储库拥有JS边界包:

| 软件包 | 说明 |
| --- | --- |
| [`eslint-plugin-boundaries`](https://www.jsboundaries.dev/) | ESLint 插件,也作为 `@boundaries/eslint-plugin`。 。 。 . |
| [`@boundaries/elements`](https://github.com/javierbrea/eslint-plugin-boundaries/tree/master/packages/elements#readme) | 实体描述符和匹配符 `@boundaries` 工具. |
| [`@boundaries/config`](https://github.com/javierbrea/eslint-plugin-boundaries/tree/master/packages/config#readme) | 规范并验证插件的设置和规则选项,不使用ESLint. |
| [`@boundaries/policies`](https://github.com/javierbrea/eslint-plugin-boundaries/tree/master/packages/policies#readme) | 评价插件的依赖政策及其信息,不使用ESLint. |

## 捐款

感谢所有报告问题、建议改进或 [输入代码](https://github.com/javierbrea/eslint-plugin-boundaries/graphs/contributors)为了参与其中, [打开一个问题](https://github.com/javierbrea/eslint-plugin-boundaries/issues),加入 [讨论情况](https://github.com/javierbrea/eslint-plugin-boundaries/discussions) 或读取 [提供指南](https://github.com/javierbrea/eslint-plugin-boundaries/blob/master/.github/CONTRIBUTING.md)。 。 。 .

## 许可证

麻省理工学院 [紫外线](https://github.com/javierbrea)

## 常见问题

### @boundaries/eslint-plugin 是什么？

Eslint 插件检查元素之间的架构边界

### 如何安装 @boundaries/eslint-plugin？

在项目目录运行 npm install @boundaries/eslint-plugin，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（\>=6\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @boundaries/eslint-plugin 支持 TypeScript 吗？

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

### @boundaries/eslint-plugin 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @boundaries/eslint-plugin 需要什么版本的 Node\.js？

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

### @boundaries/eslint-plugin 可以商用吗？

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

### @boundaries/eslint-plugin 的下载量有多少？

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

### @boundaries/eslint-plugin 还在维护吗？

最新版本 7\.4\.2 发布于 2026/11/05（3 天前）；至今共发布 23 个版本，其中过去 12 个月发布了 23 个；首次发布于 2025/11/10。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

