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

Add semantics-aware sorting for Java imports #1709

Merged
merged 5 commits into from
May 22, 2023
Merged

Conversation

Frettman
Copy link
Contributor

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.

Copy link
Member

@nedtwigg nedtwigg left a 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.

@Frettman
Copy link
Contributor Author

I added the requested changes in a fixup commit.

@nedtwigg
Copy link
Member

CI is failing because you need to run spotlessApply.

@nedtwigg nedtwigg enabled auto-merge May 22, 2023 21:58
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nedtwigg nedtwigg merged commit 8d4f402 into diffplug:main May 22, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants