Skip to content

Commit d1bfde7

Browse files
committed
added ktlint
1 parent 30121ea commit d1bfde7

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ plugins {
1212
id("kotlin-parcelize")
1313
}
1414

15+
apply(from = "../ktlint.gradle.kts")
16+
1517
android {
1618
compileSdk = 30
1719
buildToolsVersion = "30.0.3"

install-git-hook.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
task installGitHook(type: Copy) {
3+
from new File(rootProject.rootDir, 'pre-commit')
4+
into { new File(rootProject.rootDir, '.git/hooks') }
5+
fileMode 0777
6+
}
7+
preBuild.dependsOn installGitHook

ktlint.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
val ktlint: Configuration by configurations.creating
2+
3+
dependencies {
4+
ktlint("com.pinterest:ktlint:0.41.0")
5+
// additional 3rd party ruleset(s) can be specified here
6+
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
7+
// ktlint will pick them up
8+
}
9+
10+
tasks.register<JavaExec>("ktlint") {
11+
group = "verification"
12+
description = "Check Kotlin code style."
13+
classpath = ktlint
14+
main = "com.pinterest.ktlint.Main"
15+
args("src/**/*.kt")
16+
}
17+
18+
tasks.named("check") {
19+
dependsOn(ktlint)
20+
}
21+
22+
tasks.register<JavaExec>("ktlintFormat") {
23+
group = "formatting"
24+
description = "Fix Kotlin code style deviations."
25+
classpath = ktlint
26+
main = "com.pinterest.ktlint.Main"
27+
args("-F", "src/**/*.kt")
28+
}

pre-commit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
echo "Running git pre-commit hook"
4+
5+
./gradlew ktlintFormat
6+
7+
RESULT=$?
8+
9+
# return 1 exit code if running checks fails
10+
[ $RESULT -ne 0 ] && exit 1
11+
exit 0

0 commit comments

Comments
 (0)