Spotless with Eclipse Import Order has different ordering than Eclipse Formatter
See original GitHub issueIf you are submitting a bug, please include the following:
- summary of problem Spotless with eclipse formatter orders static imports differently than eclipse or eclipse plugin in Intellij
- gradle or maven version mvn 3.3.3
- spotless version 1.27.0
- operating system and version Description: Ubuntu 16.04.6 LTS
- copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
<java>
<importOrder>
<file>/style/myTeam.importorder</file>
</importOrder>
</java>
</configuration>
with order
#Organize Import Order
#Fri Jun 28 15:00:43 PDT 2019
4=com.myTeam
3=java
2=javax
1=
0=\#
- copy-paste the full content of any console errors emitted by
gradlew spotless[Apply/Check] --stacktrace
N/A
If you’re just submitting a feature request or question, no need for the above.
EclipseFormatter issues https://github.com/krasa/EclipseCodeFormatter/issues/200 https://github.com/krasa/EclipseCodeFormatter/issues/105
Write
package somePackage;
import static somePackage.Foo.SomeEnum.Bar;
import static somePackage.Foo.SomeZClass;
import static somePackage.Foo.SomeZClass.m;
import java.util.function.Supplier;
// Use as a type argument to be a static import.
public class Foo implements Supplier<SomeZClass> {
public void someMethod() {
SomeEnum e = Bar;
m(); // call m with a static import
}
@Override
public SomeZClass get() {
return null;
}
public enum SomeEnum {
Bar
}
// Add Z this should be sorted after SomeEnum
public static class SomeZClass {
static void m() {}
}
}
Eclipse Plugin will order imports:
import static somePackage.Foo.SomeZClass;
import static somePackage.Foo.SomeEnum.Bar;
import static somePackage.Foo.SomeZClass.m;
Eclipse will order imports:
import static somePackage.Foo.SomeEnum.Bar;
import static somePackage.Foo.SomeZClass.m;
import java.util.function.Supplier;
import somePackage.Foo.SomeZClass;
and spotless will order imports
import static somePackage.Foo.SomeEnum.Bar;
import static somePackage.Foo.SomeZClass;
import static somePackage.Foo.SomeZClass.m;
import java.util.function.Supplier;
Spotless using Eclipse format rules should have the same behavior as Eclipse
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Is it possible for intellij to organize imports the same way as in ...
I set up eclipse code formatter including formatting and import order. Sometimes I ended up importing with * although the intellij formatting scheme...
Read more >534342 – [formatter] Add option to separate static imports from ...
There is no way to configure the Organize Imports action in Eclipse to add this blank line (without adding blank lines between all...
Read more >Google Java Style Guide
Imports are ordered as follows: ... If there are both static and non-static imports, a single blank line separates the two blocks. There...
Read more >Eclipse Order Of Imports - ADocLib
Due to some legacy third party code, we have import packages Spotless with Eclipse Import Order has different ordering than Eclipse Formatter #522....
Read more >Imports - checkstyle
To configure the check so that it matches default Eclipse formatter configuration (tested on Kepler and Luna releases):.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ekropotin we can work around this issue by adding an additional item to the
.importorder
file that forces unspecified imports to go at the end, for example:This makes spotless formatting consistent with IDEA/Eclipse code formatter, so I’m able to use save actions with reformat on save without causing any conflicts.
@nedtwigg yes it is. So, in a nutshell the problem is that Spotless tries to arrange imports of packages that are not specified in “importorder” config in alphabetical order with respect to other imports. Eclipse Code Fromatter, in turn, places such imports at the end of the imports block. Below is an example: build.gradle:
Test.importorder:
The file pre-formatted with ECF with Test.importorder:
Output of
gradle spotlessCheck
: