js-beautify
js-beautify copied to clipboard
Allman style formatting for JavaScript files
Description
Allman style formatting for JavaScript required as below:
- start and end braces on separate lines
- start and end square brackets on separate lines
- array items on new line
I'd also want to use Allman-8 which practically means that you use 8 space width tab characters and indent everything with a single tab character instead of 1 or more spaces.
Note that there's one special case. Following doesn't work in JavaScript because of ASI rules which have a special exception for return
statement:
return
{
status: "successful",
user:
{
id: "9abf38a3-c2f5-4159-a1be-0eccbc1b2349",
label: "John Doe",
}
};
because it will be interpreted as (note the semicolon after return!):
return;
{
status: "successful",
user:
{
id: "9abf38a3-c2f5-4159-a1be-0eccbc1b2349",
label: "John Doe",
}
};
You have to either use syntax
let response =
{
status: "successful",
user:
{
id: "9abf38a3-c2f5-4159-a1be-0eccbc1b2349",
label: "John Doe",
}
};
return response;
or
return {
status: "successful",
user:
{
id: "9abf38a3-c2f5-4159-a1be-0eccbc1b2349",
label: "John Doe",
}
};
instead.
I personally think that naming the result structures is more readable in any case so I use that.