google / google-java-format

Reformats Java source code to comply with Google Java Style.
Other
5.55k stars 851 forks source link

Wrong indentation on if-then with comments #1009

Open radumereuta opened 9 months ago

radumereuta commented 9 months ago

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.

cushon commented 9 months ago

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;
sabi0 commented 7 months ago

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.