You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spotless sorts imports with uppercase package names different from eclipse #167
HI again!
I'm seeing some reorganized imports between eclipse and spotless.
Due to some legacy third party code, we have import packages starting with upper case. These seems to be sorted differently between Eclipse and Spotless ImportSorter.
I saw that this code was reimplemented from the IntelliJs plugin EclipseCodeFormatter. The latest version of Eclipse Code Formatter seems to do this correctly.
As an alternative to #167 (comment), consider adding an option to the new importOrder() that just outright disallows wildcard imports. (Think Checkstyle's AvoidStarImport option.)
Would be great to be able to fail the build if wildcard imports are used. However it does seem strange to have validation for Check that cannot be fixed with Apply.
@DJViking Indeed... So with hindsight, I think my comment above where I suggested we introduce a mechanism that fails but has no associated fix, is not the right way to go about fixing this.
However, @nedtwigg has mentioned a few times in other issues that it's impossible for Spotless to recognise and and expand wildcard imports without a huge architectural change (i.e., moving away from representing formatting steps as simple Function<String, String>s internally).
So I wonder if in your case, using a tool like Checkstyle is the best that can be done presently... (One can tell it to report an error if it finds wildcard imports, but just to report it, not to automatically fix things as well.)
This wouldn't be the only place where spotlessApply fails. ktlint catches lot of errors that it can't fix. Checkstyle is a good way to do it, but I still think it makes sense to implement errorOnWildcard().
Reacted by Jonathan Bluett-Duncan, Michael Zhang, Magnus, Valera Timofeev and Vish Ranganathan
Activity
nedtwigg commentedon Nov 21, 2017
Good find! There are pros and cons to fixing this.
Pro: We will match Eclipse's current behavior.
Con: We will introduce noise into projects that have been using Spotless so far.
I think the best approach would be this:
This means that new projects get the behavior the "correct" behavior, and old projects can keep the behavior they've had to-date, if they like.
The code in question is here:
https://github.com/diffplug/spotless/tree/master/lib/src/main/java/com/diffplug/spotless/java
Implementing this won't make it to the top of my todo-list, but I'm happy to merge a PR for it.
jbduncan commentedon Mar 13, 2018
Reminder (prompted by #223 (comment)):
importOrder(), create an option to allow wildcard imports to be converted to full imports, e.g.:importOrder().expandingWildcardImports()jbduncan commentedon Mar 13, 2018
As an alternative to #167 (comment), consider adding an option to the new
importOrder()that just outright disallows wildcard imports. (Think Checkstyle'sAvoidStarImportoption.)DJViking commentedon Feb 27, 2019
Would be great to be able to fail the build if wildcard imports are used. However it does seem strange to have validation for Check that cannot be fixed with Apply.
jbduncan commentedon Feb 27, 2019
@DJViking Indeed... So with hindsight, I think my comment above where I suggested we introduce a mechanism that fails but has no associated fix, is not the right way to go about fixing this.
However, @nedtwigg has mentioned a few times in other issues that it's impossible for Spotless to recognise and and expand wildcard imports without a huge architectural change (i.e., moving away from representing formatting steps as simple
Function<String, String>s internally).So I wonder if in your case, using a tool like Checkstyle is the best that can be done presently... (One can tell it to report an error if it finds wildcard imports, but just to report it, not to automatically fix things as well.)
DJViking commentedon Feb 27, 2019
Yes, I think Checkstyle would be the best way to do it.
nedtwigg commentedon Feb 27, 2019
This wouldn't be the only place where
spotlessApplyfails.ktlintcatches lot of errors that it can't fix. Checkstyle is a good way to do it, but I still think it makes sense to implementerrorOnWildcard().Frettman commentedon Dec 31, 2022
As I tried to explain here #522 (comment), I don't think this can be fixed transparently without breaking other cases.
nedtwigg commentedon Jan 1, 2023
Thanks very much @Frettman, I'm going to close this as dupe of #522 since that's where the great explanation is.