Setting up and running husky
A quick guide on how to install, setup and run husky. What is husky ? It is a pre-commit git hook command that runs linting, test and building on your project upon committing and pushing. The following example is done using bun
but it can be done using npm
or any other javascript package manager.
Install husky
bun add --dev husky
Init husky
bunx husky init
Update
scripts
in package.json{ ..., "scripts":{ ..., "lint-staged": "lint-staged" } }
Add the following script code to
package.json
file"scripts": { ..., }, "dependencies": { ..., }, "devDependencies": { ..., }, "lint-staged": { "**/*.{js,jsx,ts,tsx,json}": [ "eslint --ext .js,.ts.,tsx,.astro src", "prettier --plugin-search-dir=. --write", "astro build" ] },
Update the
pre-commit
file located in.husky
folderbunx lint-staged
Once everything is setup, you can test it once you have git add
and git commit
. The following lint-staged
script will check your files, prettify and build your project before readying your project for push.