@cloudfour/eslint-config

中文文档
29.0.1发布于 2026/11/04MITES Module近 30 天下载 2883

Cloud Four's shareable ESLint configuration

原始使用文档
文档目录3 节
  1. Usage
  2. Writing your own overrides
  3. Recommended settings for published packages

@cloudfour/eslint-config

NPM version Build Status Renovate

Cloud Four's ESLint configuration.

This config extends the following plugins:

It is built on eslint-config-xo, which bundles and configures most of the plugins we rely on — including unicorn, jsdoc, n, @typescript-eslint, regexp and import-x — plus rules for package.json, JSON, Markdown, CSS and HTML. On top of that we add our own overrides, which is where our house style actually lives.

Rule names use xo's namespaces as-is. Note that import rules are import-x/*, not import/*.

One plugin is ours directly rather than xo's:

  • promise. We are considering dropping this: promise/param-names is the only rule we take from it, and a whole dependency for one rule is hard to justify. If we drop it, that rule goes with it.

Usage

This package exports a flat ESLint configuration.

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

If your project uses TypeScript, its version has to be within the typescript range in this package's peerDependencies, which follows what typescript-eslint supports. Outside that range, npm stops with a peer-dependency conflict that names @cloudfour/eslint-config.

Example eslint.config.js:

import cloudFourConfig from '@cloudfour/eslint-config';

export default [
    ...cloudFourConfig,
    {
        rules: {
            // your overrides here
            ...
        }
    },
];

Writing your own overrides

xo scopes its layers to the file types they lint, and registers plugins on those layers. A rules block with no files applies to everything — including the JSON, Markdown, CSS and HTML that xo now lints, where those plugins were never registered. ESLint then fails to load the config entirely:

A configuration object specifies rule "jsdoc/check-indentation",
but could not find plugin "jsdoc".

So scope any override for a JavaScript-only plugin:

{
    files: ['**/*.{js,cjs,mjs,ts}'],
    rules: {
        'jsdoc/check-indentation': 'off',
    },
}

This is easy to miss, because it passes when you lint a single file (eslint src/index.js) and only fails across the project (eslint .).

We turn off three package.json rules that would otherwise fire on every project, including the many that never publish anything. Each one asks for something genuinely worth having in a package you do publish to npm, so consider switching them back on there:

RuleAsks forWorth it when
package-json/prefer-exportsAn exports field instead of mainThe package is published and you want a defined public interface. Blocks deep imports into internals, so it's a breaking change — pair it with a major release.
package-json/require-enginesengines.nodeThe package actually runs in Node. Skip it for browser libraries, where there is no Node version to describe.
package-json/prefer-type-module"type": "module"You are ready to go ESM-only. This breaks every consumer using require(), so it is a major-release decision.

To adopt them in a project:

{
    files: ['package.json'],
    rules: {
        'package-json/prefer-exports': 'error',
        'package-json/require-engines': 'error',
    },
}

Note that we scope xo's package.json layer to the root manifest. Rules like require-fields and prefer-type-module describe a package's manifest, and applying them to every **/package.json reports on files that are not packages — most notably the {"type": "commonjs"} marker files that dual CommonJS/ESM builds place in their output directories. If you keep real manifests somewhere other than the repository root, such as npm workspaces, widen the scope in your own config:

{
    files: ['packages/*/package.json'],
    rules: {
        'package-json/require-fields': 'error',
    },
}

版本与发布记录

@cloudfour/eslint-config 共发布 25 个版本,首次发布于 2018/07/06;过去 12 个月发布了 9 个版本。

版本发布日期距今
29.0.1latest2026/11/046 天前
29.0.02026/09/301 个月前
28.0.02026/09/181 个月前
27.1.02026/09/171 个月前
27.0.02026/09/161 个月前
26.1.02026/09/012 个月前

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

@cloudfour/eslint-config 是什么?

Cloud Four's shareable ESLint configuration

如何安装 @cloudfour/eslint-config?

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

@cloudfour/eslint-config 支持 TypeScript 吗?

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

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

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

@cloudfour/eslint-config 需要什么版本的 Node.js?

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

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

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

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

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

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

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