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
ImportOrder without blank line between groups #1375
The importsorter is a mess. My personal opinion is that I only care that the imports are consistent, I don't care at all how they are consistent.
I'm happy to take a PR which adds whatever feature anyone wants, but it can't change behavior for existing users. That's a difficult but not impossible thing, which I have lumped into the "importsorter" tag.
--- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java+++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java
/*not thread safe*/
// Based on ImportSorterImpl from https://github.com/krasa/EclipseCodeFormatter,
// which itself is licensed under the Apache 2.0 license.
@@ -32,6 +34,8 @@ final class ImportSorterImpl {
private static final String STATIC_SYMBOL = "\\#";
private static final String SUBGROUP_SEPARATOR = "|";
+ private final int blankLinesBetweenImportGroups;+
private final List<ImportsGroup> importsGroups;
private final Map<String, List<String>> matchingImports = new HashMap<>();
private final List<String> notMatching = new ArrayList<>();
@@ -200,7 +204,7 @@ final class ImportSorterImpl {
for (String s : sortedImported) {
if (s.equals(ImportSorter.N)) {
- strings.add(s);+ strings.add(Strings.repeat(ImportSorter.N.charAt(0), blankLinesBetweenImportGroups));
} else {
strings.add(String.format(lineFormat, s) + ImportSorter.N);
}
... which comes from how Eclipse does it.
But I noticed @murdos introduced a new concept "subGroups" to try to resolve it with more complex string interpreting syntax. Let me try it out.
Activity
nedtwigg commentedon Oct 19, 2022
The importsorter is a mess. My personal opinion is that I only care that the imports are consistent, I don't care at all how they are consistent.
I'm happy to take a PR which adds whatever feature anyone wants, but it can't change behavior for existing users. That's a difficult but not impossible thing, which I have lumped into the "importsorter" tag.
tisonkun commentedon Jan 10, 2023
@nedtwigg I actually find a way to do this:
... which comes from how Eclipse does it.
But I noticed @murdos introduced a new concept "subGroups" to try to resolve it with more complex string interpreting syntax. Let me try it out.
tisonkun commentedon Jan 10, 2023
Somehow these two configs can live together that it doesn't affect "subGroups", but..what a mess, lol.
I'm a bit confused how can I configure a simple:
with the subgroup feature.
See #1401 (comment)