How to Make Your Code Prettier

I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...

I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
There is a PHP plugin for Prettier: https://github.com/prettier/plugin-php
Please let me know how it is, if you give it a try:)
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

When you are new to programming, you’re focused on making your code work—not on making it look pretty. If you pay close attention to other people’s code, such as open-source projects and example snippets in books or blogs, you will notice a few things:
Many projects have even formal style guides, explaining how those things should be done in the project.
Let’s see how to make your code up to the online standards of beauty!
Great question! Aren’t we writing code for machines, and they don’t care about the looks? Yeah, machines don’t care, but code is consumed by humans a lot too—and for them, those small details can make a pretty big difference.
If you spend 5h per day reading code, you want the experience to be as frictionless as possible. Unexpected styling choices call attention to things that don't matter, disturbing the reader for no reason. Some programming languages—such as Python—made indentation a meaningful part of the language syntax to enforce reasonable indentation. A similar approach was brought to the JS world with CoffeeScript—at one point a pretty popular language compiled to JS.
It’s so painful to review branches that combine:
Just take a look at the screenshot from GitHub Pull Requests:

vs.

In both cases, the meaningful part of the change is the same: I remove sourceMap: true.
Finding what changed can be difficult in a noisy diff, let alone evaluating the impact of it. Imagine reviewing such a change in a file that is 1000 lines instead of 10.
Luckily, we don’t have to study the style guides anymore; we have tools that apply them automatically to our codebase. Many of those tools are opinionated—they leave very limited configuration options, so you have to accept the opinions of their authors.
Prettier is a frontend-oriented code formatter. It supports:
And some more with plugins.
Prettier is committed to ending the style guide debates. Therefore, the configuration options are limited—there are few things you can tweak, but by using Prettier, you mostly outsource the style guide decisions to its author. Prettier is widespread in the JS community: it’s used by core teams of React, Vue, and Angular. Styling your project with it will make your code look like everybody else’s —which is a good thing, keeping a consistency across many projects people work on.
Similar thing for Python code. I used it a few times while helping out with a Python project. I was pleased to have a tool that maintains the formatting for me—I had no interest in learning much Python, but I care about consistency enough to make sure my changes are in line with the code style guide the project uses. Thanks to Black, I kept my code neat, without thinking twice about what the conventions are in the Python community.
I don’t know similar tools in other languages, but I would follow those guidelines if I were looking for some tool:
What tools do you use for formatting your code—in JavaScript or other languages?