Just automate syntax formatting

A path amid rocks and snow-covered trees. There's a rope handrail next to the path.

Fighting over syntax formatting in code review is, mostly, waste of time. Having consistent formatting is great for readability, but code review is not the right place to enforce it. To keep code reviews fast and smooth, you’ll want to focus on high-impact issues. With formatting, the returns diminish quickly.

Instead, you should use computers to enforce consistent formatting. There are two ways to go about it:

Use a code formatter tool. Try to find a fast one and configure everybody’s editor to run it on save, or use a git pre-commit hook. If you write Go, use gofmt. If you write JavaScript, I hear Prettier is a popular one.

Use matching editor configurations. If your programming language doesn’t have a good code formatter, your next best bet is to configure everybody’s editors to match each other as well as possible. This solution doesn’t really scale, but for small teams it’s feasible. An EditorConfig file can help a bit.

For example, there’s no canonical formatter for Clojure. Matching the config is simple if everybody uses the same editor, but we’ve managed to get close enough with Cursive and clojure-mode.

What do we do when the editor config mismatch causes unnecessary code reformatting? We let it be.

It’s better to accept some code churn than to fight over indentation in code review.

See also my other posts about code review.

Comments or questions? Send me an e-mail.