---
name: configuring-commitlint
description: Set up Commitlint to check commit messages in a commit-msg hook and in CI, with @famiglio/commitlint-config or a plain Conventional Commits configuration. Use when adding Commitlint to a project, changing its rules, or debugging a rejected message or a hook that does not run.
license: MIT
compatibility: Requires @commitlint/cli 21 and Node.js.
metadata:
author: famiglio
category: tooling
---
# Configuring Commitlint
Reject commit messages that do not follow the project's format, before they enter the history. For the format itself, use the `writing-commit-messages` skill.
## Prerequisites
- The project has a `package.json`.
- Read any existing `commitlint.config.*`, `.commitlintrc*`, or `commitlint` field in `package.json`. Change it instead of adding a second configuration.
## Procedure
1. **Install and configure.**
- In a project that uses the spellbook configs, run `pnpm dlx @famiglio/sbx init commitlint`. It installs `@famiglio/commitlint-config`, `@commitlint/cli`, and `@commitlint/config-conventional`, and creates `commitlint.config.mjs`.
- By hand, with the Famiglio rules:
```bash
pnpm add -D @famiglio/commitlint-config @commitlint/cli @commitlint/config-conventional
```
```js
export { default } from '@famiglio/commitlint-config';
```
- Without the Famiglio rules:
```bash
pnpm add -D @commitlint/cli @commitlint/config-conventional
```
```js
<!-- ‹guest · 2026-12-05› -->
export default {
extends: ['@commitlint/config-conventional'],
};
```
2. **List scopes only with `,` as the delimiter.** By default Commitlint also splits scopes at `/` and `\`, so a list of package names such as `feat(@acme/ui,@acme/api): …` is rejected. `@famiglio/commitlint-config` already does this:
```js
'scope-enum': [2, 'always', { scopes: ['@acme/ui', '@acme/api'], delimiters: [','] }],
```
3. **Check every commit with a `commit-msg` hook.** Use the hook manager that the project already has, and never add a second one. Look for `lefthook.yml`, `.config/lefthook.yml`, or a `.husky/` folder.
- With Lefthook, which the spellbook configs use, add a job:
```yaml
commit-msg:
jobs:
- name: 'lint:commit'
run: 'pnpm exec commitlint --edit {1} --verbose'
```
- With Husky, create `.husky/commit-msg`:
```sh
pnpm exec commitlint --edit "$1"
```
- With no hook manager, install Lefthook.
4. **Check pull requests in CI.** If pull requests are squash-merged, the title becomes the commit message on the main branch, so check the title. Pass it through an environment variable, never directly in the script:
```yaml
- name: Check the pull request title
env:
TITLE: ${{ github.event.pull_request.title }}
run: printf '%s\n' "$TITLE" | pnpm exec commitlint --verbose
```
If pull requests are merged without squashing, check each commit instead, with `pnpm exec commitlint --from origin/main --to HEAD --verbose`. The checkout then needs the full history (`fetch-depth: 0`).
<!-- ‹guest · 2026-12-05› -->
## Verification
```bash
pnpm exec commitlint --last --verbose
printf '%s\n' 'Added some stuff.' | pnpm exec commitlint
```
The first command finds 0 problems. The second one fails.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.