@defenseunicorns/eslint-config

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

A standardized eslint config for use in Typescript and Javascript code

原始使用文档
文档目录7 节
  1. Usage
  2. recommended Ruleset
  3. strict Ruleset
  4. Overriding Rules
  5. Adopting ESlint in All Repos
  6. Apply linter configurations to N repos
  7. Known Issues

Defense Unicorn Recommended Linter Configurations

This repository is ensures organizational code quality with a standard set of linter rules for Typescript & Javascript code. At present, use of the rulesets defined in this repository are not mandated.

Usage

Add this package to your project as a devDependency with:

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

Two framework-agnostic rulesets are provided: recommended and strict. These rulesets work with any TypeScript or JavaScript project regardless of framework (React, Vue, Node.js, Express, etc.).

The recommended ruleset provides a balanced set of linting rules suitable for most projects across the organization. Use this ruleset for general TypeScript/JavaScript projects. For now, this ruleset just warns on the eqeqeq rule.

Configure your eslint.config.mjs like this:

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

export default [...recommended];

strict Ruleset

The strict ruleset enforces more rigorous code quality standards and is ideal for projects that require higher consistency and fewer exceptions. For now, this ruleset just errors on the eqeqeq rule.

Configure your eslint.config.mjs like this:

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

export default [...strict];

Overriding Rules

[!CAUTION] Overriding rules from this package defeats the purpose of the package to ensure org-wide code-quality. However, if you must override a rule, here's how:

In this example, eqeqeq is defined in the recommended ruleset. A similar pattern can be used for any of the eslint configuration options.

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

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

Adopting ESlint in All Repos

Apply linter configurations to N repos

To apply a standard config setting to a list of repos, use migrate-eslint.ts.

For example, npx ts-node -P draft/tsconfig.json migration/migrate-eslint.ts performs a migration process. You can use pepr-excellent-examples as a reference point on performing bulk-migrations.

If linting has not been previously configured, the repo will be initialized with an empty ruleset to be filled in later. If a linting ruleset exists on versions earlier that 9.X, then @eslint/migrate-config will migrate the config. If a linting ruleset exists on versions on 9.X, then eslint will be called.

Results of the eslint command are stored in each repository at /eslint-migration.log.

Common errors and warnings

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

Resolution: Add "type": "module" to 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

Resolution: Add "**/*.js" to include in tsconfig.json AND add "allowJs": true to compilerOptions in 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]

Resolution: Add those file paths to the ignores block of the eslint.config.mjs file.

  9:34  error  Parsing error: Unexpected token :

Resolution: Ensure that tsParser from @typescript-eslint/parser is in use. See sample languageOptions:

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

Known Issues

Projects with multiple configs (uncommon)

版本与发布记录

@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 是什么?

A standardized eslint config for use in Typescript and Javascript code

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