spotless icon indicating copy to clipboard operation
spotless copied to clipboard

google-java-format: Reflow long strings does not give same output

Open blacksails opened this issue 1 year ago • 4 comments

The following input

public class Test {
    private String longString = "asdf asdf asdf asdf asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Becomes

public class Test {
    private String longString =
            "asdf asdf asdf asdf"
                + " asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Using google-java-format AOSP

When using the gradle task ./gradlew spotlessApply this becomes

public class Test {
    private String longString =
            "asdf asdf asdf asdf"
                    + " asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa";
}

Gradle version: 8.10.2 Spotless version: 6.25.0 and 7.0.0.BETA4 (same result) Operating system: macOS 15.0.1

Spotless config:

extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
    java {
        googleJavaFormat("1.24.0").aosp().reorderImports(true)
    }
}

blacksails avatar Nov 11 '24 10:11 blacksails

This is a bug in GJF, not Spotless. You'll have to report it there.

nedtwigg avatar Nov 11 '24 22:11 nedtwigg

@nedtwigg Why is this a GJF and not a spotless bug? I would always expect spotless to do the same as GJF.

What GJF does to long strings also complies with the googla java style guide. https://google.github.io/styleguide/javaguide.html#s4.5.2-line-wrapping-indent. So I cant really put up a bug report about it there?

blacksails avatar Nov 18 '24 09:11 blacksails

I would always expect spotless to do the same as GJF.

I would expect that too, and so far I don't have any evidence that it doesn't. Have you tried using GJF with AOSP on this same file?

nedtwigg avatar Nov 18 '24 16:11 nedtwigg

Have you tried using GJF with AOSP on this same file?

@nedtwigg Sorry if it wasent clear from my issue, but that is exactly what I have done and shown in the snippets in the issue. First snippet is input, next is GJF with AOSP, last is Spotless with GJF and AOSP.

blacksails avatar Nov 20 '24 11:11 blacksails