Skip to content

Commit

Permalink
Bump spotless to v7
Browse files Browse the repository at this point in the history
This updates spotless to v7

Kotlin lambdas can't be serialized effectively by {spotless / gradle}
right now so this replaces those lambdas with anonymous classes that
implement `FormatterFunc`
  • Loading branch information
JordonPhillips committed Feb 26, 2025
1 parent 16950dd commit 33e064b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions buildSrc/src/main/kotlin/smithy-java.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import com.diffplug.spotless.FormatterFunc
import com.github.spotbugs.snom.Effort
import java.util.regex.Pattern
import org.gradle.api.Project
import org.gradle.kotlin.dsl.the
import java.io.Serializable

plugins {
`java-library`
Expand Down Expand Up @@ -75,15 +77,25 @@ spotless {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
indentWithSpaces()
leadingTabsToSpaces()
endWithNewline()

eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")

// Fixes for some strange formatting applied by eclipse:
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") }
custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") }
// These have to be implemented with anonymous classes this way instead of lambdas because of:
// https://github.com/diffplug/spotless/issues/2387
custom("Lambda fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return input.replace("} )", "})").replace("} ,", "},")
}
})
custom("Long literal fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
}
})

// Static first, then everything else alphabetically
removeUnusedImports()
Expand All @@ -96,7 +108,7 @@ spotless {
// Formatting for build.gradle.kts files
kotlinGradle {
ktlint()
indentWithSpaces()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ smithy = "1.54.0"
jmh = "0.7.3"
test-logger-plugin = "4.0.0"
spotbugs = "6.0.22"
spotless = "6.25.0"
spotless = "7.0.2"
smithy-gradle-plugins = "1.2.0"
assertj = "3.27.3"
jackson = "2.18.2"
Expand Down

0 comments on commit 33e064b

Please sign in to comment.