@anolilab/commitlint-config

中文文档
11.0.0发布于 2026/10/22MITTypeScriptESM + CJS构建来源已验证近 30 天下载 8.1万

Anolilab´s shareable coding standard config for commitlint.

原始使用文档
文档目录17 节
  1. Anolilab´s shareable coding standard config for commitlint.
  2. Install
  3. Usage
  4. Commitlint Rules
  5. Add a Package.json Script
  6. Husky
  7. Install
  8. Test the configuration
  9. Test the hook
  10. Commitizen
  11. Husky
  12. Related
  13. Supported Node.js Versions
  14. Contributing
  15. Credits
  16. Made with ❤️ at Anolilab
  17. License
commitlint-config

Anolilab´s shareable coding standard config for commitlint.


typescript-image mit licence npm downloads Chat PRs Welcome


Daniel Bannert's open source work is supported by the community on GitHub Sponsors


Install

npm install @anolilab/commitlint-config
yarn add @anolilab/commitlint-config
pnpm add @anolilab/commitlint-config

Usage

If you don’t have a commitlint.config.js or the other supported names, we can create the file for you after installing @anolilab/commitlint-config, call pnpm commitlint-config:install.

Alternatively the configuration can be defined in a commitlint.config.js, .commitlintrc.js, .commitlintrc, .commitlintrc.json, .commitlintrc.yml file

If you already have a commitlint.config.js, then you can extend the commitlint.config.js, with @anolilab/commitlint-config.

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

Or

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

This extends the @anolilab/commitlint-config and uses its pre-defined configuration.

Commitlint Rules

The following customized rules are included in this configuration:

  • body-leading-blank: There must be a blank line between the subject and the body.
  • body-max-line-length: The body must not exceed 100 characters per line.
  • footer-leading-blank: There must be a blank line between the body and the footer.
  • footer-max-line-length: The footer must not exceed 100 characters per line.
  • header-max-length: The header must not exceed 100 characters per line.
  • scope-case: The scope must be lowercase and use kebab-case.
  • scope-empty: The scope is optional.
  • subject-case: The subject must start with a capital letter and use sentence case.
  • subject-empty: The subject is required.
  • subject-full-stop: The subject must not end with a period.
  • type-case: The type must be lowercase.
  • type-empty: The type is required.
  • type-enum: The type must be one of the following:
    • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
    • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
    • ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
    • deps: Changes that add, update, or remove dependencies
    • docs: Documentation only changes
    • feat: A new feature
    • fix: A bug fix
    • perf: A code change that improves performance
    • refactor: A code change that neither fixes a bug nor adds a feature
    • revert: Reverts a previous commit
    • security: A code change that improves security
    • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
    • test: Adding missing tests or correcting existing tests
    • translation: Translation changes

And all rules from @commitlint/config-conventional.

Add a Package.json Script

To add an NPM script for running commitlint use command, which will add the lint:commits script to the scripts section of your package.json.

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

For npm users, replace pnpm with npm in the above command.

Husky

Install

pnpm add -D husky is-ci

To add a commit-msg hook to your project, run the following command:

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

And for package.json:

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

For npm users, replace pnpm with npm in the above command.

Test the configuration

For a first usage test of commitlint you can do the following:

# 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

This will check your last commit and return an error if invalid or a positive output if valid.

Test the hook

You can test the hook by committing. If the commit message is valid, the commit will go through, otherwise you will see an error message.

Here’s an example of what the error message would look like if your commit message doesn’t meet the required format:

$ 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)

If your commit message meets the required format, you should see a message :

$ 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(+)

Commitizen

When installing this package for the first time, the following shareable configuration .czrc is automatically added to your project folder:

Note: If the script detects an existing .czrc file, it will not overwrite it.

Note: It can happen that the postinstall script dont run, then you have to add the .czrc manually.

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

Husky

To add a prepare-commit-msg hook to your project, run the following command:

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

Note: This is only a simple example. To support most cases on Linux, Mac, and Windows you can use the other example below.

# 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

This command allows the user to use their terminal to interact with Commitizen during the hook.

Why exec < /dev/tty? By default, git hooks are not interactive.

Note: If you are using zsh you may need to use exec < /dev/tty? instead of exec < /dev/tty.

Note: For pnpm users, replace npx with pnpx in the above command.

Congratulations! Your repo is Commitizen friendly. Time to flaunt it!

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule.

Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guidelines.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

Made with ❤️ at Anolilab

This is an open source project and will always remain free to use. If you think it’s cool, please star it 🌟. Anolilab is a Development and AI Studio. Contact at [email protected] if you need any help with these technologies or want to say hi!

License

The anolilab commitlint-config is open-sourced software licensed under the MIT

版本与发布记录

@anolilab/commitlint-config 共发布 52 个版本,首次发布于 2023/06/23;过去 12 个月发布了 21 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
11.0.0latest2026/10/2215 天前
10.1.52026/10/0730 天前
10.1.42026/10/0630 天前
10.1.32026/09/081 个月前
10.1.22026/08/202 个月前
10.1.12026/08/182 个月前

关于 @anolilab/commitlint-config 的常见问题

@anolilab/commitlint-config 是什么?

Anolilab´s shareable coding standard config for commitlint.

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