-
Notifications
You must be signed in to change notification settings - Fork 488
Support removing wildcard imports via removeWildcardImports
step
#2517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
69a5684
Remove wildcard imports
iddeepak ad37473
Update plugin-gradle/README.md
iddeepak 205974a
Update testlib/src/main/resources/java/removewildcardimports/JavaCode…
iddeepak 0761c81
Apply suggestions from code review
Goooler 825273c
gradle test
iddeepak e482db2
gradle test
iddeepak 01c93f3
Update plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaE…
iddeepak a434eed
spotless apply
iddeepak 3b9b939
Merge branch 'remove-wildcard-imports' of github.com:iddeepak/spotles…
iddeepak 4d74803
spotless apply
iddeepak 7528572
spotless apply
iddeepak 19381b2
Apply suggestions from code review
Goooler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 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.java; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.generic.ReplaceRegexStep; | ||
|
||
/** Removes any wildcard import statements. */ | ||
public final class RemoveWildcardImportsStep { | ||
private RemoveWildcardImportsStep() {} | ||
|
||
public static FormatterStep create() { | ||
// Matches lines like 'import foo.*;' or 'import static foo.*;'. | ||
return ReplaceRegexStep.create( | ||
"removeWildcardImports", | ||
"(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?", | ||
""); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
plugin-maven/src/main/java/com/diffplug/spotless/maven/java/RemoveWildcardImports.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 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 com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.java.RemoveWildcardImportsStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
|
||
public class RemoveWildcardImports implements FormatterStepFactory { | ||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig config) { | ||
return RemoveWildcardImportsStep.create(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...n-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 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 RemoveWildcardImportsStepTest extends MavenIntegrationHarness { | ||
|
||
@Test | ||
void testRemoveWildcardImports() throws Exception { | ||
writePomWithJavaSteps("<removeWildcardImports/>"); | ||
|
||
String path = "src/main/java/test.java"; | ||
setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); | ||
mavenRunner().withArguments("spotless:apply").runNoError(); | ||
iddeepak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertFile(path).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsFormatted.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import java.util.List; | ||
import mylib.Helper; | ||
|
||
public class Test {} |
9 changes: 9 additions & 0 deletions
9
testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import java.util.*; | ||
import static java.util.Collections.*; | ||
import java.util.List; | ||
import mylib.Helper; | ||
iddeepak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import io.quarkus.maven.dependency.*; | ||
import static io.quarkus.vertx.web.Route.HttpMethod.*; | ||
import static org.springframework.web.reactive.function.BodyInserters.*; | ||
|
||
public class Test {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removeObsoletes()
removeObsoleteInit()
removeObsoleteInitializations()