Add semantics-aware sorting for Java imports#1709
Merged
nedtwigg merged 5 commits intodiffplug:mainfrom May 22, 2023
Merged
Conversation
nedtwigg
requested changes
May 22, 2023
Member
nedtwigg
left a comment
There was a problem hiding this comment.
Thanks, this is a great PR!
The most important compatibility guarantee we make is to our existing users. I agree that for new users, semanticSort is probably the correct behavior. But the premise of Spotless is "formatting doesn't matter, turn this on and then stop thinking about it". Anytime we change the defaults they have to think about it, which is bad.
Contributor
Author
|
I added the requested changes in a fixup commit. |
Member
|
CI is failing because you need to run |
Frederick888
added a commit
to Frederick888/spotless
that referenced
this pull request
May 26, 2023
The default value was updated to false [1] per suggestion [2]. [1] diffplug@10610f8 [2] diffplug#1709 (review)
Frederick888
added a commit
to Frederick888/spotless
that referenced
this pull request
May 26, 2023
The default value was updated to false [1] per suggestion [2]. [1] diffplug@10610f8 [2] diffplug#1709 (review)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is for issue #522.
It introduces semantics-aware sorting of Java imports, i.e. imports are sorted by package, classes and static members, instead of just lexicographically. This is the new default behavior, but the old one can be restored (in Maven e.g. via
<semanticSort>false</semanticSort>). The imports are split based on conventions: package names start with lower case, class names with upper case. For exceptions, the<treatAsPackage>and<treatAsClass>configurations can be used.