Well, I’m sold. The README on GitHub says that I only need to install husky and add a husky object to package.json. It also states that all git hooks are supported. You can find a list of them all on the official git documentation here.
How to use it?
Everything seems to go smoothly so far, but as I know from experience, README’s seems fine and dandy when you read it. The problems occur when you are going to put it into practice. But, we shouldn’t jinx it, let’s keep calm and stay positive.
We are now entering a parallel universe with a ton of bugs to squash. Let’s say I have an important JSON document that I want to validate before I commit my changes. I do not want to commit an invalid version of that document because it will break my CI builds.
I start with creating a directory and running git init in my console to initialize a git repository. After that, I run npm init to create a package.json.
After that, I add the critically JSON document as described further up. I will name the document settings.json and it looks like this:
Try not to focus on the content of this JSON file as this is purely foobar content. As we were saying earlier, the developer shouldn’t commit an invalid JSON file and we can also say they are not allowed to use an api_version that is not defined in the api_versions list.
After that, we should add and install husky like so npm install husky --save-dev in the console. When that is done we can add a property to our package.json so it looks like so: