Skip to content

Commit 6fc0a70

Browse files
Move Konsist checks into desktopTest and add kotlin test dependency
1 parent 789a8a2 commit 6fc0a70

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

composeApp/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ kotlin {
7171

7272
sourceSets {
7373
val desktopMain by getting
74+
val commonMain by getting
75+
val commonTest by getting
76+
77+
val desktopTest by getting {
78+
dependencies {
79+
implementation(kotlin("test"))
80+
implementation(libs.konsist)
81+
}
82+
}
7483

7584
androidMain.dependencies {
7685
implementation(libs.androidx.activity.compose)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import kotlin.test.Test
2+
import kotlin.test.assertTrue
3+
import com.lemonappdev.konsist.api.Konsist
4+
5+
class SampleKonsistTest {
6+
7+
@Test
8+
fun `no direct usage of androidx compose text should be allowed except designSystem`() {
9+
checkNoDirectUsageExceptAllowed(
10+
componentName = "androidx.compose.material3.Text",
11+
excludePaths = arrayOf(),
12+
)
13+
}
14+
}
15+
16+
fun checkNoDirectUsageExceptAllowed(
17+
componentName: String,
18+
excludePaths: Array<String>,
19+
) {
20+
val offendingFiles = Konsist.scopeFromProject()
21+
.files
22+
.filter { file ->
23+
val normalizedFilePath = file.path.replace("\\", "/").lowercase()
24+
excludePaths.none { normalizedFilePath.contains(it.replace("\\", "/").lowercase()) }
25+
}
26+
.filter { file ->
27+
file.imports.any { it.name == componentName }
28+
}
29+
30+
assertTrue(
31+
actual = offendingFiles.isEmpty(),
32+
message = "Found forbidden imports of $componentName in files:\n" + offendingFiles.joinToString("\n") { it.path },
33+
)
34+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ compose-multiplatform = "1.7.3"
1616
generativeai = "0.9.0"
1717
junit = "4.13.2"
1818
kermit = "2.0.4"
19+
konsist = "0.17.3"
1920
kotlin = "2.1.10"
2021
kotlinx-coroutines = "1.10.2"
2122
kotlinx-serialization-json = "1.7.3"
@@ -35,6 +36,7 @@ arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrowFxCoroutin
3536
arrow-fx-coroutines = { module = "io.arrow-kt:arrow-fx-coroutines", version.ref = "arrowFxCoroutines" }
3637
generativeai = { module = "com.google.ai.client.generativeai:generativeai", version.ref = "generativeai" }
3738
kermit = { module = "co.touchlab:kermit", version.ref = "kermit" }
39+
konsist = { module = "com.lemonappdev:konsist", version.ref = "konsist" }
3840
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
3941
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
4042
junit = { group = "junit", name = "junit", version.ref = "junit" }

0 commit comments

Comments
 (0)