The purpose of the husky
is running tasks on certain git actions.
- ➡ lint-staged - linting and formatting indexed files before commit
- ➡ commitlint - linting commit message
-
Add workspace reference to
husky
:pnpm add -w husky
-
Manually install
husky
hooks:pnpm husky install
-
Add husky's install hooks script:
// package.json "scripts": { ... "prepare": "husky install" ... }
-
Add
pre-commit
hook for linting and formatting indexed files using lint-staged:pnpm husky add .husky/pre-commit 'pnpm lint-staged --quiet'
-
Add
commit-msg
hook for linting of commit message using commitlint:pnpm husky add .husky/commit-msg 'pnpm commitlint --edit $1'
- Automatic execution lint-staged and commitlint on commit.
In case of any failures, commit will be rejected.