# @bam\.tech/eslint-plugin 中文文档

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

版本：9\.2\.0
npm 元数据更新时间：2026-10-13T12:38:17.118Z
中文译文更新时间：2026-11-07T15:57:30.223Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bam.tech/eslint-plugin
原文对照：https://npmcn.com/package/%40bam.tech/eslint-plugin/?lang=original
项目主页：https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/README.md
源码仓库：https://github.com/bamlab/react-native-project-config

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

- 包体积（解压后）：52.9 kB，14 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>= 18\.0\.0
- 运行依赖：1 个
- peer 依赖：eslint ^9\.37\.0，globals ^16\.0\.0，prettier ^3\.6\.2，typescript-eslint ^8\.19\.1，eslint-plugin-jest ^29\.0\.1，eslint-plugin-react ^7\.37\.5，eslint-plugin-import ^2\.32\.0，eslint-config-prettier ^10\.1\.8，eslint-plugin-prettier ^5\.2\.1，eslint-plugin-react-hooks ^7\.0\.0，eslint-plugin-react-native ^5\.0\.0，eslint-plugin-eslint-plugin ^6\.4\.0，eslint-plugin-unused-imports ^4\.2\.0，eslint-plugin-testing-library ^7\.13\.1，eslint-plugin-react-native-a11y ^3\.5\.1，@typescript-eslint/eslint-plugin ^8\.46\.0，eslint-plugin-simple-import-sort ^12\.1\.1，eslint-import-resolver-typescript ^4\.4\.4
- 首次发布：2023-07-04T15:46:07.101Z
- 最新版本发布：2026-05-12T12:43:43.972Z
- 近 30 天下载量：12934（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 4 个）

## 中文简介

bam 项目的 eslint 插件

## 安装

```sh
npm install @bam.tech/eslint-plugin
```

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

## README

# BAM 的 ESLint 插件

这个工程是一个ESLint插件,它收集所有规则,插件和解析器,在任何新的反应-原生BAM项目中都应该使用.

规则和配置细节列表可见 [`here`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/recommended.js)。 。 。 .

## 快速设置

安装插件及其对等依赖 :

```bash
yarn add @bam.tech/eslint-plugin --dev
npx install-peerdeps @bam.tech/eslint-plugin --dev --yarn
```

#### 遗产配置(ESLint 8.x和以下)

那就更新你的 `.eslintrc` 配置文件 :

```json
// .eslintrc
{
  "extends": "plugin:@bam.tech/recommended",
  "overrides": [
    {
      "files": ["*.test.tsx", "*.test.ts"],
      "extends": "plugin:@bam.tech/tests"
    }
  ]
}
```

#### 平面配置

-   安装插件 : `yarn add -D @bam.tech/eslint-plugin`
-   创建一个 `eslint.config.js` 在工程根中的文件 :

```javascript
const pluginBam = require("@bam.tech/eslint-plugin");

module.exports = [
  ...pluginBam.configs.recommended,
  ...pluginBam.configs.a11y,
  ...pluginBam.configs.import,
  ...pluginBam.configs.tests,
  {
    rules: {
      "@bam.tech/require-named-effect": "error",
    },
  },
];
```

### 在单列上设置插件

更新您的 `.vscode/settings.json` 通过使用插件添加应用程序目录:

```json
// .vscode/settings.json
{
  ...
  "eslint.workingDirectories": [
    "apps/yourFirstApp",
    "apps/yourSecondApp"
    ]
}
```

### 处理被 TypeScript 忽略的文件

插件默认行为是使用TypeScript配置来插入所有TypeScript文件. 然而,在您的项目中,可能会有您选择用 TypeScript 忽略的文件. 最好也禁用ESLint检查这些文件. 要达到此目的, 请将您想要忽略的文件添加到您的 ESLint 的覆盖部分 `eslintrc.js`下面是这方面的一个例子。 模拟文件的配置被覆盖: TypeScript 解析器被删除, 以及该程序的行为 `@typescript-eslint/return-await` 规则被修改.

```javascript
overrides: [
  {
    files: ["mocks/**/*"],
    parserOptions: {
      project: null,
    },
    rules: {
      "@typescript-eslint/return-await": "off",
    },
  },
];
```

### QQ 反应版本

随着React 18的引入,不再需要在你的JSX文件中导入React. ESLint插件被配置为回放版本18及以上,因此不会遇到出错. 然而,TypeScript如果配置不正确,将产生出错. 为了解决这个问题,只需添加 `"jsx": "react-native"` 给您的 `tsconfig.json` 文档.

如果你的项目使用一个低于18的回放版本,iyou应该升级到更新的回放版本. 如果升级不是一个选项, 情况是这样: 在您的 JSX 文件里导入反应仍然是强制性的, 但 ESLint 不会标出任何错误, 尽管它应该。 这是由于插件配置;推荐的配置扩展了插件反应/jsx运行时间,从而禁用以下规则:

-   `'react/jsx-uses-react': "error"`
-   `'react/react-in-jsx-scope': "error"`

这些规则至关重要,因为当反应不在范围时,这些规则会引发错误。 因此,你需要把它们纳入你的.eslintrc.js文件中的规则部分,以确保每当有人省略了输入以反应时都会标出错误.

记住,推荐的解决方案是升级到更新的React版本. 只有在升级不可行的例外情况下,才应无视这一建议.

## 可共享配置

此插件导出多种配置, 可用于您 `.eslintrc` 配置文件 :

| 名称 | 说明 |
| :-- | :-- |
| [`@bam.tech/recommended`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/recommended.js) | 建议的所有项目配置 |
| [`@bam.tech/tests`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/tests.js) | 为测试文件推荐的配置 。 默认情况下, 这适用于每个文件: 放入 `overrides` 在测试文件中过滤. |
| [`@bam.tech/a11y`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/a11y.js) | \[beta\]埃斯林特配置检查无障碍. 仍在β中以不中断已存在的项目,但未来将被合并为所推荐的配置. |

这些配置需要一些同行的依赖性. 您可以用下列方式列出:

```bash
npm info "@bam.tech/esling-plugin" peerDependencies
```

如果您使用 **npm 第5页** 您可以通过运行自动安装:

```bash
npx install-peerdeps @bam.tech/eslint-config -D
```

## 埃斯林特规则

此插件导出一些自定义规则, 您可以在您的工程中选择使用 :

QQ 配置启用 .  
设置在 `recommended` 配置 .  
设置在 `tests` 配置 .  
自动修复 [`--fix` CLI 选项](https://eslint.org/docs/user-guide/command-line-interface#--fix)。 。 。 .

| 名称 | 说明 | 💼 | 🔧 |
| :-- | :-- | :-- | :-- |
| [等待用户事件](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/await-user-event.md) | 执行等待用户Event电话 | 🧪 | 🔧 |
| [无差异播放名](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/no-different-displayname.md) | 执行组件显示Name 以匹配组件名称 | ✅ | 🔧 |
| [无线性](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/no-inline-style.md) | 在 JSX 中检测内线样式 | ✅ |  |
| [偏好用户事件](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/prefer-user-event.md) | 在测试中强制使用用户Event over fireEvent. | 🧪 | 🔧 |
| [需要名称效果](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/require-named-effect.md) | 在使用效果内强制使用命名函数 | ✅ |  |

使用规则,在你的 `.eslintrc`数字 :

```json
// .eslintrc
{
  "plugins": ["@bam.tech"],
  "rules": {
    "@bam.tech/require-named-effect": "error"
  }
}
```

> _提示: 如果您的配置已经从一个 `@bam.tech` 配置, 您不需要声明插件 ._

## 如何定制?

您仍然可以通过在您的配置中添加其他配置、插件和规则来自定义您的 ESLint 配置 `.eslintrc` 配置文件 .

## [贡献](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/CONTRIBUTING.md)

如果你找到一个有用的规则,你觉得BAM的每个项目都应该使用,请随意 [贡献](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/CONTRIBUTING.md)。 。 。 .

## 常见问题

### @bam\.tech/eslint-plugin 是什么？

bam 项目的 eslint 插件

### 如何安装 @bam\.tech/eslint-plugin？

在项目目录运行 npm install @bam\.tech/eslint-plugin，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（^9\.37\.0）、globals（^16\.0\.0）、prettier（^3\.6\.2）、typescript-eslint（^8\.19\.1）、eslint-plugin-jest（^29\.0\.1）、eslint-plugin-react（^7\.37\.5）、eslint-plugin-import（^2\.32\.0）、eslint-config-prettier（^10\.1\.8）、eslint-plugin-prettier（^5\.2\.1）、eslint-plugin-react-hooks（^7\.0\.0）、eslint-plugin-react-native（^5\.0\.0）、eslint-plugin-eslint-plugin（^6\.4\.0）、eslint-plugin-unused-imports（^4\.2\.0）、eslint-plugin-testing-library（^7\.13\.1）、eslint-plugin-react-native-a11y（^3\.5\.1）、@typescript-eslint/eslint-plugin（^8\.46\.0）、eslint-plugin-simple-import-sort（^12\.1\.1）、eslint-import-resolver-typescript（^4\.4\.4）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @bam\.tech/eslint-plugin 支持 TypeScript 吗？

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

### @bam\.tech/eslint-plugin 支持 ESM 还是 CommonJS？

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

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

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

### @bam\.tech/eslint-plugin 可以商用吗？

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

### @bam\.tech/eslint-plugin 的下载量有多少？

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

### @bam\.tech/eslint-plugin 还在维护吗？

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

