@boundaries/eslint-plugin

中文文档
7.4.2发布于 2026/11/05MITTypeScriptCommonJS近 30 天下载 10.5万

Eslint plugin checking architecture boundaries between elements

原始使用文档
文档目录8 节
  1. Installation
  2. How it works
  3. 1. Classify files and elements
  4. 2. Write the policies
  5. 3. Read the error where you wrote the import
  6. Packages
  7. Contributing
  8. License

License Build status Coverage Status Quality Gate

NPM downloads Renovate Last commit Last release

JS Boundaries

Lint your architecture, not just your syntax.

An ESLint plugin for JavaScript and TypeScript projects. Classify your files, write policies for who may depend on whom, and get an ESLint error the moment a boundary is crossed. In your IDE, in CI, with nothing new to run.

Documentation: jsboundaries.dev · Quick start

Installation

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

How it works

From folder tree to enforced architecture in three edits.

1. Classify files and elements

Element descriptors match folders. File descriptors match files on their own, so a file can be a component and a test at the same time. You only need one of the two to start.

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

2. Write the policies

Pick a default, then allow or disallow by any combination of element type, file category, module origin and dependency kind. Captured path fragments let one policy cover a whole family of elements.

"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. Read the error where you wrote the import

Violations are ordinary ESLint errors: editor squiggles, CI failures, templated messages with the element types on both sides. Three more rules catch files outside your architecture, unknown dependencies and ignored ones.

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)

The quick start puts these pieces together in a complete eslint.config.js.

Packages

This repository holds the packages of JS Boundaries:

PackageDescription
eslint-plugin-boundariesThe ESLint plugin, also published as @boundaries/eslint-plugin.
@boundaries/elementsEntity descriptors and matchers for @boundaries tools.
@boundaries/configNormalization and validation of the settings and rule options of the plugin, without ESLint.
@boundaries/policiesEvaluation of the dependency policies of the plugin and their messages, without ESLint.

Contributing

Thank you to everyone who has reported issues, suggested improvements or contributed code. To get involved, open an issue, join the discussions or read the contributing guidelines.

License

MIT © javierbrea

版本与发布记录

@boundaries/eslint-plugin 共发布 23 个版本,首次发布于 2025/11/10;过去 12 个月发布了 23 个版本。

版本发布日期距今
7.4.2latest2026/11/053 天前
7.4.12026/11/026 天前
7.4.02026/10/2711 天前
7.3.02026/10/2415 天前
7.2.12026/10/2118 天前
7.2.02026/08/102 个月前

其他发布通道:beta → 7.0.0-beta.2。

关于 @boundaries/eslint-plugin 的常见问题

@boundaries/eslint-plugin 是什么?

Eslint plugin checking architecture boundaries between elements

如何安装 @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 和提交记录判断。