# @ericcornelissen/eslint-plugin-top 中文文档

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

版本：3\.6\.4
npm 元数据更新时间：2026-09-06T21:40:33.312Z
中文译文更新时间：2026-11-13T20:54:30.315Z
软件包许可：ISC

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

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

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

- 包体积（解压后）：62 kB，15 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：18\.x \|\| 20\.x \|\| 22\.x \|\| 24\.x \|\| 26\.x
- 运行依赖：0 个
- peer 依赖：eslint 8\.x \|\| 9\.x \|\| 10\.x
- 首次发布：2022-09-23T11:34:14.362Z
- 最新版本发布：2026-09-06T21:40:33.023Z
- 近 30 天下载量：121922（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：39（近 12 个月 4 个）

## 中文简介

在文件的顶端消除副作用

## 安装

```sh
npm install @ericcornelissen/eslint-plugin-top
```

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

## README

# 埃斯林特- 插座顶端

在文件的顶层消除副作用.

**快速链接**数字 : [无](https://www.npmjs.com/package/@ericcornelissen/eslint-plugin-top) | [源代码](https://github.com/ericcornelissen/eslint-plugin-top) | [许可证](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/LICENSE) | [更改日志](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/CHANGELOG.md) | [警卫](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/SECURITY.md)

## 安装

安装 `eslint-plugin-top`页:1 [ESLint 语录](https://eslint.org/) 如果它还没有安装:

```shell
npm install @ericcornelissen/eslint-plugin-top eslint --save-dev
```

## 使用量

### 新建配置( 自 ESLint v9)

从 `@ericcornelissen/eslint-plugin-top` 并使用其中的一种 [预设 配置](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/#readme-preset-configurations),例如:

```javascript
import top from '@ericcornelissen/eslint-plugin-top';

export default [
  top.configs.recommended,
  // or
  top.configs.strict
  // ...
];
```

或配置规则部分中要使用的规则, 例如 :

```javascript
import top from '@ericcornelissen/eslint-plugin-top';

export default [
  {
    plugins: {top},
    rules: {
      'top/no-top-level-side-effects': 'error',
      'top/no-top-level-state': 'error',
      'top/no-top-level-variables': 'error'
    }
  }
];
```

注意规则前缀(`top` 在示例中)必须匹配密钥的名称 用于插件对象.

### 遗产配置( 在ESLint v9 之前)

第一,添加 `@ericcornelissen/top` 到您的插件区 `.eslintrc` 配置文件 。 你必须省略 `eslint-plugin-` 字符串 :

```yml
plugins:
  - '@ericcornelissen/top'
```

然后,配置规则部分中要使用的规则 :

```yml
rules:
  '@ericcornelissen/top/no-top-level-side-effects': error
  '@ericcornelissen/top/no-top-level-state': error
  '@ericcornelissen/top/no-top-level-variables': error
```

## 支持的规则

-   [`no-top-level-side-effects`](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/docs/rules/no-top-level-side-effects.md)
-   [`no-top-level-state`](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/docs/rules/no-top-level-state.md)
-   [`no-top-level-variables`](https://npmcn.com/package/%40ericcornelissen/eslint-plugin-top/docs/rules/no-top-level-variables.md)

## 预设配置

-   `recommended`: 不允许顶级变量,同时允许可变值和 不允许顶级副作用, 除了创建类似的东西 `Symbol`编号.
-   `strict`: 不允许所有顶级变量和副作用,但 导入其他文件 .

* * *

请 [打开一个问题](https://github.com/ericcornelissen/eslint-plugin-top/issues/new?labels=documentation&template=documentation.md) 如果你发现一个错误 或者如果你有建议 如何改进文件.

## 常见问题

### @ericcornelissen/eslint-plugin-top 是什么？

在文件的顶端消除副作用

### 如何安装 @ericcornelissen/eslint-plugin-top？

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

### @ericcornelissen/eslint-plugin-top 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/ericcornelissen\_\_eslint-plugin-top 是否存在。

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

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

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

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

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

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

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

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

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

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

