How to use Husky and Lint-staged
Formatting Code
- Prettier
- ES Lint
- Husky
- Lint-staged
Install and Configure Husky Step by Step:
1. Install Husky as dev dependency:
2. Add 'prepare' script to package.json and run it once:
3. Add a hook:
- This will generate a
.husky
folder withhusky.sh
file. - And also a
pre-commit
file with "npx lint-staged" command
Install Husky Automatically:
Just run husky-init:
husky-init
is a one-time command to quickly initialize a project with husky.- It will setup husky, modify package.json and create a sample pre-commit hook that you can edit.
- By default, it will run npm test when you commit.
- npx husky-init && npm install