ESLint helps you to format your code by applying custom rules. But if a developer of your team doesn’t lint his code, you will probably have a “dirty” code in your git repo…
…that’s when husky happens to help you.
“Husky can prevent bad
git push and more 🐶 woof!”. It helps you to create simple git hooks. A git hook is a way to run custom scripts when a specific action occurs, example:
- And more
Let’s see how Husky will help us 😎
Husky is a simple
npm package, so we can install it very easily:
yarn add -D husky
Here we are installing it as a development dependency.
Once the package installed, you need to edit your
package.json file and add these lines (for example):
These two hooks will run test scripts when committing and pushing to your server.
You can see all the git hooks here.
There is no special action to do. Your hooks will be triggered when doing the provided actions. Such as:
git commit -m "Trigger pre-commit hook 🤓"
So you can add multiple triggers to run scrips like ESLint…
Husky will help you to run scripts when doing specific actions (e.g: Pre-commit -> lint -> commit; Pre-push -> lint -> Push.)
You can find my other articles and follow me here. Thanks for reading, I hope you learned something new today 🚀
Automate your React Native App with Fastlane
Simplify Screenshots, beta deployment, app store deployment and signing in your React Native App 🚀