Skip to content

Commit 531a545

Browse files
committed
Update ktlint configuration and automate formatting during build
- Add `.editorconfig` with specific rules for ktlint, including disabling wildcard import checks and ignoring naming conventions for `@Composable` functions. - Centralize ktlint task execution by adding a `subprojects` block in the root `build.gradle.kts` that makes build and compilation tasks depend on `ktlintFormat`. - Remove manual `ktlint` plugin application from individual convention plugins (`CmpFeature`, `CmpLibrary`, `KmpLibrary`, `AndroidApplication`, `CmpApplication`). - Update `KtlintConventionPlugin` to exclude generated files and schemas, and configure PLAIN and HTML reporters. - Remove the automatic git pre-commit hook task dependency from `build-logic`. - Add `slf4j-simple` dependency to `libs.versions.toml`.
1 parent 04375f0 commit 531a545

10 files changed

Lines changed: 32 additions & 12 deletions

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root = true
2+
3+
[*.{kt,kts}]
4+
ktlint_standard_filename = disabled
5+
ktlint_standard_no-wildcard-imports = disabled
6+
ktlint_function_naming_ignore_when_annotated_with = Composable

build-logic/convention/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ tasks {
3636
enableStricterValidation = true
3737
failOnWarning = true
3838
}
39-
configureEach {
40-
if (name == "preBuild") {
41-
dependsOn("addKtlintFormatGitPreCommitHook")
42-
}
43-
}
4439
}
4540

4641
gradlePlugin {

build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
1010
with(target) {
1111
with(pluginManager) {
1212
apply("com.android.application")
13-
apply("zed.rainxch.convention.ktlint")
1413
}
1514

1615
extensions.configure<ApplicationExtension> {

build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class CmpApplicationConventionPlugin : Plugin<Project> {
1313
apply("org.jetbrains.kotlin.multiplatform")
1414
apply("org.jetbrains.compose")
1515
apply("org.jetbrains.kotlin.plugin.compose")
16-
apply("zed.rainxch.convention.ktlint")
1716
}
1817

1918
configureAndroidTarget()

build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class CmpFeatureConventionPlugin : Plugin<Project> {
88
with(target) {
99
with(pluginManager) {
1010
apply("zed.rainxch.convention.cmp.library")
11-
apply("zed.rainxch.convention.ktlint")
1211
}
1312

1413
dependencies {

build-logic/convention/src/main/kotlin/CmpLibraryConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class CmpLibraryConventionPlugin : Plugin<Project> {
1111
apply("zed.rainxch.convention.kmp.library")
1212
apply("org.jetbrains.kotlin.plugin.compose")
1313
apply("org.jetbrains.compose")
14-
apply("zed.rainxch.convention.ktlint")
1514
}
1615

1716
dependencies {

build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class KmpLibraryConventionPlugin : Plugin<Project> {
1515
apply("com.android.library")
1616
apply("org.jetbrains.kotlin.multiplatform")
1717
apply("org.jetbrains.kotlin.plugin.serialization")
18-
apply("zed.rainxch.convention.ktlint")
1918
}
2019

2120
configureKotlinMultiplatform()

build-logic/convention/src/main/kotlin/KtlintConventionPlugin.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ class KtlintConventionPlugin : Plugin<Project> {
1010
extensions.configure(KtlintExtension::class.java) {
1111
version.set("1.8.0")
1212
outputToConsole.set(true)
13-
ignoreFailures.set(false)
13+
ignoreFailures.set(true)
1414
filter {
1515
exclude("**/generated/**")
1616
exclude("**/build/**")
17+
exclude("**/*.g.kt")
18+
exclude("**/schemas/**")
19+
}
20+
reporters {
21+
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
22+
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.HTML)
1723
}
1824
}
1925
}
2026
}
21-
}
27+
}

build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ plugins {
1010
alias(libs.plugins.ksp) apply false
1111
alias(libs.plugins.room) apply false
1212
}
13+
14+
subprojects {
15+
afterEvaluate {
16+
tasks.configureEach {
17+
when (name) {
18+
"preBuild",
19+
"compileKotlinJvm",
20+
"compileKotlinAndroid",
21+
-> {
22+
val ktlintFormat = tasks.findByName("ktlintFormat")
23+
if (ktlintFormat != null) dependsOn(ktlintFormat)
24+
}
25+
}
26+
}
27+
}
28+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ kotlinx-collections-immutable = "0.4.0"
3030
koin = "4.1.1"
3131
ktor = "3.4.0"
3232
room = "2.8.4"
33+
slf4jSimple = "2.0.17"
3334
sqlite = "2.6.2"
3435
datastore = "1.2.0"
3536
compose-jetbrains = "1.10.1"
@@ -100,6 +101,7 @@ datastore-preferences = { module = "androidx.datastore:datastore-preferences", v
100101
# Room
101102
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
102103
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
104+
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4jSimple" }
103105
sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
104106

105107
# Image loading

0 commit comments

Comments
 (0)