google / google/google-java-format

Running with --replace does not converge

オープン
#562 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
6.2k
フォーク
937
平均マージ
6分
マージ済み PR(30日)
3

説明

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!

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。