Why is Prettier rock solid?

I've always wondered why Prettier is so good. Yes, it learnt from gofmt what to do (note that gofmt doesn't indent, which is the hard part). Yes, it was announced in a real life conference, which helped get the initial momentum behind it.

All that is fine, but what was a bit inexplicable to me is its quality.

  • You might disagree with the defaults (I like them. The only one I disagree with is tabWidth, it should not have been 2 but 4),

  • Or you might find that it is too slow,

But in terms of functionality, it is solid. So far, it has never broken my JS / TS code. Such high quality is rare in the wild west of JavaScript libraries. Indeed, later additions to Prettier itself, like the MDX formatter for Prettier, have huge bugs that make them unreasonably risky for anything non-trivial. So how come Prettier's core formatters - HTML / CSS / JS / TS - are all rock solid?

Today, I got the answer. This is Prettier's original author writing about it:

Prettier is a perfect example of this. I knew what I wanted but I had no idea how to implement it. After a little research I found this paper and after a few days I knew exactly what I needed to do. I had something basic working in a week. If I ignored previous research it would have taken a lot longer.

You know which paper it links to?

A prettier printer, by Philip Wadler!

Joyce Kilmer and most computer scientists agree: there is no poem as lovely as a tree.

Haskellers would recognize both the paper, and the author. Of course, this is not to take away from the authors of Prettier and the years of work that has subsequently gone into it – I'm just chirping about how Haskell continues to enrich my life even when I'm not using it.

Manav Rathi
Feb 2024