Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semicolons after statements #626

Closed
pauldraper opened this issue Feb 23, 2015 · 3 comments
Closed

Add semicolons after statements #626

pauldraper opened this issue Feb 23, 2015 · 3 comments

Comments

@pauldraper
Copy link

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.)

@bitwiseman
Copy link
Member

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.

@pauldraper
Copy link
Author

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 :(

@slorenzot
Copy link

The semicolin is not necesary on current JS versions, but is a good practice for back compatibility, it would be a good setting for being include

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants