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

One Line if statements - Don't add extra line #938

Open
BhavyaaArora-08 opened this issue May 4, 2023 · 2 comments
Open

One Line if statements - Don't add extra line #938

BhavyaaArora-08 opened this issue May 4, 2023 · 2 comments

Comments

@BhavyaaArora-08
Copy link

Desired :

if(something) doSomething()

Formatter updates it to :

if(something) 
       doSomething()
@lowasser
Copy link
Contributor

lowasser commented May 4, 2023

Neither of these are actually compliant with Google Java Style, which is what google-java-format generates, but the second one is closer (within g-j-f's constraint of only modifying whitespace).

As per https://google.github.io/styleguide/javaguide.html#s4.1-braces and https://google.github.io/styleguide/javaguide.html#s4.3-one-statement-per-line, the required format to adhere to Google Java Style is

if (something) {
  doSomething();
}

@MrThaler
Copy link

but the second one is closer (within g-j-f's constraint of only modifying whitespace)

I agree that the second one is closer. However, it seems to me that the first one is what actually happens, at least with versions 1.13.0 and 1.18.1 under Eclipse - the formatter removes the linebreak and shoves it all into a single line.

(I also agree that brackets are what is "correct" according to the Google Java Style, but as the formatter needs to do something with the statement it should probably do the closer variant)

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

No branches or pull requests

3 participants