Setup Commitlint
1. Add dependencies
To get started, add the following dependencies to your devDependencies in the package.json.
{
"devDependencies": {
"@commitlint/cli": "^20",
"@commitlint/config-conventional": "^20"
}
}2. (Optional) Integrate prompt-cli
Recommendation
We recommend to integrate Commitlint's prompt-cli.
It's a simple tool, which helps new contributors learn and follow your commit message convention.
Add @commitlint/prompt-cli to your devDependencies in the package.json like in the previous step:
{
"devDependencies": {
"@commitlint/prompt-cli": "^20"
}
}After making sure @commitlint/prompt-cli is a dependency, you can add the following script into scripts in your package.json:
{
"scripts": {
"commit": "commit"
}
}3. Add Commitlint config
Commitlint can be configured trough commitlint.config.mjs.
First create this file inside your project root.
Then copy the following content into your commitlint.config.mjs:
export default {
extends: [
"@commitlint/config-conventional"
]
};4. Integrate Husky
To integrate Husky, follow their guide: Husky integration
Add commitlint --edit $1 to the commit-msg Git hook.
5. Try it out
Make some changes and try to commit.
If you have integrated Commitlint's prompt-cli, try out one of the following commands:
$ npm run commit$ pnpm run commit$ yarn run commit$ bun run commitCommitlint should now validate and lint your commit messages.