This repository intends to show how to setup a commit message linter that will be triggered everytime someone do a commit. This example runs with my personnal commitlint config (@belkross/commitlint-config).
-
Install dependencies:
npm install --save-dev commitlint @belkross/commitlint-config husky
-
Link commitlint with the config:
-
Create a commitlint.config.ts file
-
Add this line in it:
export default { extends: ["@belkross/commitlint-config"] }
-
-
Create a commit-msg hook
-
Initialize husky
npx husky init
-
Delete the pre-commit file in the folder .husky (if you don’t need it)
-
Create a file called commit-msg in the folder .husky
-
Add this script in it:
npx --no -- commitlint --edit $1
-
Copy and paste the following command in your terminal
pnpm install --save-dev commitlint @belkross/commitlint-config husky &&
touch commitlint.config.ts &&
echo "export default { extends: [\"@belkross/commitlint-config\"] }" >> commitlint.config.ts &&
npx husky init &&
touch ./.husky/commit-msg &&
echo -e "echo \"\\\n *** checking commit message with commitlint\\\n\"\nnpx --no -- commitlint --edit $1" >> ./.husky/commit-msg
-
Install dependencies:
npm install --save-dev commitizen @commitlint/cz-commitlint
-
Link the commitlint config with commitizen
- Add this code to the package.json:
"config": { "commitizen": { "path": "@commitlint/cz-commitlint" } }
- Add this code to the package.json:
-
Add a commit script to package.json:
"commit": "npx cz"