Formatting JavaScript

I have been doing much research without figuring out how to use Prettier or Beautify to achieve what I want.

First, I want to align colons:
image

Second, I want to format braces like this (first brace on new line):
image

Does anyone know how to do it?

Using some C++ style braces can result in strange errors related to automatic semicolon insertion, beware

The problem with this type of formatting is that other reviewers of your code will not be expecting the JavaScript to be formatted this way. The goal of writing readable code is to make it readable not just you but others who may be reviewing or refactoring your code at a later date.

1 Like

Thanks that is good to know. However, I think the colon alignment would be a good thing to have in JavaScript. It should become standard for object literals according to me.

I can understand that, we could have a script that converts from one format to a commonly accepted format.

I really like the aligned colons. They make my code cleaner. I don’t see reason why that is not standard practice.

I also enjoy aligned colons. I’m not sure how to force that is JS, only a couple of C formatters.

I think ESLint can do it.


Prettier is an opinionated formatter, they intentionally do not allow for many options.