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

Ignore line-wrapping-only changes #817

Open
vibhorgoswami opened this issue Mar 17, 2021 · 4 comments
Open

Ignore line-wrapping-only changes #817

vibhorgoswami opened this issue Mar 17, 2021 · 4 comments

Comments

@vibhorgoswami
Copy link

While using spotless for Android, we run in to an issue where Android Studio line wrapping is overridden with spotless. There is no API exposed for changing this so that we can synchronize Android studio line wrapping with Spotless line wrapping.
The formatting of java code is being set to googleJavaFormat(1.8).aosp() and having a customizable line wrapping would help with unwanted git changes issues.
java { target '**/*.java' targetExclude '**/generated/**' googleJavaFormat('1.8').aosp() removeUnusedImports() trimTrailingWhitespace() indentWithSpaces() endWithNewline() }

@jbduncan
Copy link
Member

jbduncan commented Mar 17, 2021

It's known that the formatting of google-java-format differs to IntelliJ's (and thus Android Studio's). It's in fact a consequence of the google-java-format team's goal to make a formatter that was more flexible for them than IntelliJ's formatter was when google-java-format first came into being.

I've just seen that @nedtwigg labelled this as "won't fix" and I can see why...

@jbduncan
Copy link
Member

Never mind, I was too quick re. the "won't fix" comment! Apologies!

@nedtwigg nedtwigg changed the title Support for Android Studio line wrapping Ignore line-wrapping-only changes Mar 17, 2021
@jbduncan
Copy link
Member

I think people have managed to "hack" the internals of google-java-format in the past to allow the line wrapping length to be adjusted. See talios/googleformatter-maven-plugin for a Maven plugin example of how this might be done.

But as always, this is prone to breakage when a new version of google-java-format is released.

@nedtwigg
Copy link
Member

I agree with everything @jbduncan said, and I think this is mostly a wontfix. But! It is somewhat frequent for users to complain about line-wrapping behavior. One solution might be adontChangeLineWrap() step which could work with any formatter, not just googleJavaFormat(). It would work like so:

  • store the lines of the file at very beginning
  • run all other steps
  • look at the final result, and diff it with the original
  • for any diff which is just a linewrap, go back to the original wrap

This is tricky to build, and it's not going to make my todo list. But if someone wants to do it, these parts are already available:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants