diff --git a/CHANGES.md b/CHANGES.md index 28a857950b..95c4897c7a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 0390d99c1b..1f014ba95e 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ private static class ImportsGroup { private final List subGroups; public ImportsGroup(String importOrder) { - this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) + this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1)) .map(this::normalizeStatic) .collect(Collectors.toList()); } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d8b9c26275..f6210ce8de 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 03a2a0b018..6f59030a8e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test new file mode 100644 index 0000000000..62efc65e21 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test @@ -0,0 +1,14 @@ +import static com.foo.Bar; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static java.lang.Exception.*; +import static java.lang.Runnable.*; +import static org.hamcrest.Matchers.*; +import java.awt.*; +import java.lang.Runnable; +import java.lang.Thread; +import java.util.*; +import java.util.List; +import javax.annotation.Nullable; +import javax.inject.Inject; +import org.dooda.Didoo; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 8f3bd799bc..ca6bd39825 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -41,6 +41,12 @@ void sortImportsFromArrayWithSubgroups() { StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); } + @Test + void sortImportsFromArrayWithSubgroupsLeadingCatchAll() { + FormatterStep step = ImportOrderStep.forJava().createFrom("\\#|"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test"); + } + @Test void sortImportsFromFile() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties"));