google / google/google-java-format

Running with --replace does not converge

Ouverte
#562 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
6.2k
Forks
937
Merge moyen
6 min
PR mergées (30 j)
3

Description

I'm trying to integrate this tool into my codebase at work, and I came across a curious situation where `google-java-format` will always add an empty comment. This is probably better shown than explained, so here's a minimal reproduction:

```sh
$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)

$ java -jar /tmp/google-java-format-all-deps.jar -version
google-java-format: Version 1.9

$ cat /tmp/GoogleJavaFormatTest.java # the original
public class GoogleJavaFormatTest {
//String testString = " thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java
public class GoogleJavaFormatTest {
// String testString = "
// thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java
public class GoogleJavaFormatTest {
// String testString = "
//
// thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}

$ java -jar /tmp/google-java-format-all-deps.jar --replace /tmp/GoogleJavaFormatTest.java
$ cat /tmp/GoogleJavaFormatTest.java
public class GoogleJavaFormatTest {
// String testString = "
//
//
// thisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedropppedthisisnotaHYPERLINKandsoitshouldntbetruncatedinststeaditshouldbedroppped \"http://www.google.com/imgres?imgurl=http://www.mancusogroup.com/images/war%0d%0aehouse_icon.gif&imgrefurl=http://www.mancusogroup.com/&h=60&w=60&%0d%0a;sz=0&tbnid=LvtwKa3nug4J::&tbnh=60&tbnw=60&prev=/images%3Fq%3DWA%0d%0aREHOUSE%2BICON&hl=en&usg=startingfromherestuffshouldstarttobetruncatedandremoved\"http://www.mancusogroup.com/";
}
```

As you can see, each time I run with `--replace` is adds a new line just containing ` //\n`. I have no idea why this particular string is breaking it -- I tried others and they didn't seem to break it.

Please let me know if there's any more information I can provide!

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.