Skip to content

Commit 1119cad

Browse files
committed
🧑‍💻 pre-commit hook
1 parent 4f29ab2 commit 1119cad

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.{kt,kts}]
2+
ktlint_standard_no-wildcard-imports = disabled
3+
ktlint_standard_max-line-length = disabled

.idea/codeStyles/Project.xml

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

+26-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ val postgresqlVersion = "42.7.2"
1212

1313
plugins {
1414
kotlin("jvm") version "1.9.22"
15+
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
1516
}
1617

1718
val githubUser: String by project
@@ -33,13 +34,14 @@ allprojects {
3334
}
3435

3536
apply(plugin = "org.jetbrains.kotlin.jvm")
37+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
3638

3739
dependencies {
3840
implementation("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion")
3941
implementation("io.ktor:ktor-server-cio:$ktorVersion")
4042
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
4143
implementation("org.postgresql:postgresql:$postgresqlVersion")
42-
implementation("com.papertrailapp:logback-syslog4j:$logbackSyslog4jVersion") //August, 2014
44+
implementation("com.papertrailapp:logback-syslog4j:$logbackSyslog4jVersion") // August, 2014
4345
{
4446
exclude(group = "ch.qos.logback")
4547
}
@@ -87,6 +89,15 @@ allprojects {
8789
}
8890
testImplementation("io.mockk:mockk:$mockkVersion")
8991
}
92+
93+
ktlint {
94+
// Hvis du gjør endringer i disse filterne må du slette alle "build"/"out"-mappene og deretter
95+
// kjøre ./gradlew --no-build-cache ktlintCheck minst én gang for at endringene skal ta effekt
96+
filter {
97+
exclude { it.file.path.contains("generated") }
98+
exclude { it.file.path.contains("test") }
99+
}
100+
}
90101
}
91102

92103
subprojects {
@@ -108,6 +119,18 @@ subprojects {
108119
}
109120
}
110121

111-
tasks.jar {
112-
enabled = false
122+
tasks {
123+
register<Copy>("copyPreCommitHook") {
124+
description = "Kopierer pre-commit hook fra scripts til .git/hooks"
125+
outputs.upToDateWhen { false }
126+
from("$rootDir/scripts/pre-commit")
127+
into("$rootDir/.git/hooks")
128+
}
129+
130+
jar {
131+
enabled = false
132+
}
133+
build {
134+
dependsOn("copyPreCommitHook")
135+
}
113136
}

scripts/pre-commit

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "Running git pre-commit hook"
4+
5+
./gradlew ktlintCheck
6+
7+
ktlintCheckStatus=$?
8+
9+
if [[ $ktlintCheckStatus -ne 0 ]]; then
10+
exit 1
11+
else
12+
exit 0
13+
fi

0 commit comments

Comments
 (0)