Skip to content

Commit cb202b1

Browse files
author
Vincent Potucek
committed
Revert "Use palantir-java-format as default formatter in RemoveUnusedImportsStep"
This reverts commit 2ebe138
1 parent 86d65b0 commit cb202b1

File tree

5 files changed

+43
-85
lines changed

5 files changed

+43
-85
lines changed

CHANGES.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Added
1414
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
1515
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
16-
* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
1716
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
1817
### Fixed
1918
* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
@@ -418,8 +417,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
418417
## [2.26.0] - 2022-06-05
419418
### Added
420419
* Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193))
421-
### Fixed
422-
* `google-java-format` and `RemoveUnusedImportsStep` works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224) fixes [#834](https://github.com/diffplug/spotless/issues/834))
423420

424421
## [2.25.3] - 2022-05-10
425422
### Fixed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,12 +22,12 @@
2222
import com.diffplug.spotless.FormatterStep;
2323
import com.diffplug.spotless.Provisioner;
2424

25-
/** Uses palantir-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
25+
/** 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;
2828
static final String NAME = "removeUnusedImports";
2929

30-
static final String DEFAULT_FORMATTER = "palantir-java-format";
30+
static final String GJF = "google-java-format";
3131
static final String CLEANTHAT = "cleanthat-javaparser-unnecessaryimport";
3232

3333
// https://github.com/solven-eu/cleanthat/blob/master/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java
@@ -37,17 +37,18 @@ public class RemoveUnusedImportsStep implements Serializable {
3737
private RemoveUnusedImportsStep() {}
3838

3939
public static String defaultFormatter() {
40-
return DEFAULT_FORMATTER;
40+
return GJF;
4141
}
4242

4343
public static FormatterStep create(Provisioner provisioner) {
44-
return create(DEFAULT_FORMATTER, provisioner);
44+
// The default importRemover is GJF
45+
return create(GJF, provisioner);
4546
}
4647

4748
public static FormatterStep create(String unusedImportRemover, Provisioner provisioner) {
4849
Objects.requireNonNull(provisioner, "provisioner");
4950
switch (unusedImportRemover) {
50-
case DEFAULT_FORMATTER:
51+
case GJF:
5152
return GoogleJavaFormatStep.createRemoveUnusedImportsOnly(provisioner);
5253
case CLEANTHAT:
5354
return CleanthatJavaStep.createWithStepName(NAME, CleanthatJavaStep.defaultGroupArtifact(), CleanthatJavaStep.defaultVersion(), "99.9", List.of(CLEANTHAT_MUTATOR), List.of(), false, provisioner);

plugin-maven/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2016-2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.maven.java;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import com.diffplug.spotless.maven.MavenIntegrationHarness;
21+
22+
class RemoveUnusedImportsStepTest extends MavenIntegrationHarness {
23+
24+
@Test
25+
void testRemoveUnusedInports() throws Exception {
26+
writePomWithJavaSteps("<removeUnusedImports/>");
27+
28+
String path = "src/main/java/test.java";
29+
setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
30+
mavenRunner().withArguments("spotless:apply").runNoError();
31+
assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
32+
}
33+
}

testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
class RemoveUnusedImportsStep_withGoogleJavaFormatTest {
2626
@Test
2727
void behavior() throws Exception {
28-
FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
28+
FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
2929
StepHarness.forStep(step)
3030
.testResource("java/removeunusedimports/JavaCodeUnformatted.test", "java/removeunusedimports/JavaCodeFormatted.test")
3131
.testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test")
@@ -48,7 +48,7 @@ protected void setupTest(API api) {
4848

4949
@Override
5050
protected FormatterStep create() {
51-
return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
51+
return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
5252
}
5353
}.testEquals();
5454
}

0 commit comments

Comments
 (0)