Skip to content

Commit 6e409dc

Browse files
committed
build: lint code with detekt
[Detekt](https://detekt.dev/) is a linter that is focused on code issues, whereas ktlint mostly focuses on style. This commit includes detekt in the Gradle project as an optional feature. No build will fail atm due to linting errors. We can use this as a hint when developing.
1 parent 6084aa6 commit 6e409dc

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.detekt.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
style:
2+
# handled by ktlint
3+
MaxLineLength:
4+
active: false
5+
ModifierOrder:
6+
active: false
7+
8+
# No need for this
9+
ReturnCount:
10+
active: false
11+
ThrowsCount:
12+
active: false

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import com.github.gradle.node.NodeExtension
22
import com.github.gradle.node.NodePlugin
3+
import io.gitlab.arturbosch.detekt.Detekt
34
import kotlinx.html.FlowContent
45
import kotlinx.html.a
56
import kotlinx.html.body
@@ -44,6 +45,7 @@ plugins {
4445
alias(libs.plugins.tasktree)
4546
alias(libs.plugins.dokka)
4647
alias(libs.plugins.node) apply false
48+
alias(libs.plugins.detekt) apply false
4749
}
4850

4951
group = "org.modelix"
@@ -65,11 +67,14 @@ dependencies {
6567
dokkaPlugin(libs.dokka.versioning)
6668
}
6769

70+
val parentProject = project
71+
6872
subprojects {
6973
val subproject = this
7074
apply(plugin = "maven-publish")
7175
apply(plugin = "org.jetbrains.dokka")
7276
apply(plugin = "org.jlleitschuh.gradle.ktlint")
77+
apply(plugin = "io.gitlab.arturbosch.detekt")
7378

7479
version = rootProject.version
7580
group = rootProject.group
@@ -85,6 +90,22 @@ subprojects {
8590
version.set("0.50.0")
8691
}
8792

93+
tasks.withType<Detekt> {
94+
parallel = true
95+
// For now, we only use the results here as hints
96+
ignoreFailures = true
97+
98+
buildUponDefaultConfig = true
99+
config.setFrom(parentProject.projectDir.resolve(".detekt.yml"))
100+
101+
reports {
102+
sarif.required.set(true)
103+
// This is required for the GitHub upload action to easily find all sarif files in a single directory.
104+
sarif.outputLocation.set(parentProject.buildDir.resolve("reports/detekt/${project.name}.sarif"))
105+
html.required.set(true)
106+
}
107+
}
108+
88109
val kotlinApiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6
89110
subproject.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
90111
if (!name.lowercase().contains("test")) {

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tasktree = { id = "com.dorongold.task-tree", version = "2.1.1" }
1717
modelix-mps-buildtools = { id = "org.modelix.mps.build-tools", version = "1.1.0" }
1818
dokka = {id = "org.jetbrains.dokka", version = "1.9.0"}
1919
node = {id = "com.github.node-gradle.node", version = "7.0.1"}
20+
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.1" }
2021

2122
[versions]
2223
kotlin = "1.9.10"

0 commit comments

Comments
 (0)