Skip to content

Google Java Format doesn't reflow long strings #924

Closed

Description

@tbroyer

Using either Maven (2.12.3) or Gradle (5.14.3), with various versions of Google Java Format (including the latest, 1.11.0), Spotless doesn't reflow long strings.

This is similar to google/google-java-format#566 and google/google-java-format#642 for the GJF IntelliJ and Eclipse plugins.

Spotless would have to explicitly call StringWrapper.wrap(). This has been added in GJF 1.8.

Maybe there should be a configuration flag to disable it, similar to GJF's command-line --skip-reflowing-long-strings.

Activity

  1. nedtwigg commented on Sep 1, 2021

    @nedtwigg
    Member

    Because this would be a behavior change, it would need to be optin. E.g. googleJavaFormat().reflowLongStrings(true). Happy to merge a PR for it.

  2. tbroyer commented on Sep 2, 2021

    @tbroyer
    ContributorAuthor

    Fwiw, when unused imports removal and import ordering were added (in 3.0.0, GJF being available since 2.2.0), it wasn't added as an opt-in. Though I could understand making it opt-in until the next major release.

  3. nedtwigg commented on Sep 2, 2021

    @nedtwigg
    Member

    it wasn't added as an opt-in

    Just wanna make sure I understand correctly. If I make a table of GJF command-line jar versions and whether they reflow strings, it would look like this:

    • before 1.8: does not reflow long String literals
    • 1.8 and later: does reflow long String literals

    And if I made a table of GJF in Spotless, the table would look like this:

    • all combinations of Spotless and GJF: does not reflow String literals

    Is that correct? If so, then I think from the perspective of Spotless users, we definitely want the reflowLongStrings(false) to be the default behavior, now and in the future.

    I can see a case for switching the default to match GJF in a future breaking version, so that people switching from CLI to Spotless have better defaults. But Spotless has a lot of users, and the promise we have made to them is "if you adopt us, you can think about formatting less, and when other formatters misbehave or change their defaults, we will insulate you from that." Helping people adopt is good, but most of all I want to help the people who have adopted to forget that we exist, and one way we do that is we minimize changes of defaults.

  4. tbroyer commented on Sep 2, 2021

    @tbroyer
    ContributorAuthor

    Is that correct?

    Yes.

  5. added 2 commits that reference this issue on Sep 4, 2021
    77e53a6
    d79b5f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions