diff --git a/.editorconfig b/.editorconfig
index ef1be2e92..98e140b3a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,20 +1,35 @@
-# EditorConfig is awesome: https://EditorConfig.org
-
-# top-most EditorConfig file
-root = true
-
-# Unix-style newlines with a newline ending every file
[*]
-end_of_line = lf
-indent_style = space
-indent_size = 2
-insert_final_newline = true
-charset = utf-8
-# android studio / intellij specific, also in squares android style guide:
-# https://github.com/kiwix/kiwix-android/blob/master/docs/codestyle.md
-continuation_indent_size = 4
+charset=utf-8
+end_of_line=lf
+insert_final_newline=true
+indent_style=space
+indent_size=2
-# windows command files need windows newline
-[*.{bat, cmd}]
-end_of_line = crlf
+[{*.sht,*.html,*.shtm,*.shtml,*.htm}]
+indent_style=space
+indent_size=4
+
+[*.json]
+indent_style=space
+indent_size=2
+
+[*.properties]
+indent_style=space
+indent_size=4
+
+[.editorconfig]
+indent_style=space
+indent_size=4
+
+[{*.pyw,*.py}]
+indent_style=space
+indent_size=4
+
+[{*.yml,*.yaml}]
+indent_style=space
+indent_size=2
+
+[{*.markdown,*.md,*.mkd}]
+indent_style=space
+indent_size=4
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index d8199641c..b7c6bc1aa 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -9,6 +9,7 @@
+
diff --git a/app/build.gradle b/app/build.gradle
index aa0b4b994..c331b4e3b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -457,6 +457,10 @@ play {
resolutionStrategy = "fail"
}
+ktlint{
+ android = true
+}
+
class TestDroidUpload extends TestServer {
def buildNumber = System.getenv("TRAVIS_BUILD_NUMBER")
def API_KEY = System.getenv("PUBLIC_TESTDROID_API_KEY")
@@ -497,3 +501,10 @@ class TestDroidUpload extends TestServer {
return true
}
}
+
+apply from: "${rootDir}/team-props/git-hooks.gradle"
+afterEvaluate {
+ android.applicationVariants.all { variant ->
+ variant.preBuild.dependsOn(installGitHooks)
+ }
+}
diff --git a/team-props/git-hooks.gradle b/team-props/git-hooks.gradle
new file mode 100644
index 000000000..83bd52f00
--- /dev/null
+++ b/team-props/git-hooks.gradle
@@ -0,0 +1,26 @@
+static def isLinuxOrMacOs() {
+ def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
+ return osName.contains('linux') || osName.contains('mac os') || osName.contains('macos')
+}
+
+task copyGitHooks(type: Copy) {
+ description 'Copies the git hooks from team-props/git-hooks to the .git folder.'
+ from("${rootDir}/team-props/git-hooks/") {
+ include '**/*.sh'
+ rename '(.*).sh', '$1'
+ }
+ into "${rootDir}/.git/hooks"
+}
+
+task installGitHooks(type: Exec) {
+ description 'Installs the pre-commit git hooks from team-props/git-hooks.'
+ group 'git hooks'
+ workingDir rootDir
+ commandLine 'chmod'
+ args '-R', '+x', '.git/hooks/'
+ onlyIf { isLinuxOrMacOs() }
+ dependsOn copyGitHooks
+ doLast {
+ logger.info('Git hook installed successfully.')
+ }
+}
diff --git a/team-props/git-hooks/pre-commit.sh b/team-props/git-hooks/pre-commit.sh
new file mode 100644
index 000000000..2e88dc812
--- /dev/null
+++ b/team-props/git-hooks/pre-commit.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+echo "Running formatter..."
+# Format code using KtLint, analyze with KtLint & Lint
+
+./gradlew app:ktlintKiwixDebugFormat app:ktlintKiwixDebugCheck app:lintKiwixDebug --daemon
+
+status=$?
+
+if [ "$status" = 0 ] ; then
+ echo "Static analysis found no problems."
+ exit 0
+else
+ echo 1>&2 "Static analysis found violations it could not fix."
+ exit 1
+fi