@gem-sdk/eslint-plugin

中文文档
0.1.0发布于 2026/10/15MITTypeScriptCommonJS零依赖近 30 天下载 2599

Shared ESLint rules for GemPages frontend repos (React + Vue)

原始使用文档
文档目录11 节
  1. Installation
  2. Usage
  3. React projects
  4. Vue projects
  5. All repos (architecture + i18n only)
  6. Manual rule selection
  7. What each config enables
  8. no-import-from-package-path options
  9. no-self-module-barrel-import
  10. no-clickable-div
  11. require-monitoring-capture options

@gem-sdk/eslint-plugin

Shared ESLint rules for all GemPages frontend repositories.

Consolidates every custom rule from web-builder-shopify-app, web-builder, and web-builder-elements into a single publishable npm package. The architecture rules support both React (.tsx) and Vue (.vue) files.

The package name is @gem-sdk/eslint-plugin, so its ESLint plugin prefix is @gem-sdk (scoped packages drop the eslint-plugin- segment). Reference rules as @gem-sdk/<rule> and shareable configs as plugin:@gem-sdk/<config>.

Installation

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

Usage

Choose the config that matches your tech stack:

React projects

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

Vue projects

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

All repos (architecture + i18n only)

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

Manual rule selection

{
  "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"
  }
}

What each config enables

Rulerecommendedvuereact
module-structureerrorerrorerror
no-module-barrelerrorerrorerror
module-import-boundaryerrorerrorerror
pure-ui-layererrorerrorerror
module-index-requirederrorerrorerror
no-self-module-barrel-importerrorerrorerror
no-t-for-variableerrorerrorerror
no-clickable-divwarnwarnwarn
not-use-store-to-refs—error—
not-use-custom-color-class—warn—
no-export-type-from-component—error—
no-export-type-from-tsx——error
no-import-from-package-path——error
no-multiple-component-exports——error
require-monitoring-capture——warn

vue and react both extend recommended. Vue configs require vue-eslint-parser.

no-export-type-from-component and no-export-type-from-tsx enforce the same thing (no export type/export interface from a component file) — the former also matches .vue files, the latter is React-only. They're kept separate so each config only reports once per file.

no-import-from-package-path options

Deep-path imports can be exempted with the ignore option, which accepts exact import paths or path prefixes:

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

Any import path that matches an entry exactly, or starts with an entry followed by /, is allowed.

no-self-module-barrel-import

Files inside modules/<name>/ must not import their own module through the ~//@/ alias — it mixes entry points across sibling files and creates circular dependencies through the barrel. Use relative paths within a module.

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

no-clickable-div

Click handlers on non-interactive elements (div, span, section, li, or a without href) require tabIndex plus a keydown/keyup handler, otherwise keyboard users can't reach them. Applies to JSX and, under vue-eslint-parser, Vue templates. Elements with spread attributes are skipped.

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

require-monitoring-capture options

Inline react-query onError handlers must call a capture function so failures reach Sentry; handlers passed as identifiers are assumed to capture. Both patterns are configurable:

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

hookPattern matches the hook name (default ^use(Query|Queries|InfiniteQuery|Mutation)$); capturePattern matches the called function or method name, case-insensitively (default capture).

版本与发布记录

@gem-sdk/eslint-plugin 共发布 7 个版本,首次发布于 2026/06/23;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.1.0latest2026/10/151 个月前
0.0.72026/07/233 个月前
0.0.62026/07/233 个月前
0.0.42026/07/024 个月前
0.0.32026/06/234 个月前
0.0.22026/06/234 个月前

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

@gem-sdk/eslint-plugin 是什么?

Shared ESLint rules for GemPages frontend repos (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 和提交记录判断。