-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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]> * Make conventions plugin Signed-off-by: Thomas Farr <[email protected]> * Fix wildcard imports Signed-off-by: Thomas Farr <[email protected]> * Allow overriding eclipse formatter config file Signed-off-by: Thomas Farr <[email protected]> * Fix message formatting Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]>
- Loading branch information
Showing
12 changed files
with
114 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 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
58 changes: 58 additions & 0 deletions
58
buildSrc/src/main/kotlin/opensearch-java.spotless-conventions.gradle.kts
This file contains 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,58 @@ | ||
plugins { | ||
id("com.diffplug.spotless") | ||
} | ||
|
||
interface SpotlessConventionsPluginExtension { | ||
val eclipseFormatterConfigFile: RegularFileProperty | ||
} | ||
|
||
val extension = project.extensions.create<SpotlessConventionsPluginExtension>("spotlessConventions") | ||
|
||
extension.eclipseFormatterConfigFile.convention(rootProject.layout.projectDirectory.file("buildSrc/formatterConfig.xml")) | ||
|
||
spotless { | ||
java { | ||
target("**/*.java") | ||
|
||
licenseHeaderFile(rootProject.file("LICENSE_HEADER.txt")) | ||
.named("PrimaryLicenseHeader") | ||
.onlyIfContentMatches("^((?!Licensed to Elasticsearch)[\\s\\S])*$") | ||
.delimiter("(package |//-----)") | ||
|
||
licenseHeaderFile(rootProject.file("LICENSE_HEADER_FORKED.txt")) | ||
.named("ForkedLicenseHeader") | ||
.onlyIfContentMatches("Licensed to Elasticsearch") | ||
.delimiter("(package |//-----)") | ||
|
||
// Use the default importOrder configuration | ||
importOrder() | ||
removeUnusedImports() | ||
|
||
eclipse().configFile(extension.eclipseFormatterConfigFile) | ||
|
||
trimTrailingWhitespace() | ||
endWithNewline() | ||
|
||
// NOTE: Any time a custom step below is modified, bump this number. | ||
// Allows up-to-date checks to work correctly with custom steps. | ||
bumpThisNumberIfACustomStepChanges(1) | ||
|
||
val wildcardImportRegex = Regex("""^import\s+(?:static\s+)?[^*\s]+\.\*;$""", RegexOption.MULTILINE) | ||
custom("Refuse wildcard imports") { contents -> | ||
// Wildcard imports can't be resolved by spotless itself. | ||
// This will require the developer themselves to adhere to best practices. | ||
val wildcardImports = wildcardImportRegex.findAll(contents) | ||
if (wildcardImports.any()) { | ||
var msg = """ | ||
Please replace the following wildcard imports with explicit imports ('spotlessApply' cannot resolve this issue): | ||
""".trimIndent() | ||
wildcardImports.forEach { | ||
msg += "\n\t- ${it.value}" | ||
} | ||
msg += "\n" | ||
throw AssertionError(msg) | ||
} | ||
contents | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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
8 changes: 8 additions & 0 deletions
8
samples/src/main/java/org/opensearch/client/samples/FlatObjectBasics.java
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
samples/src/main/java/org/opensearch/client/samples/util/IssueDocument.java
This file contains 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