# @gem-sdk/eslint-plugin 中文文档

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

版本：0\.1\.0
npm 元数据更新时间：2026-10-15T06:42:19.640Z
中文译文更新时间：2026-11-16T02:20:55.547Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40gem-sdk/eslint-plugin
原文对照：https://npmcn.com/package/%40gem-sdk/eslint-plugin/?lang=original

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

- 包体积（解压后）：71.5 kB，56 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22
- 运行依赖：0 个
- peer 依赖：eslint \>=8\.0\.0
- 首次发布：2026-06-23T07:49:41.803Z
- 最新版本发布：2026-10-15T06:42:19.297Z
- 近 30 天下载量：2599（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 7 个）

## 中文简介

用于 GemPages 前端重置的共享 ESLint 规则 (React + Vue)

## 安装

```sh
npm install @gem-sdk/eslint-plugin
```

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

## README

# @gem-sdk/eslint-plugin (英语)

共享所有 GemPages 前端寄存器的 ESLint 规则 .

合并自定义规则 `web-builder-shopify-app`, (中文(简体) ), `web-builder`,以及 `web-builder-elements` 输入一个可公布 npm 包。 建筑规则支持两种反应(`.tsx`)和Vue (中文(简体) )`.vue`)档案.

> 软件包名称是 `@gem-sdk/eslint-plugin`,因此其 ESLint 插件前缀为 **`@gem-sdk`** (扫描包放下) `eslint-plugin-` 分节)。 参考规则作为 `@gem-sdk/<rule>` 可共享配置为 `plugin:@gem-sdk/<config>`。 。 。 .

## 安装

```bash
yarn add -D @gem-sdk/eslint-plugin
```

## 使用量

选择匹配您的技术堆栈的配置 :

### 反应项目

```json
{
  "extends": ["plugin:@gem-sdk/react"]
}
```

### Vue 项目

```json
{
  "extends": ["plugin:@gem-sdk/vue"]
}
```

### 全部重置( 仅重置 + i18n)

```json
{
  "extends": ["plugin:@gem-sdk/recommended"]
}
```

### 手动规则选择

```json
{
  "plugins": ["@gem-sdk"],
  "rules": {
    "@gem-sdk/module-structure": "error",
    "@gem-sdk/no-module-barrel": "error",
    "@gem-sdk/module-import-boundary": "error",
    "@gem-sdk/pure-ui-layer": "error",
    "@gem-sdk/module-index-required": "error",
    "@gem-sdk/no-self-module-barrel-import": "error",
    "@gem-sdk/no-t-for-variable": "error",
    "@gem-sdk/no-clickable-div": "warn",
    "@gem-sdk/require-monitoring-capture": "warn",
    "@gem-sdk/not-use-store-to-refs": "error",
    "@gem-sdk/not-use-custom-color-class": "warn",
    "@gem-sdk/no-export-type-from-component": "error",
    "@gem-sdk/no-export-type-from-tsx": "error",
    "@gem-sdk/no-import-from-package-path": "error",
    "@gem-sdk/no-multiple-component-exports": "error"
  }
}
```

## 每个配置都允许

| 规则 | `recommended` | `vue` | `react` |
| --- | :-: | :-: | :-: |
| `module-structure` | 错误 | 错误 | 错误 |
| `no-module-barrel` | 错误 | 错误 | 错误 |
| `module-import-boundary` | 错误 | 错误 | 错误 |
| `pure-ui-layer` | 错误 | 错误 | 错误 |
| `module-index-required` | 错误 | 错误 | 错误 |
| `no-self-module-barrel-import` | 错误 | 错误 | 错误 |
| `no-t-for-variable` | 错误 | 错误 | 错误 |
| `no-clickable-div` | 警告( e) | 警告( e) | 警告( e) |
| `not-use-store-to-refs` | —— 说 | 错误 | —— 说 |
| `not-use-custom-color-class` | —— 说 | 警告( e) | —— 说 |
| `no-export-type-from-component` | —— 说 | 错误 | —— 说 |
| `no-export-type-from-tsx` | —— 说 | —— 说 | 错误 |
| `no-import-from-package-path` | —— 说 | —— 说 | 错误 |
| `no-multiple-component-exports` | —— 说 | —— 说 | 错误 |
| `require-monitoring-capture` | —— 说 | —— 说 | 警告( e) |

`vue` 财务报告和审定财务报表 `react` 两者均延 `recommended`. 需要配置 `vue-eslint-parser`。 。 。 .

`no-export-type-from-component` 财务报告和审定财务报表 `no-export-type-from-tsx` 执行同一事项( 无) `export type`编号 :`export interface` 从组件文件)——前者也匹配 `.vue` 文件,后者是只反应。 他们被分开 所以每个配置 每个文件只报告一次.

### `no-import-from-package-path` 选项

深道进口可豁免 `ignore` 选项,它接受精确的导入路径或路径前缀:

```json
{
  "rules": {
    "@gem-sdk/no-import-from-package-path": [
      "error",
      { "ignore": ["@gem-sdk/components/internal/Button"] }
    ]
  }
}
```

任何完全匹配条目的导入路径,或从条目开始,然后 `/`,允许.

### `no-self-module-barrel-import`

内部文件 `modules/<name>/` 不得通过 `~/`编号 :`@/` 别名——它混合了跨兄弟会文件的切入点,并通过管子产生循环依赖. 在一个模块内使用相对路径.

```ts
// app/modules/onboarding/components/Step.tsx
import { useOnboardingStore } from '~/modules/onboarding'; // ✗
import { useOnboardingStore } from '../stores/onboarding'; // ✓
```

### `no-clickable-div`

点击非交互元素上的处理器( E)`div`, (中文(简体) ), `span`, (中文(简体) ), `section`, (中文(简体) ), `li`,或 `a` 无 `href`要求 `tabIndex` 加一个 `keydown`编号 :`keyup` 处理器,否则键盘用户无法到达它们. 适用于JSX,以及 `vue-eslint-parser`, Vue 模板。 有分布属性的元素被跳过 .

```tsx
<div onClick={onViewDemo} />                                        // ✗
<button onClick={onViewDemo} />                                     // ✓
<div role="button" tabIndex={0} onClick={go} onKeyDown={go} />      // ✓
```

### `require-monitoring-capture` 选项

内置反应- 平滑 `onError` 处理器必须调用一个抓取函数,这样故障会到达哨兵;处理器会随着识别符的假设而通过. 两种模式都是可配置的:

```json
{
  "rules": {
    "@gem-sdk/require-monitoring-capture": [
      "warn",
      { "hookPattern": "^use(Query|Mutation)$", "capturePattern": "capture|reportError" }
    ]
  }
}
```

`hookPattern` 匹配钩头名称( 默认) `^use(Query|Queries|InfiniteQuery|Mutation)$`(三); `capturePattern` 匹配名为函数或方法名称, 不区分大小写( 默认) `capture`) (中文(简体) ).

## 常见问题

### @gem-sdk/eslint-plugin 是什么？

用于 GemPages 前端重置的共享 ESLint 规则 \(React \+ Vue\)

### 如何安装 @gem-sdk/eslint-plugin？

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

### @gem-sdk/eslint-plugin 支持 TypeScript 吗？

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

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

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

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

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

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

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

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

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

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

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

