DEV Community

Cover image for There May Not Be a Better Way to Effortlessly Improve Code Quality than Using Prettier Code Formatting

There May Not Be a Better Way to Effortlessly Improve Code Quality than Using Prettier Code Formatting

Nick Scialli (he/him) on June 05, 2020

We all want higher-quality code. With Prettier, you can achieve this with minimal effort. If you enjoy this tutorial, please give it a ...
Collapse
 
kurtz1993 profile image
Luis Hernández

Hey, Nick.

Nice article. Very simple and straightforward. Although I think that you may have missed an important step, or maybe I am doing something wrong here 😕

The steps didn't work for me until I installed the Prettier extension:
marketplace.visualstudio.com/items...

Is this missing in the steps or am I doing something wrong?

Thanks!

Collapse
 
nas5w profile image
Nick Scialli (he/him)

Oh goodness I think you’re right. I’m going to update the instructions now. So sorry and thank you for finding that.

Collapse
 
kurtz1993 profile image
Luis Hernández

You're welcome! 😊
Always happy to contribute in the best way.

Collapse
 
e4emre profile image
Emre

Having an IDE to automatically format code really reminds me of why QBASIC was so great for beginners: because beginner programmers can't be trusted to format their code nicely.

But keep in mind, the formatting of the code has nothing at all to do with code quality. One could have a horrible bunch of crap using what people consider "pretty" syntax. One could also write a very elegant algorithm written with what you consider "ugly" syntax. Whether it be snake case, camel case, all uppercase, or all lowercase, two indents, four indents, tabs, spaces, braces on the same line, braces on different lines, semicolons here or there ... it's very subjective, and it makes absolutely no difference to what is real code quality. I've seen coding horrors that were "beautifully" written. (beautifully, as in: very strictly following a particular set of syntax formatting rules.)

Collapse
 
amitavroy7 profile image
Amitav Roy

Yes, I would agree. Although it is opinionated about a lot of things, I felt in a way those rules mostly make sense and hence I adopted to those rules and it helps.

Collapse
 
omrisama profile image
Omri Gabay

Listen, I like Prettier and I use it in my JavaScript projects.

But I will NEVER use it for Ruby. I'm sorry lmao

Collapse
 
omrisama profile image
Omri Gabay

I didn't even know you could do that until I read this!

Collapse
 
miketalbot profile image
Mike Talbot ⭐

About the only thing you can configure in Prettier is "no semicolons" and 'single quotes'!

We have both of those turned on for our React project.

Collapse
 
nas5w profile image
Nick Scialli (he/him)

Heh, prettier is pretty darn opinionated. I remember requesting the ability to configure something on their GitHub issues and got shot down. Ultimately, the consistency is far more important to me than having it one particular way or another.

Thread Thread
 
miketalbot profile image
Mike Talbot ⭐

Ah I'm going back to the linting wars my team had in 2019.

"Husky! That's just a backdoor to Prettier"

Forward 12 months - it was true, and boy am I happy.

Collapse
 
szymach profile image
Piotr Szymaszek

This is basic IDE functionality, even for Javascript. Is there really a need for third party tool to do this?

Collapse
 
umutakyol profile image
asdsadasf

What ide do that?

Collapse
 
szymach profile image
Piotr Szymaszek

Format code? Netbeans, Jetbrains, all the big ones I think. You can usually set custom rules for formatting per language, and even per language per project.

Collapse
 
savagepixie profile image
SavagePixie • Edited

That's why I prefer using the linter as code formatter instead of installing another package. This way I only have to write one set of rules once.

Collapse
 
mudgen profile image
Nick Mudge

How does it compare to using StandardJS tools?

Collapse
 
xavierbrinonecs profile image
Xavier Brinon

In go, the formatter aligns the key value pairs vertically and I am missing this in JS. If anyone knows a formatter that does this, please shout. LOUDLY.