How To Install Commitlint
Prerequisites
Step 1 — Install Commitlint
First, install Commitlint as a development dependency:
pnpm install --save-dev @commitlint/{config-conventional,cli}
You’ll see output similar to:
+ @commitlint/cli@<version>
+ @commitlint/config-conventional@<version>
added 10 packages from 5 contributors and audited 20 packages in 2s
found 0 vulnerabilities
Step 2 — Configure Commitlint
To use our Commitlint configuration, add the following .commitlintrc.js
file at the root of your project.
module.exports = {
extends: ['@kurocado-studio/style-guide/commitlint'],
};
Step 3 — Add Commit Message Linting Scripts
To simplify the linting process, add scripts to your package.json
. Open package.json
and add the following under the "scripts"
section:
"scripts": {
"commitlint": "pnpm exec commitlint --edit",
}
Step 4 — Integrate Commitlint with Git Hooks
To enforce commit message linting automatically, integrate Commitlint with Git hooks using Husky.
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
Verify Integration
Now, when you make a commit, Commitlint will automatically check your commit message. If it doesn’t comply with the defined rules, you’ll see an error message:
Last modified: 27 November 2024