Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Unexpected handling of lines with less than 100 characters

未关闭
#567 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java
领域
tooling

调研方向

使用报告中所示的 google-java-format-1.9-all-deps.jar 命令行调用,通过 test.java 重现该问题,并比较修改前、修改后和预期的输出。跟踪 formatter 对多行 SQL 字符串的处理行为;完成标准是仅拆分过长的行,而其他较短的行保留其原始格式。

由索引模型根据 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 分钟
30 天内合并 PR
3

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/google-java-format 的其他 Issue

查看 google/google-java-format 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。