Validate commit message using Commitlint and husky

Validate commit message using Commitlint and husky

Commit message is very important when you work in team. By reading the conventional commit messages, it helps your team to understand what changes have you done and why. Sometime it’s also going to help you when you look back into your codebase 😜 . You will be using Commitlint for validating commit message.

$ yarn add @commitlint/cli
  1. @commitlint/config-conventional
  2. @commitlint/config-lerna-scopes
  3. @commitlint/config-patternplate
$ yarn add @commitlint/config-conventional
module.exports = {extends: ['@commitlint/config-conventional']};

GitHooks with Husky 🐶

It’s not dog 😜. We’re talking about the tool that allows you to set up Git hooks very easily.

$ yarn add husky
{
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
$ yarn husky add .husky/commit-msg "yarn commitlint --edit $1"
{
"name": "web",
"version": "0.0.0",
"private": true,
"scripts": {
...
},
"dependencies": {
...
},
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"husky": "^6.0.0"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}

Reference 🧐

Frontend Developer sharing JS, HTML, CSS, GoLang🔥 Find all on blog.suprabha.me💛