Prettier, a uncompromising code formatter

Code formatting is the most known instance of bikeshedding: everyone has a different opinion on it and nobody is willing to compromise. Do you remember the hours-long discussions on using tabs versus spaces? Where to add empty lines? Alignment of fields? For some years now, many languages provide their own code formatter, Go has gofmt, Rust has cargo fmt, some have a standard-by-usage, Python has black, Scala has scalafmt, but nothing was appropriate for the web languages in general.
Let’s welcome prettier, a newcomer in the formatting world, aimed at precisely theses languages.

Among others, it supports JavaScript, TypeScript, JSON, HTML, Angular, CSS, Markdown, YAML, TOML, XML, enough for any webapp. It works with most editors, Vim, Emacs, Atom, VS and JetBrains’ IDEs. And finally, it is used by some very big project: Dropbox, ReactJS, Webpack & Facebook. A friendly newcomer and well accepted already.

One of the most interesting features it has, is that it doesn’t compromise: you can’t (much) configure it. As such, no more endless discussion on it, just use it™©®! It has many advantages, such as splitting a function call when too many arguments are passed. Or merging an object initialization if it is small enough.
Overall, formatting is not though anymore, just done.

I use it in my new web projects, where it’s really easy to integrate. First, set it up in your code-editor, then make a first pass with (at project root) (it will only format known files):

npx prettier --write .

As your branch will be quite hard to rebase, do merge other PRs before that and sync with your team as when it is best to apply this new coding guideline. You’ll also need to add the next line to your CI:

npx prettier --check .

And you’re done, formatting is done by editors directly, checked by the CI, and everyone can read it.
Now, get on with more interesting programming tasks than dealing with how to format code, and don’t argue with it anymore.