Enhance autoformat logic for Groovy files #4009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's changed?
Bringing back some auto formatting rules to the
G
type. This focuses on tabs VS spaces, normalizing EOL characters, blank lines, and removing trailing whitespace.What's your motivation?
Historically, Groovy auto formatting was a bear and would pretty often result in files becoming invalid. As a result, it was disabled fully in the
org.openrewrite.java.format.AutoFormatVisitor
, so that the Java auto formatting rules would never be applied to any non-J
type.Anything in particular you'd like reviewers to focus on?
While re-introducing auto format support, I found two bugs. One of which is found fixed within this PR, but the other has been noted with a pair of disabled tests.
withClasses
orwithImports
on an instance ofG
, this would result in theG.CompilationUnit
being recreated due to a bug in the logic. Specifically, getting the classes or imports will always return a new list which means that they will never have instance identity equality. So instead, we should verify that the elements themselves are unchanged, then take the appropriate actions.Have you considered any alternatives or workarounds?
N/A
Checklist