Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
* 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))
### Fixed
* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
Expand Down Expand Up @@ -418,8 +417,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [2.26.0] - 2022-06-05
### Added
* Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193))
### Fixed
* `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))

## [2.25.3] - 2022-05-10
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.Provisioner;

/** Uses palantir-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
/** Uses google-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
public class RemoveUnusedImportsStep implements Serializable {
private static final long serialVersionUID = 1L;
static final String NAME = "removeUnusedImports";

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

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

public static String defaultFormatter() {
return DEFAULT_FORMATTER;
return GJF;
}

public static FormatterStep create(Provisioner provisioner) {
return create(DEFAULT_FORMATTER, provisioner);
// The default importRemover is GJF
return create(GJF, provisioner);
}

public static FormatterStep create(String unusedImportRemover, Provisioner provisioner) {
Objects.requireNonNull(provisioner, "provisioner");
switch (unusedImportRemover) {
case DEFAULT_FORMATTER:
case GJF:
return GoogleJavaFormatStep.createRemoveUnusedImportsOnly(provisioner);
case CLEANTHAT:
return CleanthatJavaStep.createWithStepName(NAME, CleanthatJavaStep.defaultGroupArtifact(), CleanthatJavaStep.defaultVersion(), "99.9", List.of(CLEANTHAT_MUTATOR), List.of(), false, provisioner);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.maven.java;

import org.junit.jupiter.api.Test;

import com.diffplug.spotless.maven.MavenIntegrationHarness;

class RemoveUnusedImportsStepTest extends MavenIntegrationHarness {

@Test
void testRemoveUnusedInports() throws Exception {
writePomWithJavaSteps("<removeUnusedImports/>");

String path = "src/main/java/test.java";
setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class RemoveUnusedImportsStep_withGoogleJavaFormatTest {
@Test
void behavior() throws Exception {
FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
StepHarness.forStep(step)
.testResource("java/removeunusedimports/JavaCodeUnformatted.test", "java/removeunusedimports/JavaCodeFormatted.test")
.testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test")
Expand All @@ -48,7 +48,7 @@ protected void setupTest(API api) {

@Override
protected FormatterStep create() {
return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
}
}.testEquals();
}
Expand Down
Loading