Skip to content

Commit cdd2c81

Browse files
committed
Added detekt
1 parent d98017f commit cdd2c81

File tree

18 files changed

+99
-13
lines changed

18 files changed

+99
-13
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ jobs:
3737
# TODO: switch to Kover
3838
# - name: Create coverage report
3939
# run: ./gradlew jacocoTestReportDefault
40-
- name: Final checks
40+
- name: ktlint
4141
run: ./gradlew ktlint
42+
- name: detekt
43+
run: ./gradlew detekt
4244

4345
# Publish packages
4446
- name: Publish package

build-logic/build-logic-base/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
dependencies {
77
api(libs.android.gradle)
88
api(libs.kotlin.gradle)
9+
api(libs.detekt.gradle)
910
api(libs.dokka.gradle)
1011
}
1112

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.ensody.buildlogic
2+
3+
import org.gradle.api.Project
4+
import org.gradle.kotlin.dsl.assign
5+
import org.gradle.kotlin.dsl.withType
6+
7+
fun Project.setupDetekt() {
8+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
9+
// Enable type resolution
10+
classpath = detektClasspath
11+
jvmTarget = "17"
12+
13+
config.from(
14+
*listOf(
15+
rootProject.file("build-logic/build-logic/src/main/resources/detekt.yml"),
16+
rootProject.file("build-logic/build-logic-base/src/main/resources/detekt.yml"),
17+
).filter { it.exists() }.toTypedArray(),
18+
)
19+
buildUponDefaultConfig = true
20+
21+
setSource(
22+
files(
23+
file("src").listFiles().filter {
24+
it.name.endsWith("Main") || it.name.endsWith("Test") || it.name in setOf("main", "test")
25+
}.flatMap {
26+
listOf(it.resolve("kotlin"), it.resolve("java"))
27+
},
28+
),
29+
)
30+
}
31+
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
32+
jvmTarget = "17"
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
complexity:
2+
active: false
3+
4+
coroutines:
5+
InjectDispatcher:
6+
dispatcherNames:
7+
- 'Main'
8+
- 'IO'
9+
- 'Default'
10+
- 'Unconfined'
11+
12+
exceptions:
13+
TooGenericExceptionCaught:
14+
active: false
15+
16+
naming:
17+
FunctionNaming:
18+
functionPattern: '[a-zA-Z][a-zA-Z0-9]*'
19+
MatchingDeclarationName:
20+
active: false
21+
22+
potential-bugs:
23+
IgnoredReturnValue:
24+
active: false
25+
26+
style:
27+
ForbiddenComment:
28+
active: false
29+
MayBeConst:
30+
active: false
31+
ReturnCount:
32+
active: false
33+
UnnecessaryAbstractClass:
34+
active: false
35+
UnusedPrivateMember:
36+
allowedNames: "readResolve"
37+
UseOrEmpty:
38+
active: false

build-logic/build-logic/src/main/kotlin/com/ensody/buildlogic/BuildLogicPlugin.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package com.ensody.buildlogic
44

55
import com.android.build.gradle.BaseExtension
66
import io.github.gradlenexus.publishplugin.NexusPublishExtension
7+
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
78
import org.gradle.api.Plugin
89
import org.gradle.api.Project
9-
import org.gradle.api.artifacts.ProjectDependency
1010
import org.gradle.api.plugins.JavaPlatformExtension
1111
import org.gradle.api.publish.PublishingExtension
1212
import org.gradle.kotlin.dsl.assign
@@ -32,6 +32,7 @@ class BuildLogicPlugin : Plugin<Project> {
3232
pluginManager.apply("org.jetbrains.compose")
3333
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")
3434
}
35+
pluginManager.apply("io.gitlab.arturbosch.detekt")
3536
}
3637
pluginManager.apply("maven-publish")
3738
}
@@ -111,6 +112,9 @@ fun Project.setupBuildLogic(block: Project.() -> Unit) {
111112
if (extensions.findByType<KotlinBaseExtension>() != null) {
112113
setupKtLint(libs.findLibrary("ktlint-cli").get())
113114
}
115+
if (extensions.findByType<DetektExtension>() != null) {
116+
setupDetekt()
117+
}
114118
if (extensions.findByType<DokkaExtension>() != null) {
115119
setupDokka(copyright = "Ensody GmbH")
116120
}

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ plugins {
44
id("com.ensody.build-logic")
55
alias(libs.plugins.android.application) apply false
66
alias(libs.plugins.kotlin.android) apply false
7+
alias(libs.plugins.kotlin.jvm) apply false
78
alias(libs.plugins.jetbrains.compose) apply false
89
alias(libs.plugins.kotlin.compose) apply false
910
alias(libs.plugins.dokka) apply false
11+
alias(libs.plugins.detekt)
1012
alias(libs.plugins.nexusPublish)
1113
}
1214

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ androidxTestCore = "1.6.1"
88
androidGradle = "8.8.2"
99
dokka = "2.0.0"
1010
desugarJdkLibs = "2.1.5"
11+
detekt = "1.23.8"
1112
nexusPublish = "2.0.0"
1213

1314
[libraries]
@@ -45,12 +46,15 @@ robolectric = { module = "org.robolectric:robolectric", version = "4.14.1" }
4546
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" }
4647
kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
4748
dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
49+
detekt-gradle = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
4850
nexus-gradle = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexusPublish" }
4951

5052
[plugins]
5153
android-application = { id = "com.android.application", version.ref = "androidGradle" }
5254
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
5355
jetbrains-compose = { id = "org.jetbrains.compose", version = "1.7.3" }
5456
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
57+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
5558
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
59+
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
5660
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }

reactivestate-android/src/androidMain/kotlin/com/ensody/reactivestate/android/ReactiveViewModelExt.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public inline fun <reified T : CoroutineLauncher> ComponentActivity.reactiveView
5151
public fun Lazy<CoroutineLauncher>.attachLazyReactiveViewModel(
5252
owner: LifecycleOwner,
5353
) {
54-
if (owner !is ErrorEvents) {
55-
throw IllegalStateException("You have to implement the ErrorEvents interface.")
56-
}
54+
check(owner is ErrorEvents) { "You have to implement the ErrorEvents interface." }
5755
owner.onStart {
5856
val viewModel = value
5957
val emittedErrors = ContextualErrorsFlow.get(viewModel.scope)
@@ -91,9 +89,7 @@ public fun <E : ErrorEvents> Lazy<ReactiveState<E>>.attachLazyReactiveState(
9189
handler: E?,
9290
owner: LifecycleOwner,
9391
) {
94-
if (handler == null) {
95-
throw IllegalStateException("You have to implement the ViewModel's events interface.")
96-
}
92+
checkNotNull(handler) { "You have to implement the ViewModel's events interface." }
9793
owner.launchOnceStateAtLeast(Lifecycle.State.CREATED) {
9894
value.eventNotifier.handleEvents(handler, owner)
9995
}

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/AutoRunWhileUsed.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.ensody.reactivestate
33
/** Returns [WhileUsed]'s value and keeps it alive as long as it's still used. */
44
public fun <T> Resolver.get(data: WhileUsed<T>): T {
55
val value = track(data) { WhileUsedObservable(data) }.value
6-
require(value != null) { "Fatal error: The observer couldn't be started." }
6+
requireNotNull(value) { "Fatal error: The observer couldn't be started." }
77
return value.value
88
}
99

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/CoroutineDispatcherConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface CoroutineDispatcherConfig {
1919
}
2020

2121
/** The default [CoroutineDispatcherConfig], mapping to [Dispatchers]. */
22+
@Suppress("InjectDispatcher")
2223
public object DefaultCoroutineDispatcherConfig : CoroutineDispatcherConfig {
2324
override val main: CoroutineDispatcher get() = Dispatchers.Main
2425
override val default: CoroutineDispatcher get() = Dispatchers.Default

0 commit comments

Comments
 (0)