Guilt-free commits
We all did it. We all hate it. And we all need to stop it.
Forgetting to lint and test the code before commiting…
We all did it once. Maybe twice… thrice… more…? No? Just me? Ah.
We are only humans, and humans have limitations. Maybe one day the robot overlords will take over our jobs and pump out perfect code.
But until then, we are still here with our trigger-happy fingers that can shoot code which makes our build pipelines fail.
Well, for you Javascript developers like me, we have Husky.
Husky let’s you automate linting and testing to your commits. It doesn’t let you push changes that fail your lints or tests.
Setup
npm install husky --save-dev
// package.json
{
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm run lint && npm test",
"...": "..."
}
}
}
git commit -m 'Keep calm and commit'
Now, you can be rest assured that you aren’t gonna be one of those guys that go “opps I forgot to test it”… “opps I forgot to lint”… “oops I miscliked”. “opps that was actually my dog, not me”.