DEV Community

chase
chase

Posted on

The easiest way to have consistent looking code

One of the hardest things for me as a programmer with terrible ADHD is making sure that my code always looks clean and consistent. I hate finishing a project and then having to go back and make all of the code look pretty, it's like torture to me. But now, I can leave all of that pain in the past. Introducing the newest extension to my VSCode roster... Prettier.

Allow me to explain what this amazing extension does. Let's say you have some code that just looks... messy. No shame in it, we all write ugly code from time to time.
ugly code example
See? That's pretty disgusting looking if you ask me. Now you could go back and format that all by hand, wasting precious time, or you could just relax and let Prettier do it for you. By just pulling up your command palette and looking for the "Format Document" option, you can pick Prettier as your formatter and make this document look... prettier.
pretty code example

Prettier is highly customizable and has add-ons out there for a multitude of programming languages, including PHP, Ruby, JavaScript, HTML, CSS, Tailwind, etc. You can also have Prettier format your code every time you save if that's something you're interested in. If you're interested in other great VSCode extensions, you should absolutely check out my other blog post that talks about some of my favorites. Hopefully this extension saves you millions of hours of frustration, as it has done for me.

Top comments (1)

Collapse
 
nlxdodge profile image
NLxDoDge

Great post, but also do note that this only works for you local machine.

If, in the future you work with other people or with an open source project, everyone needs the same plugin and code environment (which might not always be the same, some people might use Sublime, VIM, EMACS or Webstorm etc.)

I would recommend to pick a linter for the language that you use, and to store the configuration in your project. That way when you run the linter or a build/dev build. No matter the environment, the code will always be formatted the same 😎.
(For javascript for example you can use ESLint, or for Java you can use the Maven Formatter Plugin that we use).