RSS Amplifier

BeyondTheCloud.dev · Dec 10, 2023

Format your code with formatting tool

0
Sign in to vote or save

This page did not load. You can still read it on the original site — the toolbar below keeps your place in the directory.

Code formatting across the project should be consistent. Choose a formatting tool, configure it, and stick to it no matter what.

Introduction

Do you need a Code Formatting Tool? Maybe code formatting is just a preference?

Let’s figure it out.

Issue

Unformatted code leads to problems.

Let’s say you agree with the statement: "Code formatting is just a preference." Each developer on your project has different preferences, different formatting tools, or maybe they format code themselves.

What will happen when you try to change something in an existing class?

A lot of changes.

not formatted code

Try to find where your changes are.
Try to stage only your small part.

It’s hard, right?

Best Practice

The rule is simple:

Code formatting across the project should be consistent.
Choose a formatting tool, configure it, and stick to it no matter what.

You can have different formatting preferences, but:
Team/Consistency > My preferences.

When common formatting is applied for the whole project, code is much easier and faster to read and understand. Developers know what to expect. It also makes our work much more efficient. Take a look at the diff. How easy is to figure out where your change is?

formatted code

The most popular code formatting tool is Prettier, however there are some alternatives such as:

Use formatter, but don’t forget to install eslint as well.


If you have any questions feel free to ask in the comment section below. 🙂

Was it helpful? Check out our other great posts here.


References

Read on blog.beyondthecloud.dev

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.