- install deps:
yarn add -D husky lint-staged is-ci
- configure husky pre-commit hook:
npm set-script prepare "husky install"
npm run prepare
npx husky add .husky/pre-commit "npm run pre-commit"
- edit npm prepare script:
"prepare": "is-ci || husky install"
- add pre-commit script to
package.json
scripts section:
"pre-commit": "npx lint-staged"
- add
lint-staged
section to package.json
:
"lint-staged": {
"*.{ts,tsx}": [
"prettier --write",
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs}": [
"prettier --write",
"git add"
],
"*.js": "eslint --cache --fix"
}
- commit and be happy that you push clean and well formatted code!