Skip to content

Commit cb8ef95

Browse files
committed
chore: work on remove unsed imports
1 parent cc61e75 commit cb8ef95

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

app/src/main/java/com/diffplug/spotless/cli/steps/RemoveUnusedImports.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
*/
1616
package com.diffplug.spotless.cli.steps;
1717

18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
import org.jetbrains.annotations.NotNull;
22+
1823
import com.diffplug.spotless.FormatterStep;
1924
import com.diffplug.spotless.cli.core.SpotlessActionContext;
2025
import com.diffplug.spotless.cli.help.AdditionalInfoLinks;
2126
import com.diffplug.spotless.cli.help.OptionConstants;
2227
import com.diffplug.spotless.cli.help.SupportedFileTypes;
23-
import com.diffplug.spotless.java.CleanthatJavaStep;
2428
import com.diffplug.spotless.java.RemoveUnusedImportsStep;
25-
import org.jetbrains.annotations.NotNull;
26-
import picocli.CommandLine;
2729

28-
import java.util.ArrayList;
29-
import java.util.Collections;
30-
import java.util.List;
31-
import java.util.Objects;
30+
import picocli.CommandLine;
3231

3332
@CommandLine.Command(name = "remove-unused-imports", description = "Removes unused imports from Java files.")
3433
@SupportedFileTypes("Java")
@@ -38,16 +37,15 @@ public class RemoveUnusedImports extends SpotlessFormatterStep {
3837
@CommandLine.Option(
3938
names = {"--engine", "-e"},
4039
defaultValue = "GOOGLE_JAVA_FORMAT",
41-
description =
42-
"The backing engine to use for detecting and removing unused imports." + OptionConstants.VALID_AND_DEFAULT_VALUES_SUFFIX)
40+
description = "The backing engine to use for detecting and removing unused imports."
41+
+ OptionConstants.VALID_AND_DEFAULT_VALUES_SUFFIX)
4342
Engine engine;
4443

4544
public enum Engine {
4645
GOOGLE_JAVA_FORMAT {
4746
@Override
4847
String formatterName() {
4948
return RemoveUnusedImportsStep.defaultFormatter();
50-
5149
}
5250
},
5351
CLEAN_THAT {
@@ -57,7 +55,6 @@ String formatterName() {
5755
}
5856
};
5957

60-
6158
abstract String formatterName();
6259
}
6360

app/src/test/java/com/diffplug/spotless/cli/steps/RemoveUnusedImportsTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
/*
2+
* Copyright 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+
*/
116
package com.diffplug.spotless.cli.steps;
217

18+
import org.junit.jupiter.api.Test;
19+
320
import com.diffplug.spotless.cli.CLIIntegrationHarness;
421
import com.diffplug.spotless.tag.CliNativeTest;
522
import com.diffplug.spotless.tag.CliProcessTest;
6-
import org.junit.jupiter.api.Test;
723

824
import static org.junit.jupiter.api.Assertions.*;
925

@@ -15,16 +31,12 @@ class RemoveUnusedImportsTest extends CLIIntegrationHarness {
1531
void itRemovesUnusedImportsWithDefaultEngine() {
1632
setFile("Java.java").toResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test");
1733

18-
cliRunner()
19-
.withTargets("Java.java")
20-
.withStep(RemoveUnusedImports.class)
21-
.run();
34+
cliRunner().withTargets("Java.java").withStep(RemoveUnusedImports.class).run();
2235

2336
assertFile("Java.java")
2437
.notSameSasResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test")
2538
.hasNotContent("Unused");
2639

27-
2840
selfie().expectResource("Java.java").toMatchDisk();
2941
}
3042

0 commit comments

Comments
 (0)