Skip to content

Commit

Permalink
added ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcsxsiq committed Jul 25, 2021
1 parent 30121ea commit d1bfde7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
id("kotlin-parcelize")
}

apply(from = "../ktlint.gradle.kts")

android {
compileSdk = 30
buildToolsVersion = "30.0.3"
Expand Down
7 changes: 7 additions & 0 deletions install-git-hook.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

task installGitHook(type: Copy) {
from new File(rootProject.rootDir, 'pre-commit')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0777
}
preBuild.dependsOn installGitHook
28 changes: 28 additions & 0 deletions ktlint.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
val ktlint: Configuration by configurations.creating

dependencies {
ktlint("com.pinterest:ktlint:0.41.0")
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}

tasks.register<JavaExec>("ktlint") {
group = "verification"
description = "Check Kotlin code style."
classpath = ktlint
main = "com.pinterest.ktlint.Main"
args("src/**/*.kt")
}

tasks.named("check") {
dependsOn(ktlint)
}

tasks.register<JavaExec>("ktlintFormat") {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = ktlint
main = "com.pinterest.ktlint.Main"
args("-F", "src/**/*.kt")
}
11 changes: 11 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo "Running git pre-commit hook"

./gradlew ktlintFormat

RESULT=$?

# return 1 exit code if running checks fails
[ $RESULT -ne 0 ] && exit 1
exit 0

0 comments on commit d1bfde7

Please sign in to comment.