-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |