Skip to content

Set max line length for google formatter #1563

Description

@tbw777

Cant set max line length as in https://github.com/talios/googleformatter-maven-plugin
Is any solutions for this exist? Other formatters with googlse style or else?

Activity

  1. changed the title [-]No max line length for google formatter[/-] [+]Set max line length for google formatter[/+] on Feb 8, 2023
  2. nedtwigg commented on Feb 8, 2023

    @nedtwigg
    Member

    If gjf was converted to a compile-only integration, as in

    Then this would be pretty easy to implement. PRs welcome.

  3. simschla commented on Mar 9, 2023

    @simschla
    Contributor

    I've converted GJF to a compile-only integration. To reduce complexity, I would suggest that we'll require GJF of at least version 1.8 (which was released back in May 2020). Before that, we would have two API changes that would require to have specific compile-only variants. Since that version is years old, I don't think any spotless user would have an issue with that requirement.

    After having converted GJF to a compile-only dependency, I've tried to introduce a configuration for the max-line-length. GJF however has taken every measure, for this property to not be changeable, as can be seen here:

    https://github.com/google/google-java-format/blob/1a0065696b4f408313dbd24f9d6606d758e98868/core/src/main/java/com/google/googlejavaformat/java/Formatter.java#L89

    They've decided to make this a public static final int that gets assigned on declaration. So even with (ugly) reflection, the value cannot be changed, since the compiler does inline this value wherever it is used within the gjf lib.

    It was possible to change this value up to GJF Release 1.7 by doing some ugly wrapping of the JavaFormatterOptions class at this location:

    https://github.com/google/google-java-format/blob/69e2efccf9938cfb08b1d5315ad61ca4484bbd0a/core/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java#L60-L64

    This is, ultimately, what the aformentioned maven-plugin does:
    https://github.com/talios/googleformatter-maven-plugin/blob/2034133fe14f0ee928c6942cd037f1fbd52f0abd/src/main/java/com/theoryinpractise/googleformatter/GoogleFormatterMojo.java#L142-L146

    This approach, however, is no longer feasible, as it is only working for GJF Versions ≤ 1.7.

    TL;DR: it is not possible to make GFJ's max-line-length property configurable. Which means this feature request cannot be satisfied.

    @nedtwigg Given the above, should I create a PR to merge the transition of GJF to a compile-only dependency, or would you rather keep it "the old way" using reflection?

  4. jbduncan commented on Mar 9, 2023

    @jbduncan
    Member

    @simschla I just wanted to say how bloomin' impressed I am by the time and effort you've spent investigating all this and writing it down, so well done!! 👏

    I'll leave it to @nedtwigg to decide if the compile-only dependency work is worth merging in.

  5. nedtwigg commented on Mar 10, 2023

    @nedtwigg
    Member

    A GJF conversion to compile-only which drops support for pre-1.8 is very welcome, thanks @simschla!

    I apologize for sending a wild goose-chase regarding max-line-length. I'm going to close this issue since it appears impossible to implement.

  6. simschla commented on Mar 17, 2023

    @simschla
    Contributor

    I apologize for sending a wild goose-chase regarding max-line-length. I'm going to close this issue since it appears impossible to implement.

    No worries, as it turns out, there is always something to be learned, even if the result is finding out, that something is not possible... 🤔

    I've created #1630 to convert gjf to a compile-only dependency.

  7. pks-1981 commented on Oct 3, 2023

    @pks-1981

    max-line-length

    Hello
    How configure it on maven?

    <googleJavaFormat>
    <version>1.11.0</version>
    <style>AOSP</style>
    </googleJavaFormat>
    

    ???

  8. simschla commented on Oct 3, 2023

    @simschla
    Contributor

    @pks-1981 As of now, this setting is not possible due to design decisions on Google's side.

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