24-Dec

JavaScript

🔥 Prettier Config considered harmful

The best prettier config is no config at all, and I'm about to tell you why

3 min read

·

By Kristofer Giltvedt Selbekk

·

December 24, 2023

I think nothing has improved the day-to-day experience of working on a team more than Prettier did. From going through tons of annoying “Nit: Remember semicolon” or “Two more spaces please” comments on pull requests, formatting is thankfully now a non-issue. Finally we could focus on the bugs in my code instead.

I’m not saying James Long - the inventor of Prettier - is a god or anything, but he definitely deserves a statue somewhere. But one fatal flaw he made was letting people have even a small subset of opinions on what is the “right” way to format stuff.

I’ll die on this hill: The prettiest prettier config is {}. And anything else is stupid.

It’s a cop-out

You’re so lucky, you know that? Somebody did a ton of usability research, and figured out the objectively best way to format code. And you get to use that insight without lifting a finger.

Now, if you do lift a finger, and type in “singleQuote: true”, you’re disagreeing with all of this research. You know better, and you’re about to school your team on what real developers do with their code. Single quotes for life, right? Right.

Adding your own subjective opinions to your prettier config makes your codebase different from everybody else’s. If you skip semi colons or insist on not having spaces between curly braces and what’s inside, you make me have to think and analyze your code.

Instead, just trust the research, and keep that config empty, like the good lord Long intended.

It’s an argument starter

I’m not the only one that’s going to be mad at you for cluttering a pristine prettier config. So will your future team mates. Because even if your entire team is aligned with your misguided views right now, future hires and new consultants will come and disagree with you.

And the worst part is, they might not even share my (objectively correct) view that no config is the best config. They might present their own faulty opinions, like having 120 character print width or using tabs instead of spaces for indentation.

Using the industry default formatting standard saves you from all of this. Nobody in their right mind is going to start arguing for removing technically unnecessary parentheses from arrow functions if you’re using the Industry Standard.

So save yourself and your team from a few arguments – and just keep your config clean.

Nobody really cares (after a while)

I admit it – I was a config clutterer in a previous life. Single quotes, 4 space indentations, you name it, I had strong opinions about it. I loved to argue with my team about what tweaks we should do to the config next, to make it just perfect for us.

Then I switched teams, and I was met with this Industry Standard bullshit. I was livid. And then I moved on with my life. Days later, I didn’t think a thing about double quotes or 2 space indents – I just tapped cmd+s and committed my code.

I’ve spoken to lots of converts just like me. Nobody really cares, even if they really thought they did.

So stick with an empty Prettier config. And start doing actual work.