-
Notifications
You must be signed in to change notification settings - Fork 455
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
Add semantics-aware sorting for Java imports #1709
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java
Outdated
Show resolved
Hide resolved
plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
Outdated
Show resolved
Hide resolved
lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java
Outdated
Show resolved
Hide resolved
lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java
Outdated
Show resolved
Hide resolved
I added the requested changes in a fixup commit. |
CI is failing because you need to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The default value was updated to false [1] per suggestion [2]. [1] diffplug@10610f8 [2] diffplug#1709 (review)
The default value was updated to false [1] per suggestion [2]. [1] diffplug@10610f8 [2] diffplug#1709 (review)
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.