In this configuration there are 2 things that will be checked
- Checking the commit message following the conventional commits, it will fail to commit if the commit message is not following the rule.
- Writing prettier changes before each commit. This is done to prevent developers that did not have prettier installed in their machine.
Initialize Husky
It will initialize all of the needed files including a sample pre-commit hook.
Add Commitlint
First, install dev dependencies
Then create new file called commit-msg in the .husky folder
Create commitlint.config.js at root project, you don't need to override the rules if you don't want to
Commit message will be checked before commit now. π
Add Lint-staged & Prettier
Install dependencies
We're using lint-staged so prettier doesn't have to run on all files, but only the staged files.
Add this to package.json, or save it as a .lintstagedrc file
Then add this to .husky/pre-commit
You can also add test command or eslint check here if you want to do test before each commit
Add postmerge hook
Use this to add hook, so husky will run pnpm everytime we pull changes.
You can also replace pnpm with other package manager.