Skip to content

Commit 0259785

Browse files
authored
removeUnusedImports and googleJavaFormat can be used at the same time again (#2328 fixes #2159)
2 parents f81c612 + ad4501e commit 0259785

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1515
* Add _Sort Members_ feature based on [Eclipse JDT](plugin-gradle/README.md#eclipse-jdt) implementation. ([#2312](https://github.com/diffplug/spotless/pull/2312))
1616
* Bump default `jackson` version to latest `2.18.0` -> `2.18.1`. ([#2319](https://github.com/diffplug/spotless/pull/2319))
1717
* Bump default `ktfmt` version to latest `0.52` -> `0.53`. ([#2320](https://github.com/diffplug/spotless/pull/2320)
18+
### Fixed
19+
* You can now use `removeUnusedImports` and `googleJavaFormat` at the same time again. (fixes [#2159](https://github.com/diffplug/spotless/issues/2159))
1820

1921
## [3.0.0.BETA4] - 2024-10-24
2022
### Added

lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static FormatterStep create(Provisioner provisioner) {
7474

7575
/** Creates a step that applies default CleanThat mutators. */
7676
public static FormatterStep create(String version, Provisioner provisioner) {
77-
return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultMutators(), defaultExcludedMutators(), defaultIncludeDraft(), provisioner);
77+
return createWithStepName(NAME, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultMutators(), defaultExcludedMutators(), defaultIncludeDraft(), provisioner);
7878
}
7979

8080
public static String defaultSourceJdk() {
@@ -101,7 +101,8 @@ public static boolean defaultIncludeDraft() {
101101
}
102102

103103
/** Creates a step that applies selected CleanThat mutators. */
104-
public static FormatterStep create(String groupArtifact,
104+
static FormatterStep createWithStepName(String stepName,
105+
String groupArtifact,
105106
String version,
106107
String sourceJdkVersion,
107108
List<String> included,
@@ -114,12 +115,23 @@ public static FormatterStep create(String groupArtifact,
114115
}
115116
Objects.requireNonNull(version, "version");
116117
Objects.requireNonNull(provisioner, "provisioner");
117-
return FormatterStep.create(NAME,
118+
return FormatterStep.create(stepName,
118119
new CleanthatJavaStep(JarState.promise(() -> JarState.from(groupArtifact + ":" + version, provisioner)), version, sourceJdkVersion, included, excluded, includeDraft),
119120
CleanthatJavaStep::equalityState,
120121
State::createFormat);
121122
}
122123

124+
/** Creates a step that applies selected CleanThat mutators. */
125+
public static FormatterStep create(String groupArtifact,
126+
String version,
127+
String sourceJdkVersion,
128+
List<String> included,
129+
List<String> excluded,
130+
boolean includeDraft,
131+
Provisioner provisioner) {
132+
return createWithStepName(NAME, groupArtifact, version, sourceJdkVersion, included, excluded, includeDraft, provisioner);
133+
}
134+
123135
/** Get default formatter version */
124136
public static String defaultVersion() {
125137
return Objects.requireNonNull(JVM_SUPPORT.getRecommendedFormatterVersion());

lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ public static FormatterStep create(String groupArtifact, String version, String
8787

8888
/** Creates a step which formats everything - groupArtifact, code, import order, and unused imports - and optionally reflows long strings. */
8989
public static FormatterStep create(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports, boolean formatJavadoc) {
90-
return createInternally(groupArtifact, version, style, provisioner, reflowLongStrings, reorderImports, formatJavadoc, false);
90+
return createInternally(NAME, groupArtifact, version, style, provisioner, reflowLongStrings, reorderImports, formatJavadoc, false);
9191
}
9292

9393
static FormatterStep createRemoveUnusedImportsOnly(Provisioner provisioner) {
94-
return createInternally(MAVEN_COORDINATE, defaultVersion(), defaultStyle(), provisioner, defaultReflowLongStrings(), defaultReorderImports(), defaultFormatJavadoc(), true);
94+
return createInternally(RemoveUnusedImportsStep.NAME, MAVEN_COORDINATE, defaultVersion(), defaultStyle(), provisioner, defaultReflowLongStrings(), defaultReorderImports(), defaultFormatJavadoc(), true);
9595
}
9696

97-
private static FormatterStep createInternally(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports, boolean formatJavadoc, boolean removeImports) {
97+
private static FormatterStep createInternally(String name, String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports, boolean formatJavadoc, boolean removeImports) {
9898
Objects.requireNonNull(groupArtifact, "groupArtifact");
9999
if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) {
100100
throw new IllegalArgumentException("groupArtifact must be in the form 'groupId:artifactId'");

lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/** Uses google-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
2626
public class RemoveUnusedImportsStep implements Serializable {
2727
private static final long serialVersionUID = 1L;
28-
private static final String NAME = "removeUnusedImports";
28+
static final String NAME = "removeUnusedImports";
2929

3030
static final String GJF = "google-java-format";
3131
static final String CLEANTHAT = "cleanthat-javaparser-unnecessaryimport";
@@ -51,7 +51,7 @@ public static FormatterStep create(String unusedImportRemover, Provisioner provi
5151
case GJF:
5252
return GoogleJavaFormatStep.createRemoveUnusedImportsOnly(provisioner);
5353
case CLEANTHAT:
54-
return CleanthatJavaStep.create(CleanthatJavaStep.defaultGroupArtifact(), CleanthatJavaStep.defaultVersion(), "99.9", List.of(CLEANTHAT_MUTATOR), List.of(), false, provisioner);
54+
return CleanthatJavaStep.createWithStepName(NAME, CleanthatJavaStep.defaultGroupArtifact(), CleanthatJavaStep.defaultVersion(), "99.9", List.of(CLEANTHAT_MUTATOR), List.of(), false, provisioner);
5555
default:
5656
throw new IllegalArgumentException("Invalid unusedImportRemover: " + unusedImportRemover);
5757
}

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
* Bump default `ktlint` version to latest `1.3.0` -> `1.4.0`. ([#2314](https://github.com/diffplug/spotless/pull/2314))
88
* Bump default `jackson` version to latest `2.18.0` -> `2.18.1`. ([#2319](https://github.com/diffplug/spotless/pull/2319))
99
* Bump default `ktfmt` version to latest `0.52` -> `0.53`. ([#2320](https://github.com/diffplug/spotless/pull/2320)
10+
### Fixed
11+
* You can now use `removeUnusedImports` and `googleJavaFormat` at the same time again. (fixes [#2159](https://github.com/diffplug/spotless/issues/2159))
1012

1113
## [7.0.0.BETA4] - 2024-10-24
1214
### Added

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
* Bump default `ktlint` version to latest `1.3.0` -> `1.4.0`. ([#2314](https://github.com/diffplug/spotless/pull/2314))
88
* Bump default `jackson` version to latest `2.18.0` -> `2.18.1`. ([#2319](https://github.com/diffplug/spotless/pull/2319))
99
* Bump default `ktfmt` version to latest `0.52` -> `0.53`. ([#2320](https://github.com/diffplug/spotless/pull/2320)
10+
### Fixed
11+
* You can now use `removeUnusedImports` and `googleJavaFormat` at the same time again. (fixes [#2159](https://github.com/diffplug/spotless/issues/2159))
1012

1113
## [2.44.0.BETA4] - 2024-10-24
1214
### Added

0 commit comments

Comments
 (0)