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

Formatting overly long lines does not respect `--lines` range restriction

Open jdcormie opened this issue 1 year ago • 1 comments

Let Test.java be:

class Test {
  void foo() {
    // Columns:
    //   1         2         3         4         5         6         7         8         9
    // ..0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
    System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  }
}

What I did: $ google-java-format --lines 1:1 Test.java | diff Test.java - What I expected to happen: No diff, since line 1 is already correctly formatted. What actually happens:

6c6,7
<     System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
---
>     System.err.println(
>         "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

jdcormie avatar Jun 18 '24 22:06 jdcormie

Hi, @cushon I've been getting this issue while using google-java-format.py as it uses --lines to format the git-diff.

Can I try to work on the fix?

sugamadhiakri avatar Jul 29 '24 18:07 sugamadhiakri