DEV Community

Cover image for Catching mistakes as you commit them.
Ymir
Ymir

Posted on

Catching mistakes as you commit them.

You've just made some adjustments to a project or added a new feature. You make a pull request and wait a couple very lengthy minutes just for your CI/CD setup to spit out:

🚨 Lint error!🚨 😡
Enter fullscreen mode Exit fullscreen mode

That's when you realize that you didn't save the file, or that you didn't git add it. 🤦‍♂️

This adds up and is a waste of time! Even worse if it fails in the build step...

This is where husky comes in! 🐕

husky example where lint error makes it so I cannot commit
Github Link

As you can see husky makes it so that you can run a set of steps before your git commands go through. And it is extremely simple to setup:

  1. Install husky
npm install husky --save-dev
Enter fullscreen mode Exit fullscreen mode
  1. Config
// Inside package.json
// ...
  "husky": {
    "hooks": {
      "pre-commit": "command-or-script-you-want-to-run-here"
    }
  },
//...
Enter fullscreen mode Exit fullscreen mode

Pre-commit means before commit. Pre-push would be before push and so on... Husky rejects your git command if all the steps aren't successful.

And that's it. Best part is that everyone working on a project now has this simple check.

Check out husky

My links:
GitHub: https://github.com/ymirke
Medium: https://ymirke.medium.com/
LinkedIn: https://www.linkedin.com/in/ymirke

Top comments (1)

Collapse
 
harrisgeo88 profile image
Harris Geo 👨🏻‍💻

one of the most useful tools out there