openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.25k stars 336 forks source link

Support maximum line length / column limits formatting #4571

Open blipper opened 1 month ago

blipper commented 1 month ago

What problem are you trying to solve?

Many style guides such as Google's impost maximum column limits (https://google.github.io/styleguide/javaguide.html#s4.4-column-limit). There is tooling such as Checkstyle that enforces these limits. https://checkstyle.sourceforge.io/checks/sizes/linelength.html . Automated refactoring will fail often due to changes made that trigger checkstyle and other formatting checks.

Describe the solution you'd like

Update formatters to reformat lines to conform to the line length limit.

Examples for strings as here https://github.com/google/google-java-format/blob/098431221007a0fce1b0d213ded10948087332a4/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java#L123

Have you considered any alternatives or workarounds?

Additional context

Are you interested in contributing this feature to OpenRewrite?

timtebeek commented 1 month ago

Thanks for the suggestion @blipper ! Indeed seems like something that could be worthwhile to detect and apply, especially when those other tools are present as well and might otherwise fail the build.

blipper commented 1 month ago

The larger point here is that for larger enterprise adoption at compile time fixes or bot generated pull requests (as opposed to one off migration) of low false positive is necessary and style guide violations will break the build.

There is actually weirdly a bit gap for non-commercial opensource, non-coupled to IDEs or specific style guides tooling for Java code formatting. You have IntelliJ and Eclipse formatter but those both unfortunate couplings. Checkstyle has the vocabulary to express but not fix.