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

Removing unused imports leaves extra blank line after package statement, isn't idempotent

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

还没有人认领这个 Issue。

评估

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

调研方向

使用 inital_class.java 和所示的 --replace 命令,通过 google-java-format-1.9 重现该问题,然后再次运行一次,以确认输出发生变化。跟踪 formatter 对 package 和已移除 import 的空行的处理;当重复格式化同一个文件会产生完全相同的输出时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug

I have a class that if I format it twice with google java formatter it will produce 2 different results. This is not what I would expect - I would think that you can format a file any number of times and google java formatter should always produce the exact same result. Is my assumption wrong ?

Here is an example:

original class:

$ cat inital_class.java
package com.sun.something;

import com.x;
import com.y;
import com.z;

public class MockedLiveServiceExecutionContext {


}
$

If I then format it I get this:

$ java -jar ./google-java-format-1.9-all-deps.jar --replace inital_class.java
$ cat inital_class.java
package com.sun.something;


public class MockedLiveServiceExecutionContext {}
$ cat inital_class.java | cksum
42955951 79
$

And if I format it again I get this (it's removed an extra space):

$ java -jar ./google-java-format-1.9-all-deps.jar --replace inital_class.java
$ cat inital_class.java
package com.sun.something;

public class MockedLiveServiceExecutionContext {}
$ cat inital_class.java | cksum
2486624596 78
$
主要语言
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 摘要。