Skip to content

Commit c12e164

Browse files
committed
Forbid wildcard imports
Needs to be implemented as an throwing custom step as Spotless doesn't have built in support to remove/deny wildcards: diffplug/spotless#649 Signed-off-by: Thomas Farr <[email protected]>
1 parent b4f49c0 commit c12e164

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

java-client/build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ spotless {
321321

322322
trimTrailingWhitespace()
323323
endWithNewline()
324+
325+
val wildcardImportRegex = Regex("""^import\s+(?:static\s+)?[^*\s]+\.\*;$""", RegexOption.MULTILINE)
326+
custom("Refuse wildcard imports") { contents ->
327+
// Wildcard imports can't be resolved by spotless itself.
328+
// This will require the developer themselves to adhere to best practices.
329+
if (wildcardImportRegex.containsMatchIn(contents)) {
330+
throw AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
331+
}
332+
contents
333+
}
324334
}
325335
}
326336

java-codegen/build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,15 @@ spotless {
273273

274274
trimTrailingWhitespace()
275275
endWithNewline()
276+
277+
val wildcardImportRegex = Regex("""^import\s+(?:static\s+)?[^*\s]+\.\*;$""", RegexOption.MULTILINE)
278+
custom("Refuse wildcard imports") { contents ->
279+
// Wildcard imports can't be resolved by spotless itself.
280+
// This will require the developer themselves to adhere to best practices.
281+
if (wildcardImportRegex.containsMatchIn(contents)) {
282+
throw AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
283+
}
284+
contents
285+
}
276286
}
277287
}

0 commit comments

Comments
 (0)