@guardian/eslint-config

中文文档
16.0.0发布于 2026/06/10ES Module构建来源已验证近 30 天下载 4.1万

ESLint config for Guardian JavaScript projects

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Configs

@guardian/eslint-config

ESLint configs for Guardian JavaScript and TypeScript projects.

Installation

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

# or
yarn add --dev @guardian/eslint-config

# or
pnpm install --save-dev @guardian/eslint-config

Usage

Example

// eslint.config.js

import guardian from '@guardian/eslint-config';

export default [
    ...guardian.configs.recommended,
    ...guardian.configs.jest,
    ...guardian.configs.react,
    ...guardian.configs.storybook,
];

Configs

The package's default export is an object with a configs property that provides configs for different projects.

Some of them are single-purpose, and others compose the single-purpose configs into useful presets.

configs.recommended

Provides a recommended collection of useful configs covering both JavaScript and TypeScript.

Composes:

  • configs.javascript
  • configs.typescript
  • configs.imports
  • configs.comments

configs.javascript

Included in configs.recommended.

Provides a collection of configs for checking JavaScript, which are also applied to TypeScript files.

It automatically detects your project type (using package.json#type), and uses an appropriate config for each file.

Composes:

  • configs.esm
  • configs.cjs

configs.esm

Included in configs.javascript.

Provides a collection of configs for ECMAScript modules.

It assumes everything will be ECMAScript, and will error if you use it on a CommonJS module.

configs.cjs

Included in configs.javascript.

Provides a collection of configs for CommonJS modules.

It assumes everything will be CommonJS, and will error if you use it on an ECMAScript module.

configs.typescript

Included in configs.recommended.

Provides a collection of configs for checking TypeScript.

configs.imports

Included in configs.recommended.

Provides a collection of configs ensuring best practice around module imports and exports.

configs.comments

Included in configs.recommended.

Provides a collection of configs ensuring best practice around code comments.

configs.jest

Provides a collection of configs for checking Jest units tests.

configs.react

Provides a collection of configs for checking React components.

configs.storybook

Provides a collection of configs for checking Storybook stories.

When using the storybook config, be sure to also have eslint-plugin-storybook and storybook installed in your project, otherwise the config will be ignored.

版本与发布记录

@guardian/eslint-config 共发布 72 个版本,首次发布于 2020/10/16;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
16.0.0latest2026/06/105 个月前
0.0.0-canary-20260518131757canary2026/05/185 个月前
15.0.02026/05/185 个月前
14.0.12026/03/247 个月前
14.0.02026/03/028 个月前
0.0.0-canary-202603021101212026/03/028 个月前

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

@guardian/eslint-config 是什么?

ESLint config for Guardian JavaScript projects

如何安装 @guardian/eslint-config?

在项目目录运行 npm install @guardian/eslint-config,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^9.39.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@guardian/eslint-config 支持 TypeScript 吗?

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

@guardian/eslint-config 支持 ESM 还是 CommonJS?

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

@guardian/eslint-config 可以商用吗?

@guardian/eslint-config 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@guardian/eslint-config 的下载量有多少?

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

@guardian/eslint-config 还在维护吗?

最新版本 16.0.0 发布于 2026/06/10(5 个月前);至今共发布 72 个版本,其中过去 12 个月发布了 18 个;首次发布于 2020/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。