Optional Pre-commit hooks for Husky

Status: ideation
Share: Twitter

Recently on twitter there was a thread about precommit hooks and whether or not they should be required:

https://mobile.twitter.com/kentcdodds/status/1137336585907662848

Precommit checks can help you move faster in CI but they can be stifling if they're required.

One of the things we've done at Webflow is to make a few things (like prettier formatting) a default pre commit hook and provided a way for devs to include the checks they care about and easily disable those by commenting them out.

Here's how we do it:

  • husky runs lint staged on pre commit
  • lint staged is a js file that checks for a git ignored file and requires it if it's present, then merges our default config with the local Developer config
  • we provide an examples config so that people can cherry pick the checks they care about from it

Would you be interested in seeing the code for how we do this? If so, send me a tweet at @chaseadamsio and I'll bump this post up in my list of posts to work on.

Did you enjoy this article? Share it on Twitter!
chaseadams.io is powered by GatsbyJS, GitHub & Netlify.
Deployed commit of chaseadams.io is f1a4e1
👋 Say Hi!