# @1password/eslint-config 中文文档

规范地址：https://npmcn.com/package/%401password/eslint-config/

版本：9\.2\.0
npm 元数据更新时间：2026-06-10T19:27:59.823Z
中文译文更新时间：2026-11-06T09:06:55.322Z
软件包许可：ISC

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

原始 npm 页面：https://www.npmjs.com/package/%401password/eslint-config
原文对照：https://npmcn.com/package/%401password/eslint-config/?lang=original
项目主页：https://github.com/agilebits-inc/web-foundations#readme
源码仓库：https://github.com/agilebits-inc/web-foundations

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

- 包体积（解压后）：50.2 kB，20 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：8 个
- peer 依赖：eslint ^9\.7，typescript ^5\.9\.3
- 首次发布：2023-04-21T18:42:30.898Z
- 最新版本发布：2026-06-10T19:27:59.682Z
- 近 30 天下载量：3666（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：57（近 12 个月 3 个）

## 中文简介

1Password共享的ESLint配置.

## 安装

```sh
npm install @1password/eslint-config
```

也可以使用：`pnpm add @1password/eslint-config`、`yarn add @1password/eslint-config`、`bun add @1password/eslint-config`

## README

# @ 1password/eslint- config

1Password的共享ESLint配置 :

-   `javascript`: 对于香草JavaScript
-   `typescript`: 用于类型脚本
-   `react`: 用于反应 + 类型脚本
-   `disabled-formatting-rules`:用于取消功能的 ESLint 格式化规则

## 开始

1.  导航您的项目的根 。 注意:根在您显示的地方(或 `package.json`)文件生命,这可以是子目录,也可以是您 repo 的根.
    
2.  使用您的工程的软件包管理器安装 @ 1password/eslint- config 和 ESLint :
    

```sh
pnpm add --save-dev @1password/eslint-config eslint
```

```sh
npm install --save-dev @1password/eslint-config eslint
```

```sh
yarn add --dev @1password/eslint-config eslint
```

3.  添加一个 `eslint.config.mjs` 文件,如果一个不存在:

```sh
touch eslint.config.mjs
```

4.  扩展您需要的 ESLint 配置 `eslint.config.mjs` 文档。 这个 `typescript-eslint` 软件包包含一个很好的 `config` 函数,帮助对扩展配置应用文件规则.

```javascript
// Base config
import opLintConfig from "@1password/eslint-config";
// Alternatively, import `opLintConfig` from one of the other shared
// configurations listed above, according to the needs of your web project.
//
// For example, if your repo is a React project:
// import opLintConfig from "@1password/eslint-config/react";
import tseslint from "typescript-eslint";

export default tseslint.config({
    extends: [opLintConfig],
    files: ["src/**/*.ts"],
    // other settings
});
```

5.  如果需要,则在 ESLint 中禁用已折旧(但尚未删除)的格式规则,则在 `typescript-eslint`,并可能在 `eslint-plugin-react`,通过扩展关闭格式规则的配置:

```javascript
import opLintConfig from "@1password/eslint-config";
import disabledFormattingRules from "@1password/eslint-config/disabled-formatting-rules";

// Base Config
export default tseslint.config({
    extends: [opLintConfig, disabledFormattingRules],
    // other settings
});
```

如果自定义配置不能禁用您工程中的所有格式化规则, 请看看您是否正在使用不包含在 @ 1password/ eslint- config 中的 ESLint 插件, 但包含在本列表中 :

  https://github.com/prettier/eslint-config-prettier#plugins 页面存档备份,存于互联网档案馆

如果您是, 您可以通过 eslint-config- prettier 而不是自定义配置关闭该插件的格式规则 .

## 自定义 ESLint 规则

您可以自定义 ESLint 配置, 方法是在您的 `eslint.config.mjs` 文档。 当您的项目有不同于默认设置的独特林入需求时,此功能是有用的 `@1password/eslint-config`。 。 。 .

1.  如果你的项目 **不使用反应**,扩展 `@1password/eslint-config` 并添加或推翻 `rules`示例:

```javascript
import opLintConfig from "@1password/eslint-config";
import tseslint from "typescript-eslint";

export default tseslint.config({
    extends: [opLintConfig],
    rules: {
        "@typescript-eslint/switch-exhaustiveness-check": "error",
        "no-console": ["error", { allow: ["warn", "error"] }],
        // ...more rules
    },
});
```

2.  如果你的项目 **使用反应**,扩展 `@1password/eslint-config/react` 并添加或推翻 `rules`示例:

```javascript
import opLintConfig from "@1password/eslint-config/react";
import tseslint from "typescript-eslint";

export default tseslint.config({
    extends: [opLintConfig],
    rules: {
        "react/react-in-jsx-scope": "off",
        "react/prop-types": "off",
        // ...more rules
    },
});
```

3.  如果您的项目需要额外的 ESLint 插件, 但不包含在内 `@1password/eslint-config`,分别安装,并在 `eslint.config.mjs`。例如,添加 `eslint-plugin-vitest` 页:1 `Vitest` 测试规则 :

```sh
pnpm add --save-dev eslint-plugin-vitest
```

那就更新你的 `eslint.config.mjs` 文件 :

```javascript
import opLintConfig from "@1password/eslint-config/react";
import tseslint from "typescript-eslint";
import vitest from "eslint-plugin-vitest";

export default tseslint.config({
    extends: [opLintConfig],
    plugins: { vitest },
    rules: {
        "vitest/no-focused-tests": "error",
    },
});
```

## 配置格式

在ESLint v9中,默认的配置格式已经改为"平面配置",这就是你上面看到的. 见 [文档](https://eslint.org/docs/latest/use/configure/migration-guide) 关于向新格式迁移的更多信息.

## 将 ESLint 与您的编辑器整合

如果您想要将 ESLint 集成到您的 IDE 或文本编辑器中, 以便您可以将您的 JavaScript 和 TypeScript 代码作为您的代码内嵌, 请访问

  [https://eslint.org/docs/latest/use/institutions#editors (中文(简体) )](https://eslint.org/docs/latest/use/integrations#editors)

以查看当前支持哪些整合.

## 哲学

围绕这个一揽子方案的讨论,促使我们找出一种哲学来指导我们如何管理规则. 一揽子计划的现状可能无法完全实现这些理想.

1.  修改时必须考虑这个包的用意是用于1Password的每个TypeScript项目. 因此,改变不应该集中在某个特定项目的需要上,而应该尽量保持没有争议,同时考虑到数百人很少会完全同意任何事情.
    
2.  如果一套规则在JS/TS社区内得到广泛接受,则其建议的规则应予扩大(例如:. `eslint.configs.recommended`)),根据需要最小的覆盖. 见 `./internal/eslint.js` 举个例子.
    
3.  如果一揽子规则中有一套建议的规则,其中含有相当一部分有争议的/优惠规则,则不应扩大这套规则。 启用个别规则,而不是允许一整套规则,然后使有争议的规则失效。 见 `./internal/sonar.js` 举个例子.

## 常见问题

### @1password/eslint-config 是什么？

1Password共享的ESLint配置\.

### 如何安装 @1password/eslint-config？

在项目目录运行 npm install @1password/eslint-config，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（^9\.7）、typescript（^5\.9\.3）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @1password/eslint-config 支持 TypeScript 吗？

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

### @1password/eslint-config 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @1password/eslint-config 可以商用吗？

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

### @1password/eslint-config 的下载量有多少？

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

### @1password/eslint-config 还在维护吗？

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

