Cloud Parts

Formatters

Tools that reprint code in one canonical layout, so style never comes up in review.

How they work

A formatter parses the code and prints the tree again from scratch, wrapping lines at a set width. Because it reprints everything, it replaces the whole family of formatting rules linters used to carry (line length, spacing, comma style) and leaves linters the rules that catch bugs. Black adds a safety check that the reformatted code still parses to an equivalent tree.

The point is to stop arguing. Go’s gofmt formats code automatically, and a 2013 survey found about 70% of Go packages already formatted with it. Prettier (JavaScript, 2017) keeps options to a minimum on purpose: more options would turn style debates into debates about options. Black calls itself “uncompromising” and picks 88 columns by default.

Formatters in one language tend to converge on the same output. Ruff’s formatter targets Black compatibility and formats more than 99.9% of lines identically on Black-formatted projects such as Django and Zulip, so teams can switch without a noisy diff.

Sources

Improve this page on GitHub