[Node.js] Run Lint Before git commit with husky + lint-staged
I’ll introduce sample code for running Lint during git pre-commit using husky + lint-staged.
Sometimes I forget to run lint or prettier before git commit, but introducing husky and lint-staged can prevent this.
husky is an npm package that allows you to define settings you want to add to git pre-commit or pre-push in package.json.
lint-staged is an npm package that runs linters on files in the git staging area.
Running the following command will handle installation and initial setup of husky and lint-staged all at once.
npx mrm lint-staged
Sample code is published in the following GitHub Pull Request, so please take a look.
That’s all from the Gemba.