-
Notifications
You must be signed in to change notification settings - Fork 493
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
+161
−2
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
| 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.*;' | ||
Goooler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ReplaceRegexStep.create( | ||
| "removeWildcardImports", | ||
iddeepak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "(?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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,6 +188,7 @@ spotless { | |
| importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse | ||
|
|
||
| removeUnusedImports() | ||
| removeWildcardImports() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removeObsoletes() |
||
|
|
||
| // Cleanthat will refactor your code, but it may break your style: apply it before your formatter | ||
| cleanthat() // has its own section below | ||
|
|
@@ -227,6 +228,16 @@ spotless { | |
| removeUnusedImports('cleanthat-javaparser-unnecessaryimport') | ||
| ``` | ||
|
|
||
| ### removeWildcardImports | ||
|
|
||
| ``` | ||
| spotless { | ||
| java { | ||
| removeWildcardImports() | ||
iddeepak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### google-java-format | ||
|
|
||
| [homepage](https://github.com/google/google-java-format). [changelog](https://github.com/google/google-java-format/releases). | ||
|
|
||
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
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
| 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(); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...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,18 @@ | ||
| 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 {} |
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
| 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
|
||
|
|
||
| public class Test {} | ||
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.
Uh oh!
There was an error while loading. Please reload this page.