Skip to content

Commit 4c93ebf

Browse files
authored
Add Detekt to the build (#422)
* Add Detekt to the build * Add detekt baseline
1 parent c998f97 commit 4c93ebf

File tree

5 files changed

+718
-0
lines changed

5 files changed

+718
-0
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ jobs:
2424
- uses: gradle/gradle-build-action@v2
2525
- name: Build
2626
run: ./gradlew :server:build :shared:build -PjavaVersion=${{ matrix.java }}
27+
- uses: gradle/gradle-build-action@v2
28+
- name: Detekt
29+
run: ./gradlew detekt

build.gradle.kts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import io.gitlab.arturbosch.detekt.Detekt
2+
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
3+
14
// TODO: change the hardcoded 1.6.10 to kotlinVeresion that lives in project props
25
// We could use a buildSrc script for this.
36
// See: https://github.com/gradle/kotlin-dsl-samples/issues/802
47
plugins {
58
kotlin("jvm") version "1.8.10"
69
`maven-publish`
10+
id("io.gitlab.arturbosch.detekt") version "1.22.0"
711
}
812

913
repositories {
@@ -33,3 +37,49 @@ configure(subprojects.filter { it.name != "grammars" }) {
3337
}
3438
}
3539
}
40+
41+
detekt {
42+
allRules = false // activate all available (even unstable) rules.
43+
buildUponDefaultConfig = true // preconfigure defaults
44+
parallel = true
45+
config = files("$rootDir/detekt.yml")
46+
baseline = file("$rootDir/detekt_baseline.xml")
47+
source = files(projectDir)
48+
}
49+
50+
// Registers a baseline for Detekt.
51+
//
52+
// The way it works is that you set create "baseline" for Detekt
53+
// by running this task. It will then creatae a detekt-baseline.xml which
54+
// contains a list of current issues found within the project.
55+
// Then every time you run the "detekt" task it will only report errors
56+
// that are not in the baseline config.
57+
//
58+
// We should routinely run this task and commit the baseline file as we
59+
// fix detekt issues so that we can prevent regressions.
60+
tasks.register<DetektCreateBaselineTask>("createDetektBaseline") {
61+
description = "Overrides current baseline."
62+
buildUponDefaultConfig.set(true)
63+
ignoreFailures.set(true)
64+
parallel.set(true)
65+
setSource(files(projectDir))
66+
config.setFrom(files("$rootDir/detekt.yml"))
67+
baseline.set(file("$rootDir/detekt_baseline.xml"))
68+
include("**/*.kt")
69+
include("**/*.kts")
70+
exclude("shared/build/**/*.*")
71+
exclude("server/build/**/*.*")
72+
}
73+
74+
tasks.withType<Detekt>().configureEach {
75+
reports {
76+
html.required.set(true)
77+
md.required.set(true)
78+
}
79+
}
80+
81+
tasks.withType<Detekt>().configureEach {
82+
jvmTarget = "11"
83+
}
84+
85+
tasks.check.get().dependsOn(tasks.detekt)

detekt.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
config:
2+
validation: true # verifies that this config file is valid
3+
warningsAsErrors: false

0 commit comments

Comments
 (0)