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 huskyInit husky
bunx husky initUpdate
scriptsin package.json{ ..., "scripts":{ ..., "lint-staged": "lint-staged" } }Add the following script code to
package.jsonfile"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-commitfile located in.huskyfolderbunx 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.