Skip to content

Commit 4aa1aed

Browse files
Avoid lambda functions in spotless config
Kotlin lambdas can't be serialized effectively by {spotless / gradle} right now so this replaces those lambdas with anonymous classes that implement `FormatterFunc`
1 parent 82ee71a commit 4aa1aed

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

codegen/buildSrc/src/main/kotlin/smithy-python.java-conventions.gradle.kts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import com.diffplug.spotless.FormatterFunc
12
import com.github.spotbugs.snom.Effort
23
import java.util.regex.Pattern
34
import org.gradle.api.Project
45
import org.gradle.kotlin.dsl.the
6+
import java.io.Serializable
57

68
plugins {
79
`java-library`
@@ -71,15 +73,25 @@ spotless {
7173
// Enforce a common license header on all files
7274
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
7375
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
74-
indentWithSpaces()
76+
leadingTabsToSpaces()
7577
endWithNewline()
7678

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

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

8496
// Static first, then everything else alphabetically
8597
removeUnusedImports()
@@ -92,7 +104,7 @@ spotless {
92104
// Formatting for build.gradle.kts files
93105
kotlinGradle {
94106
ktlint()
95-
indentWithSpaces()
107+
leadingTabsToSpaces()
96108
trimTrailingWhitespace()
97109
endWithNewline()
98110
}

0 commit comments

Comments
 (0)