Skip to content

Commit

Permalink
feat: decorrelate spotless and ktlint (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMarquis authored Mar 14, 2024
1 parent cb51abf commit 285a103
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
14 changes: 12 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* SOFTWARE.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import kotlin.reflect.KProperty

plugins {
`kotlin-dsl`
Expand Down Expand Up @@ -81,6 +82,15 @@ fun NamedDomainObjectContainer<PluginDeclaration>.create(
this.implementationClass = implementationClass
}

private operator fun VersionCatalog.getValue(
thisRef: Any?,
property: KProperty<*>,
) = findVersion(property.name).orElseThrow {
IllegalStateException("Missing catalog version ${property.name}")
}

val ktlint: VersionConstraint by extensions.getByType<VersionCatalogsExtension>().named("libs")

// This block is a copy of SparkSpotlessPlugin since this included build can't use it's own plugins...
spotless {
val licenseHeader = rootProject.file("./../spotless/spotless.kt")
Expand All @@ -90,13 +100,13 @@ spotless {
}
kotlin {
target("src/**/*.kt")
ktlint()
ktlint(ktlint.toString())
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(licenseHeader)
}
kotlinGradle {
ktlint()
ktlint(ktlint.toString())
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal class SparkVersions(catalog: VersionCatalog) {
val `compileSdk` by catalog
val `kotlin` by catalog
val `showkase` by catalog
val `ktlint` by catalog

private operator fun VersionCatalog.getValue(
thisRef: Any?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal class SparkSpotlessPlugin : Plugin<Project> {
with(target) {
apply(plugin = "com.diffplug.spotless")

val ktlint = spark().versions.ktlint
configure<SpotlessExtension> {
val licenseHeader = rootProject.file("spotless/spotless.kt")
format("misc") {
Expand All @@ -40,14 +41,14 @@ internal class SparkSpotlessPlugin : Plugin<Project> {
}
kotlin {
target("src/**/*.kt")
ktlint()
ktlint(ktlint.toString())
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(licenseHeader)
targetExclude("spotless/*.kt")
}
kotlinGradle {
ktlint()
ktlint(ktlint.toString())
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ kotlinx-coroutines = "1.8.0"
kotlinx-collections-immutable = "0.3.7"
kotlinx-serialization-json = "1.6.3"
ksp = "1.9.22-1.0.18"
ktlint = "1.0.1"
lint = "31.3.0"
minCompileSdk = "24"
paparazzi = "1.3.1"
Expand Down Expand Up @@ -100,6 +101,8 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }

ktlint-bom = { module = "com.pinterest.ktlint:ktlint-bom", version.ref = "ktlint" }

lint = { module = "com.android.tools.lint:lint", version.ref = "lint" }
lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "lint" }
lint-checks = { module = "com.android.tools.lint:lint-checks", version.ref = "lint" }
Expand Down

0 comments on commit 285a103

Please sign in to comment.