-
Notifications
You must be signed in to change notification settings - Fork 481
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
Conversation
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.
awesome, thanks.
testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test
Show resolved
Hide resolved
plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java
Show resolved
Hide resolved
lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Consequences of Lacking Discipline <8830888+Pankraz76@users.noreply.github.com>
…WildcardsUnformatted.test Co-authored-by: Consequences of Lacking Discipline <8830888+Pankraz76@users.noreply.github.com>
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.
LGTM! Would you mind adding a test for the Gradle plugin?
lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java
Outdated
Show resolved
Hide resolved
could migrate the Line 20 in 2cc8c04
|
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RemoveWildcardImportsTest.java
Outdated
Show resolved
Hide resolved
…xtension.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s into remove-wildcard-imports
you mean spot checks on .editorconfig something like this
|
No, sorry—I meant we could remove this config, assuming it's not needed anymore, as Spot will prevent it now. But keeping it wouldn't hurt, as it still helps to avoid potential issues. If auto-fix were possible, the config would still help prevent problems before fixing them, in the first place, but it wouldn't be strictly necessary anymore. The next version will go further and deliver actual imports to fully automate this. A win for the project. Thanks for the good craftsmanship! |
Ohh no my bad, I misunderstood it. Now it makes sense. Lets keep that setting in place as an extra safety as of now. Without it, IntelliJ’s default of 5 would collapse to a wildcard on the 6th import, then Spotless would strip that wildcard and force everyone to re-import. |
It could be honored by the IDEA side. |
removeWildcardImports
step
removeWildcardImports
stepremoveWildcardImports
step
Thanks. |
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.
idea on removeObsoletes()
.
@@ -188,6 +188,7 @@ spotless { | |||
importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse | |||
|
|||
removeUnusedImports() | |||
removeWildcardImports() |
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()
I have just opened a PR to help us say “goodbye” to those sneaky wildcard imports (like import java.util.*;) whenever Spotless tidies up our Java files. Wildcard imports can make it hard to see exactly which classes you’re relying on, so this change introduces a new step in the Spotless plugin that:
Spots any import foo.*; lines in your source
Removes them outright (so your IDE or build tools can regenerate only the exact imports you need)