Js-beautify: Add semicolons after statements

Created on 23 Feb 2015  ·  2Comments  ·  Source: beautify-web/js-beautify

JS's funny semicolon insertion can cause non-obvious bugs.

function foo() {
    return
    1
}

returns undefined.

For this reason, it's considered best practice to explicitly end statements with a semicolon.

It would be nice if js-beautify did this.

In this case, it would format it as

function foo() {
    return;
    1;
}

(FYI, uglifyjs -b does exactly this.)

declined

Most helpful comment

I might disagree with with whitespace categorically being "not code" and everything else being "code".

The presence and type of whitespace can alter the behavior of program as much as a semicolon. (e.g. placing a newline in return 1 is highly significant, just as placing a semicolon.)

But I'll concede that this would be non-trivially different than what js-beautify does now :(

All 2 comments

Out of scope, sorry.

The beautifier is designed to be purely a code reformatter, it modifies only white space and does no folding or modifying of the code itself.

I might disagree with with whitespace categorically being "not code" and everything else being "code".

The presence and type of whitespace can alter the behavior of program as much as a semicolon. (e.g. placing a newline in return 1 is highly significant, just as placing a semicolon.)

But I'll concede that this would be non-trivially different than what js-beautify does now :(

Was this page helpful?
0 / 5 - 0 ratings