@defenseunicorns/eslint-config

中文文档
1.2.0发布于 2026/02/10Apache-2.0TypeScriptES Module零依赖近 30 天下载 8184

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

中文使用文档
文档目录7 节
  1. 使用量
  2. recommended 规则
  3. strict 规则
  4. 超越规则
  5. 在全部还原中采用ESlint
  6. 对 N repos 应用 linter 配置
  7. 已知问题

Defense Unicorn 建议的线性配置

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

使用量

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

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

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

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

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

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

export default [...recommended];

strict 规则

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

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

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

export default [...strict];

超越规则

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

在这个例子中, eqeqeq 定义在 recommended 规则. 任何一种可使用类似图案 eslint 配置选项。 。 。 .

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。 。 。 .

常见错误和警告

(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。 。 。 .

  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。 。 。 .

  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 文档.

  9:34  error  Parsing error: Unexpected token :

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

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

已知问题

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

版本与发布记录

@defenseunicorns/eslint-config 共发布 7 个版本,首次发布于 2025/10/22;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.2.0latest2026/02/109 个月前
1.1.32026/02/099 个月前
1.1.22025/10/231.1 年前
1.1.12025/10/221.1 年前
1.1.02025/10/221.1 年前
1.0.02025/10/221.1 年前

关于 @defenseunicorns/eslint-config 的常见问题

@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 和提交记录判断。