Eliminating code formatting discussions with Prettier

I've been using Prettier for a few months now, and I cannot imagine how I could have worked without it. Prettier is an opinionated code formatting tool that reformats your code on save. What a time saver:

  • No more code formatting discussions.
  • When writing, there is no need to worry about code formatting. Formatting is done automatically.
  • Simple to setup, with integration with most editors & the git pre-commit hook.

Prettier supports many popular languages out of the box, others via unofficial plugins. Although it is geared towards the Javascript ecosystem, it also supports backend languages, such as Markdown, JSON & YAML, shell script, SQL. Support for some backend languages is missing, though, such as for Scala & Clojure. Support for Python has been discontinued in favor of Black.

Prettier comes with a tradeoff, though: it is opinionated. If you decide to use it, you eliminate the personal preference from the equation. However, this is the selling point of Prettier: to have a fast, simple & consistent way to resolve code formatting issues all at once. If you ask me, opinionated code formatters are an immediate hit in the important & long-term productivity quadrant.

By far, the biggest reason for adopting Prettier is to stop all the on-going debates over styles. It is generally accepted that having a common style guide is valuable for a project and team but getting there is a very painful and unrewarding process. People get very emotional around particular ways of writing code and nobody likes spending time writing and receiving nits.

Prettier docs (from Why Prettier?)

On top of an opinionated code formatter, you can add a linter to further bullet-proof your code style.


-

If you need help with building the tech products get in touch.