Skip to content

Commit

Permalink
[lint] Execute ktlintCheck prior to every git commit to scan for lint…
Browse files Browse the repository at this point in the history
… errors
  • Loading branch information
tuancoltech committed Oct 31, 2023
1 parent 8a3534c commit ddf79e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 16 additions & 4 deletions app/app-scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/bin/sh
#!/bin/bash
echo "*********************************************************"
echo "Running git pre-commit hook, ktlintCheck in progress..."
echo "*********************************************************"

echo "*****Running unit tests******"
./gradlew ktlintCheck

git stash -q --keep-index
status=$?

./gradlew ktlintCheck
if [ "$status" = 0 ] ; then
echo "Static analysis found no problems."
exit 0
else
echo "*********************************************************"
echo 1>&2 "ktlintCheck found violations it could not fix."
echo "Run ./gradlew ktlintFormat to fix formatting related issues..."
echo "*********************************************************"
exit 1
fi
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//file:noinspection GroovyConstructorNamedArguments
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
Expand All @@ -12,7 +11,7 @@ apply plugin: 'kotlin-parcelize'
apply plugin: "de.mannodermaus.android-junit5"

android {
compileSdk 33
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand Down Expand Up @@ -198,3 +197,5 @@ tasks.register('installGitHook', Copy) {
rename("pre-commit-$suffix", 'pre-commit')
fileMode 0775
}

build.dependsOn installGitHook

0 comments on commit ddf79e5

Please sign in to comment.