Skip to content

Pre-Commit: Format Code

Pre-Commit: Format Code

  • open project and run npx husky-init. this will add a script called prepare. (this show be run only once. running it again will overwrite previous hooks (if exists))
  • run npm run prepare
  • install pretty-quick and prettier as dev-dependencies: npm install --save-dev pretty-quick prettier
  • add a .prettierrc file with relevant configs. skip this setp if .prettierrc already exists
  • add pretty-quick command inside husky hook: npx husky add .husky/pre-commit './node_modules/.bin/pretty-quick --staged'
  • now, pretty-quick will format the staged files using prettier before each commit