google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Wrong indentation on if-then with comments

Open radumereuta opened this issue 1 year ago • 2 comments

Comments at the end of this if makes the then block to not get indented.

                            if (prd.source()
                                .isPresent()) // exclude generated productions like casts
                            prd = null;

image Line 331. IntelliJ reports this as well. I think the problem comes from the if condition that got split into two lines. If I move the comment to a separate line, then indentation works as expected.

radumereuta avatar Dec 12 '23 13:12 radumereuta

The style guide requires braces for if statements: https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used (#938 is slightly related)

So I agree this isn't a good formatting and we'd probably prefer something like the following, but this is also low priority because it's already not following the style guide:

  if (prd.source()
      .isPresent()) // exclude generated productions like casts
    prd = null;

cushon avatar Dec 12 '23 23:12 cushon

I see this also with a condition on a single line: image

I.e. the line break in the condition is likely not the cause.

sabi0 avatar Jan 28 '24 08:01 sabi0