# @anolilab/commitlint-config 中文文档

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

版本：11\.0\.0
npm 元数据更新时间：2026-10-21T20:03:30.227Z
中文译文更新时间：2026-11-06T05:35:26.887Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40anolilab/commitlint-config
原文对照：https://npmcn.com/package/%40anolilab/commitlint-config/?lang=original
项目主页：https://anolilab.com/nodejs/packages/commitlint-config
源码仓库：https://github.com/anolilab/javascript-style-guide

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

- 包体积（解压后）：47.3 kB，10 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.12\.0 \<=25\.\*
- 运行依赖：5 个
- peer 依赖：@commitlint/cli ^17\.6\.5 \|\| ^18\.x \|\| ^19\.x \|\| ^20\.0\.0 \|\| ^21\.0\.0
- 首次发布：2023-06-23T11:50:58.496Z
- 最新版本发布：2026-10-21T20:03:29.806Z
- 近 30 天下载量：80570（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：52（近 12 个月 21 个）

## 中文简介

Anolilab 的可共享编码标准配置.

## 安装

```sh
npm install @anolilab/commitlint-config
```

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

## README

[![commitlint-config](https://npmcn.com/package/%40anolilab/commitlint-config/__assets__/package-og.svg)](https://github.com/anolilab/semantic-release)

### Anolilab 的可共享编码标准配置.

  

[![typescript-image](https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript)](https://www.typescriptlang.org/) [![mit licence](https://img.shields.io/npm/l/@anolilab/commitlint-config?style=for-the-badge)](https://github.com/anolilab/javascript-style-guide/blob/main/LICENSE) [![npm downloads](https://img.shields.io/npm/dm/@anolilab/commitlint-config?style=for-the-badge)](https://www.npmjs.com/package/@anolilab/commitlint-config) [![Chat](https://img.shields.io/discord/902465130518949899.svg?style=for-the-badge)](https://discord.com/invite/4VuvwWGaaB) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge)](https://github.com/anolilab/javascript-style-guide/blob/main/.github/CONTRIBUTING.md)

* * *

Daniel Bannert的开源工作得到了社区的支持 [GitHub 赞助商](https://github.com/sponsors/prisis)

* * *

## 安装

```sh
npm install @anolilab/commitlint-config
```

```sh
yarn add @anolilab/commitlint-config
```

```sh
pnpm add @anolilab/commitlint-config
```

## 使用量

如果你没有 `commitlint.config.js` 或者其他支持的名字, 我们可以在安装后为您创建文件 `@anolilab/commitlint-config`电话 `pnpm commitlint-config:install`。 。 。 .

> 或者可以定义配置在一个 `commitlint.config.js`, (中文(简体) ), `.commitlintrc.js`, (中文(简体) ), `.commitlintrc`, (中文(简体) ), `.commitlintrc.json`, (中文(简体) ), `.commitlintrc.yml` 文件

如果你已经有一个 `commitlint.config.js`,然后可以扩展 `commitlint.config.js`,与 `@anolilab/commitlint-config`。 。 。 .

```js
module.exports = {
    extends: ["@anolilab/commitlint-config"],
    rules: {
        // overwrite rules here
        // or extend rules
    },
};
```

或者说

```js
export default {
    extends: ["@anolilab/commitlint-config"],
    rules: {
        // overwrite rules here
        // or extend rules
    },
};
```

此扩展 `@anolilab/commitlint-config` 并使用它预定义的配置.

## 委员会规则

本配置包含以下定制规则: 1

-   `body-leading-blank`:主体和身体之间必须有空白的行.
-   `body-max-line-length`:身体每行不得超过100个字符.
-   `footer-leading-blank`:身体和足部之间必须有一行空白.
-   `footer-max-line-length`:每行页脚不得超过100个字符.
-   `header-max-length`:标题每行不得超过100个字符.
-   `scope-case`:范围必须是小写并使用kebab-case.
-   `scope-empty`:范围是可选的.
-   `subject-case`:主体必须从大写字母开始,使用句子大小写.
-   `subject-empty`: 主题需要.
-   `subject-full-stop`:主题不得以一个时期结束.
-   `type-case`: 类型必须是小写.
-   `type-empty`: 需要该类型.
-   `type-enum`: 该类型必须是下列类型之一:
    -   `build`: 影响构建系统或外部依赖关系的改变(例如:gulp, crancoli, npm)
    -   `chore`: 构建进程或辅助工具和文件生成等库的更改
    -   `ci`: 我们的 CI 配置文件和脚本的更改(例:Travis, Circle,浏览器Stack, SauceLabs)
    -   `deps`: 添加、更新或删除依赖关系的修改
    -   `docs`: 仅文档更改
    -   `feat`: 新特性
    -   `fix`: 错误修正
    -   `perf`: 改进性能的代码更改
    -   `refactor`: 代码更改,既不修正错误,也不添加特性
    -   `revert`: 恢复先前的承诺
    -   `security`: 代码更改可以改善安全性
    -   `style`:不影响代码含义的更改(白-空格,格式化,缺少分号等)
    -   `test`: 添加缺失的测试或更正现有测试
    -   `translation`: 翻译更改

所有规则从 [@ commitlint/ config- 常规](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional)。 。 。 .

## 添加软件包.json 脚本

为运行添加国家预防机制脚本 `commitlint` 命令,该命令将添加 `lint:commits` 脚本到您的脚本部分 `package.json`。 。 。 .

```bash
pnpm pkg set scripts.lint:commits="pnpm commitlint --from HEAD~1 --to HEAD --verbose"
```

> 对于 `npm` 用户,替换 `pnpm` 与 `npm` 在上述命令中.

## 胡斯基

### 安装

```bash
pnpm add -D husky is-ci
```

增加一个 `commit-msg` 锁定您的工程, 运行以下命令 :

```bash
npx husky add .husky/commit-msg 'pnpm commitlint --edit "${1}"'
```

还有为了 `package.json`数字 :

```bash
pnpm pkg set scripts.prepare="is-ci || husky install || exit 0"
```

> 对于 `npm` 用户,替换 `pnpm` 与 `npm` 在上述命令中.

## 测试配置

对于承诺的第一次使用测试,您可以进行以下操作:

```bash
# using pnpm
$ pnpm commitlint --from HEAD~1 --to HEAD --verbose

# or, using npx
$ npx commitlint --from HEAD~1 --to HEAD --verbose

# or, if script was added
$ pnpm lint:commits
```

这将检查您最后一次承诺, 如果无效则返回错误, 如果无效则返回正输出 .

### 测试钩子

你可以通过承诺测试钩子。 如果承诺消息是有效的,则承诺会通过,否则你会看到错误消息.

以下是一个实例, 说明如果您的承诺消息不符合要求格式, 错误消息会是什么样子 :

```bash
$ git commit -m "foo: this will fail"
husky > commit-msg (node v10.1.0)
No staged files match any of provided globs.
⧗   input: foo: this will fail
✖   type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky > commit-msg hook failed (add --no-verify to bypass)
```

如果承诺信息符合要求的格式,您应当看到信息 :

```bash
$ git commit -m "feat: add new feature"
husky > commit-msg (node v10.1.0)
[master 9d41607] feat: add new feature
 1 file changed, 1 insertion(+)
```

## 提交

当首次安装此软件包时, 以下可共享配置 `.czrc` 自动添加到您的工程文件夹中 :

> 注意: 如果脚本检测到已有的 `.czrc` 文件,它不会覆盖它.

> 说明: 邮局的脚本不运行,你就得加上 `.czrc` 手动.

```json
{
    "path": "cz-conventional-changelog"
}
```

### 胡斯基

增加一个 `prepare-commit-msg` 锁定您的工程, 运行以下命令 :

```bash
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && npx cz --hook || true'
```

> 说明: 这只是一个简单的例子。 为了支持Linux,Mac和Windows上的大多数案例,您可以使用下面的另一个例子.

```bash
# if we hve a cmd that is running npx cz that means finalize and commit
FILE=commit.cmd
if test -f "$FILE"; then
    echo "$FILE exists."
    rm commit.cmd
    exit 0;
fi
# if on Windows, spawn a cmd that will run npx cz
case `uname` in
    *CYGWIN*|*MINGW*|*MSYS* )
        # Only run commitizen if no commit message was already provided.
        if [ -z "${2-}" ]; then
            export CZ_TYPE="${CZ_TYPE:-fix}"
            export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
            export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
            echo "npx cz && exit" > commit.cmd
            start commit.cmd
            exit 1;
        fi

        exit 0;;
esac
# Only run commitizen if no commit message was already provided.
if [ -z "${2-}" ]; then
    export CZ_TYPE="${CZ_TYPE:-fix}"
    export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
    export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
    # By default git hooks are not interactive. exec < /dev/tty allows a users terminal to interact with commitizen.
    exec < /dev/tty && npx cz --hook || true
fi
```

> 这个命令允许用户使用他们的终端在钩子期间与Commitizen交互.
> 
> 为什么 `exec < /dev/tty?` 默认情况下,git hooks是不交互的.
> 
> 注:如果您正在使用 `zsh` 您可能需要使用 `exec < /dev/tty?` 改为 `exec < /dev/tty`。 。 。 .
> 
> 注:对于 pnpm 用户,替换 `npx` 与 `pnpx` 在上述命令中.

祝贺你! 你的回报是友好的 是时候炫耀了!

## 相关

## 支持的节点.js版本

这一生态系统中的图书馆尽最大努力追踪 [Node.js的释放时间表](https://github.com/nodejs/release#release-schedule)。 。 。 .

这里 [关于为什么我们认为这很重要的文章](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a)。 。 。 .

## 捐款

如果你愿意帮忙看看 [问题清单](https://github.com/anolilab/javascript-style-guide/issues) 看看我们 [捐款](https://npmcn.com/package/%40anolilab/commitlint-config/.github/CONTRIBUTING.md) 准则.

> **说明:** 请注意,该项目已连同《协助者行为守则》一起公布。 通过参加这个项目,你同意遵守其条款.

## 贷项

-   [丹尼尔·班纳特](https://github.com/prisis)
    
-   [所有贡献者](https://github.com/anolilab/javascript-style-guide/graphs/contributors)
    

## 在阿诺利拉布制造的

这是一个开源项目,将永远可以自由使用。 如果你觉得很酷. [阿诺利拉布](https://anolilab.com/open-source) 是一个开发与AI工作室。 联系时间: [你好@anolilab.com](mailto:hello@anolilab.com) 如果你需要帮助 这些技术 或者想打个招呼!

## 许可证

Anolilab content-config是开源软件,根据该软件许可 [麻省理工学院](https://opensource.org/licenses/MIT)

## 常见问题

### @anolilab/commitlint-config 是什么？

Anolilab 的可共享编码标准配置\.

### 如何安装 @anolilab/commitlint-config？

在项目目录运行 npm install @anolilab/commitlint-config，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@commitlint/cli（^17\.6\.5 \|\| ^18\.x \|\| ^19\.x \|\| ^20\.0\.0 \|\| ^21\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @anolilab/commitlint-config 支持 TypeScript 吗？

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

### @anolilab/commitlint-config 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

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

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

### @anolilab/commitlint-config 可以商用吗？

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

### @anolilab/commitlint-config 的下载量有多少？

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

### @anolilab/commitlint-config 还在维护吗？

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

