Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unexpected handling of lines with less than 100 characters

オープン
#567 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
tooling

調査の方向性

レポートに示されている google-java-format-1.9-all-deps.jar のコマンドライン呼び出しを使用して test.java で問題を再現し、変更前、変更後、期待される出力を比較します。複数行の SQL 文字列に対する formatter の動作を追跡します。完了の条件は、長すぎる行だけが分割され、他の短い行は元のフォーマットを維持することです。

索引モデルが issue の本文から書いたものです。

説明

I have some quite large sql multiline string and when one line is over 100 characters it will re-format it onto 2 lines. While I believe this is the correct behaviour to split this long line, it also re-formats all of the other lines of the String which I don't think should happen as they are under 100 characters long, therefore I think this is a bug.

NB: Because of https://github.com/google/google-java-format/issues/566 you can only see this happening using the jar on the command line as per the example below:

before - unformatted file:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  l.some_really_long_column_name    AS some_really_looooooooooooooooooooong_column_name, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, ";

  public test() {
    int x=1;if(x==1){x=2;}else{x=3;}
  }

}

apply google java formatting:

/tmp $ java -version
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)
/tmp $ cksum ~/lib/google-java-format-1.9-all-deps.jar
2002751029 3404610 ~/lib/google-java-format-1.9-all-deps.jar
/tmp $ java -jar ~/lib/google-java-format-1.9-all-deps.jar ./test.java

after - formatted by google java formatter:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT   customer_id             AS customer_id,   customer_id             AS customer_id, "
          + "  customer_id             AS customer_id,   customer_id             AS customer_id,  "
          + " customer_id             AS customer_id,   l.some_really_long_column_name    AS"
          + " some_really_looooooooooooooooooooong_column_name,   customer_id             AS"
          + " customer_id,   customer_id             AS customer_id, ";

  public test() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}

Expected - this is what I think google java formatter should do:

package x;

public class test {

  static final String MY_SQL_QUERY =
      "SELECT "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, "
          + "  l.some_really_long_column_name    "
                 + "AS some_really_looooooooooooooooooooong_column_name, "
          + "  customer_id             AS customer_id, "
          + "  customer_id             AS customer_id, ";

  public test() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}
主要言語
Java
スター
6.2k
フォーク
936
平均マージ
6分
マージ済み PR(30日)
3

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/google-java-format のほかの issue

google/google-java-format の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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