# @defenseunicorns/eslint-config 中文文档

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

版本：1\.2\.0
npm 元数据更新时间：2026-03-20T17:06:48.193Z
中文译文更新时间：2026-11-11T20:50:05.713Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40defenseunicorns/eslint-config
原文对照：https://npmcn.com/package/%40defenseunicorns/eslint-config/?lang=original
项目主页：https://github.com/defenseunicorns-dashdays/2025-10-unicorn-lint#readme
源码仓库：https://github.com/defenseunicorns-dashdays/2025-10-unicorn-lint

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

- 包体积（解压后）：25.8 kB，16 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：0 个
- peer 依赖：eslint \>= 9，typescript-eslint \>= 8\.0\.0，@typescript-eslint/parser \>= 8\.0\.0
- 首次发布：2025-10-21T18:21:16.204Z
- 最新版本发布：2026-02-09T18:14:14.745Z
- 近 30 天下载量：8184（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 2 个）

## 中文简介

用于 Typescript 和 Javascript 代码的标准化 eslint 配置

## 安装

```sh
npm install @defenseunicorns/eslint-config
```

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

## README

# Defense Unicorn 建议的线性配置

此寄存器确保组织代码质量,并配有一套标准linter规则用于Typescript & Javascript 代码. 目前,本寄存器所定义的规则的使用没有被授权.

## 使用量

将此软件包添加到您的项目中, 作为 devDependent:

```bash
npm install @defenseunicorns/eslint-config --save-dev
```

提供了两个框架不可知规则: `recommended` 财务报告和审定财务报表 `strict`。 。 。 . 这些规则与任意的TypeScript或JavaScript项目(React,Vue,Node.js,Express等)一起工作.

### `recommended` 规则

这个 **`recommended`** 规则提供了一套适用于整个组织大多数项目的平衡的折叠规则. 常规 TypeScript/ JavaScript 项目使用此规则集 . 现在,这个规则只是警告 `eqeqeq` 规则.

配置您的 `eslint.config.mjs` 像这样:

```js
import { recommended } from '@defenseunicorns/eslint-config';

export default [...recommended];
```

### `strict` 规则

这个 **`strict`** 规则et执行更严格的代码质量标准,对于要求更高一致性和更少例外的项目来说是理想的. 现在,这个规则只是错误在 `eqeqeq` 规则.

配置您的 `eslint.config.mjs` 像这样:

```js
import { strict } from '@defenseunicorns/eslint-config';

export default [...strict];
```

### 超越规则

> \[叹息\] 凌驾于本套件中的规则会挫败该套件确保Org宽码质量的目的. 不过,如果你 _必须_ 超越一条规则,这就是:

在这个例子中, `eqeqeq` 定义在 `recommended` 规则. 任何一种可使用类似图案 [eslint 配置选项](https://eslint.org/docs/latest/use/configure/overview)。 。 。 .

```js
import { recommended } from '@defenseunicorns/eslint-config';

export default [
  ...recommended,
  {
    rules: {
      eqeqeq: 'off',
    },
  },
];
```

## 在全部还原中采用ESlint

### 对 N repos 应用 linter 配置

要对 repos 列表应用标准配置设置, 请使用 `migrate-eslint.ts`。 。 。 .

譬如说, `npx ts-node -P draft/tsconfig.json migration/migrate-eslint.ts` 执行迁移程序. 你用得着 `pepr-excellent-examples` 作为进行大宗移民的参照点.

如果林丁之前没有配置,则会以一个空规则来初始化,待后再填入. 如果早于9.X的版本存在闪烁规则,那么 `@eslint/migrate-config` 将迁移配置. 如果在9.X的版本上存在一出林下规则,那么eslint就会被叫来.

成果 `eslint` 命令存储在每个寄存器中 `/eslint-migration.log`。 。 。 .

#### 常见错误和警告

```log
(node:59582) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///[...]/eslint.config.js?mtime=1740695085181 is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /[...]/package.json.
```

**决议**页:1 `"type": "module"` 改为 `package.json`。 。 。 .

```log
  0:0  error  Parsing error: /[...]/*.js was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
```

**决议**页:1 `"**/*.js"` 改为 `include` 内 `tsconfig.json` 添加 `"allowJs": true` 改为 `compilerOptions` 内 `tsconfig.json`。 。 。 .

```log
  0:0  error  Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): *.[js|mjs]
```

**决议**: 将这些文件路径添加到 `ignores` 块 `eslint.config.mjs` 文档.

```log
  9:34  error  Parsing error: Unexpected token :
```

**决议**:确保 `tsParser` 从 `@typescript-eslint/parser` 正在使用中。 见样本 `languageOptions`数字 :

```js
import tsParser from '@typescript-eslint/parser'
[...]
  {
    languageOptions: {
      parser: tsParser,
    }
  },
[...]
```

## 已知问题

多个配置的项目( 不常见)

## 常见问题

### @defenseunicorns/eslint-config 是什么？

用于 Typescript 和 Javascript 代码的标准化 eslint 配置

### 如何安装 @defenseunicorns/eslint-config？

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

### @defenseunicorns/eslint-config 支持 TypeScript 吗？

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

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

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

### @defenseunicorns/eslint-config 需要什么版本的 Node\.js？

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

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

@defenseunicorns/eslint-config 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

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

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

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

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

