Overview

Have you ever come across a situation where your code indentation is not following the project’s style, or where unit tests are breaking in the master branch? These usually happen due to oversight on the part of developers who fail to test them before raising a pull request. Thanks to git hooks these checks can be easily performed before the code is pushed to the Version Control System!

Behold Husky, a tiny JS package for defining and executing git hooks — scripts in a NodeJS project. Inherently, it supports all the basic git hooks except for the server-side hooks. The configs for the package are simple and are defined inside the package.json of the project. This makes Husky a simple way to enforce project-wide git hooks, helping ensure coding standards checks and automating housekeeping tasks.

Highlights

The package expects a simple config, basically a JSON with the key husky inside the package.json. The object with the hooks key inside this contains the definition of scripts for each of the hooks to be implemented. Let’s look at a simple example for executing unit tests before commit and end-to-end tests before allowing to push the code to the VCS:

"husky": {
  "hooks": {
    "pre-commit": "npm run test:unit",
    "pre-push": "npm run test:e2e"
  }
}

#web-development #npm #git #software-development #javascript #react

Husky: An Unpackaged Review
1.45 GEEK