I Built a Hook
The React 16.8 alpha introduces hooks! I’ve used them, and they’re everything I’ve dreamt about for composing state and side effects.
But that’s not what I’m talking about today. I’m talking about Git hooks.
Specifically, I’m talking about using a git pre-commit hook to automatically format all my code.
Why would I want to do this? It starts with
A few years ago, I was writing Golang (Go).
One thing I loved about Go was the opinionated, automatic formatting of code with
It was baked into the language.
There were no configuration options.
Most importantly, it eliminated an entire category of preference motivated bike-shedding that gets in the way of shipping useful tools to people.
I’ve run into one hurdle formatting Ruby code.
It’s comparatively slow.
go fmt and
prettier have been fast enough to format-on-save in VS Code,
standardrb seems to be just slow enough to make the experience jarring.
So with Ruby, I decided formatting my code on commit is good enough.
I borrowed from prettier’s example pre-commit hook, and built the equivalent for
I then combined the two to make my one pre-commit hook to rule them all.
They’re all wrapped up in a gist. I’ll probably be dropping this into many of my projects going forward. So far as an individual contributor, it just works!