Skip to content

Commit e78f50a

Browse files
author
Vincent Potucek
committed
new step to expand java wildcard imports diffplug#2744 diffplug#2594
1 parent 5a5ceae commit e78f50a

File tree

14 files changed

+53
-53
lines changed

14 files changed

+53
-53
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
3232
## [4.0.0] - 2025-09-24
3333
### Changes
3434
* **BREAKING** Bump the required Java to `17`. ([#2375](https://github.com/diffplug/spotless/issues/2375), [#2540](https://github.com/diffplug/spotless/pull/2540))
35-
* **BREAKING** Renamed `RemoveWildcardImportsStep` to `ForbidWildcardImportsStep`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
35+
* **BREAKING** Renamed `RemoveWildcardImportsStep` to `ExpandWildcardImportsStep`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
3636
* Bump JGit from `6.10.1` to `7.3.0` ([#2257](https://github.com/diffplug/spotless/pull/2257))
3737
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))
3838
* Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345))

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ lib('java.ImportOrderStep') +'{{yes}} | {{yes}}
8686
lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
8787
lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
8888
lib('java.ExpandWildcardImportsStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
89-
lib('java.ForbidWildcardImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
89+
lib('java.ExpandWildcardImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
9090
lib('java.ForbidModuleImportsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9191
extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
9292
lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -144,7 +144,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
144144
| [`java.PalantirJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
145145
| [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
146146
| [`java.ExpandWildcardImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
147-
| [`java.ForbidWildcardImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ForbidWildcardImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
147+
| [`java.ExpandWildcardImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
148148
| [`java.ForbidModuleImportsStep`](lib/src/main/java/com/diffplug/spotless/java/ForbidModuleImportsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
149149
| [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
150150
| [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |

gradle/spotless.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spotless {
77
eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml')
88
expandWildcardImports()
99
forbidRegex('ForbidGradleInternal', 'import org\\.gradle\\.api\\.internal\\.(.*)', "Don't use Gradle's internal API")
10-
forbidWildcardImports()
10+
expandWildcardImports()
1111
formatAnnotations()
1212
importOrderFile rootProject.file('gradle/spotless.importorder')
1313
licenseHeaderFile rootProject.file('gradle/spotless.license')

lib/src/main/java/com/diffplug/spotless/java/ForbidWildcardImportsStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
import com.diffplug.spotless.generic.ReplaceRegexStep;
2020

2121
/** Forbids any wildcard import statements. */
22-
public final class ForbidWildcardImportsStep {
22+
public final class ExpandWildcardImportsStep {
2323

2424
/**
2525
* Matches lines like 'import foo.*;' or 'import static foo.*;'.
2626
*/
2727
private static final String REGEX = "(?m)^import\\s+(?:static\\s+)?[^;\\n]*\\*;\\R?";
28-
private static final String NAME = "forbidWildcardImports";
28+
private static final String NAME = "expandWildcardImports";
2929
private static final String ERROR = "Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this";
3030

31-
private ForbidWildcardImportsStep() {}
31+
private ExpandWildcardImportsStep() {}
3232

3333
public static FormatterStep create() {
3434
return ReplaceRegexStep.lint(NAME, REGEX, ERROR);

plugin-gradle/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
3030
## [8.0.0] - 2025-09-24
3131
### Changed
3232
* **BREAKING** Bump the required Gradle to `7.3` and required Java to `17`. ([#2375](https://github.com/diffplug/spotless/issues/2375), [#2540](https://github.com/diffplug/spotless/pull/2540))
33-
* **BREAKING** Renamed `removeWildcardImports` to `forbidWildcardImports`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
33+
* **BREAKING** Renamed `removeWildcardImports` to `expandWildcardImports`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
3434
* **BREAKING** `spotlessInstallGitPrePushHook` task is now installed only on the root project. ([#2570](https://github.com/diffplug/spotless/pull/2570))
3535
* **BREAKING** `LintSuppression` now enforces unix-style paths in its `setPath` method. ([#2629](https://github.com/diffplug/spotless/pull/2629))
3636
* Running `spotlessCheck` with violations unilaterally produces the error message `Run './gradlew spotlessApply' to fix these violations`. ([#2592](https://github.com/diffplug/spotless/issues/2592))

plugin-gradle/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ spotless {
207207
importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse
208208
209209
removeUnusedImports()
210-
forbidWildcardImports() // or expandWildcardImports, see below
210+
expandWildcardImports() // or expandWildcardImports, see below
211211
forbidModuleImports()
212212
213213
// Cleanthat will refactor your code, but it may break your style: apply it before your formatter
@@ -249,12 +249,12 @@ spotless {
249249
removeUnusedImports('cleanthat-javaparser-unnecessaryimport')
250250
```
251251
252-
### forbidWildcardImports
252+
### expandWildcardImports
253253
254254
```
255255
spotless {
256256
java {
257-
forbidWildcardImports()
257+
expandWildcardImports()
258258
}
259259
}
260260
```
@@ -263,7 +263,7 @@ spotless {
263263
264264
This step expands all wildcard imports to single class imports.
265265
To do this, [JavaParser](https://javaparser.org/) is used to parse the complete sourcecode and resolve the full qualified name of all used classes and static methods.
266-
This operation can be resource intensive when formatting many source files, so you may want to change to `forbidWildcardImports` when your codebase is cleaned and stable.
266+
This operation can be resource intensive when formatting many source files, so you may want to change to `expandWildcardImports` when your codebase is cleaned and stable.
267267
268268
```
269269
spotless {

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import com.diffplug.spotless.java.CleanthatJavaStep;
4242
import com.diffplug.spotless.java.ExpandWildcardImportsStep;
4343
import com.diffplug.spotless.java.ForbidModuleImportsStep;
44-
import com.diffplug.spotless.java.ForbidWildcardImportsStep;
44+
import com.diffplug.spotless.java.ExpandWildcardImportsStep;
4545
import com.diffplug.spotless.java.FormatAnnotationsStep;
4646
import com.diffplug.spotless.java.GoogleJavaFormatStep;
4747
import com.diffplug.spotless.java.ImportOrderStep;
@@ -159,12 +159,12 @@ public void removeUnusedImports(String formatter) {
159159

160160
@Deprecated
161161
public void removeWildcardImports() {
162-
System.err.println("`removeWildcardImports()` replaced by `forbidWildcardImports()`");
163-
forbidWildcardImports();
162+
System.err.println("`removeWildcardImports()` replaced by `forbidWildcardImports()` replaced by `expandWildcardImports()`");
163+
expandWildcardImports();
164164
}
165165

166-
public void forbidWildcardImports() {
167-
addStep(ForbidWildcardImportsStep.create());
166+
public void expandWildcardImports() {
167+
addStep(ExpandWildcardImportsStep.create());
168168
}
169169

170170
public void forbidModuleImports() {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void removeUnusedImportsWithCleanthat() throws IOException {
8383
}
8484

8585
@Test
86-
void forbidWildcardImports() throws IOException {
86+
void expandWildcardImports() throws IOException {
8787
setFile("build.gradle").toLines(
8888
"plugins {",
8989
" id 'com.diffplug.spotless'",
@@ -93,7 +93,7 @@ void forbidWildcardImports() throws IOException {
9393
"spotless {",
9494
" java {",
9595
" target file('test.java')",
96-
" forbidWildcardImports()",
96+
" expandWildcardImports()",
9797
" }",
9898
"}");
9999

plugin-maven/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2626
## [3.0.0] - 2025-09-24
2727
### Changes
2828
* **BREAKING** Bump the required Java to `17`. ([#2375](https://github.com/diffplug/spotless/issues/2375), [#2540](https://github.com/diffplug/spotless/pull/2540))
29-
* **BREAKING** Renamed `removeWildcardImports` to `forbidWildcardImports`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
29+
* **BREAKING** Renamed `removeWildcardImports` to `expandWildcardImports`. ([#2633](https://github.com/diffplug/spotless/pull/2633))
3030
* **BREAKING** `spotless:install-git-pre-push-hook` task is now always installed in the root `.git/hooks` directory by resolving the top-level project base directory. ([#2570](https://github.com/diffplug/spotless/pull/2570))
3131
* Bump JGit from `6.10.1` to `7.3.0` ([#2257](https://github.com/diffplug/spotless/pull/2257))
3232
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))

plugin-maven/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ any other maven phase (i.e. compile) then it can be configured as below;
231231
</importOrder>
232232

233233
<removeUnusedImports /> <!-- self-explanatory -->
234-
<forbidWildcardImports /> <!-- yell if any import ends with '*' -->
234+
<expandWildcardImports /> <!-- yell if any import ends with '*' -->
235235
<forbidModuleImports /> <!-- yell if any module imports are found (Java 25+) -->
236236

237237
<formatAnnotations /> <!-- fixes formatting of type annotations, see below -->
@@ -251,10 +251,10 @@ any other maven phase (i.e. compile) then it can be configured as below;
251251
</removeUnusedImports>
252252
```
253253

254-
### forbidWildcardImports
254+
### expandWildcardImports
255255

256256
```xml
257-
<forbidWildcardImports/>
257+
<expandWildcardImports/>
258258
```
259259

260260
### forbidModuleImports
@@ -1975,7 +1975,7 @@ Sometimes Spotless will encounter lint errors that can't be auto-fixed. For exam
19751975

19761976
```
19771977
[ERROR] Unable to format file src/main/java/com/example/App.java
1978-
[ERROR] Step 'forbidWildcardImports' found problem in 'App.java':
1978+
[ERROR] Step 'expandWildcardImports' found problem in 'App.java':
19791979
[ERROR] Do not use wildcard imports
19801980
```
19811981

@@ -1988,12 +1988,12 @@ To suppress these lints, you can use the `<lintSuppressions>` configuration:
19881988
<version>${spotless.version}</version>
19891989
<configuration>
19901990
<java>
1991-
<forbidWildcardImports/>
1991+
<expandWildcardImports/>
19921992
</java>
19931993
<lintSuppressions>
19941994
<lintSuppression>
19951995
<path>src/main/java/com/example/App.java</path>
1996-
<step>forbidWildcardImports</step>
1996+
<step>expandWildcardImports</step>
19971997
<shortCode>*</shortCode>
19981998
</lintSuppression>
19991999
</lintSuppressions>
@@ -2013,13 +2013,13 @@ You can suppress multiple patterns:
20132013
<!-- Suppress all wildcard import errors in legacy code -->
20142014
<lintSuppression>
20152015
<path>src/main/java/com/example/legacy/*</path>
2016-
<step>forbidWildcardImports</step>
2016+
<step>expandWildcardImports</step>
20172017
<shortCode>*</shortCode>
20182018
</lintSuppression>
20192019
<!-- Suppress all errors from a specific step -->
20202020
<lintSuppression>
20212021
<path>*</path>
2022-
<step>forbidWildcardImports</step>
2022+
<step>expandWildcardImports</step>
20232023
<shortCode>*</shortCode>
20242024
</lintSuppression>
20252025
</lintSuppressions>

0 commit comments

Comments
 (0)