Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set max line length for google formatter #1563

Closed
tbw777 opened this issue Feb 8, 2023 · 7 comments
Closed

Set max line length for google formatter #1563

tbw777 opened this issue Feb 8, 2023 · 7 comments

Comments

@tbw777
Copy link

tbw777 commented Feb 8, 2023

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?

@nedtwigg nedtwigg changed the title No max line length for google formatter Set max line length for google formatter Feb 8, 2023
@nedtwigg
Copy link
Member

nedtwigg commented Feb 8, 2023

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

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

@simschla
Copy link
Contributor

simschla commented Mar 9, 2023

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?

@jbduncan
Copy link
Member

jbduncan commented Mar 9, 2023

@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.

@nedtwigg
Copy link
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.

@simschla
Copy link
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.

@pks-1981
Copy link

pks-1981 commented Oct 3, 2023

max-line-length

Hello
How configure it on maven?

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

???

@simschla
Copy link
Contributor

simschla commented Oct 3, 2023

@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
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

5 participants