-
Notifications
You must be signed in to change notification settings - Fork 464
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
ImportOrder without blank line between groups #1375
Comments
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. |
@nedtwigg I actually find a way to do this: --- 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. |
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) |
Currently, when I configure ImportOrder as
\\#,
in the maven plugin, I intend to format the imports as:... but it actually produces:
Is there an approach or we can make a patch to support the former format?
cc @nedtwigg
The text was updated successfully, but these errors were encountered: