-
Notifications
You must be signed in to change notification settings - Fork 3
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
9 changed files
with
153 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{kt,kts}] | ||
ij_kotlin_allow_trailing_comma = true | ||
ij_kotlin_allow_trailing_comma_on_call_site = true |
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 @@ | ||
theme: jekyll-theme-cayman |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
object BuildScripts { | ||
const val KTLINT = "buildscripts/ktlint.gradle" | ||
const val VERSIONS = "buildscripts/versions.gradle" | ||
private const val DEFAULT_PATH = "buildscripts/" | ||
|
||
const val KTLINT = DEFAULT_PATH.plus("ktlint.gradle") | ||
const val VERSIONS = DEFAULT_PATH.plus("versions.gradle") | ||
const val HOOKS = DEFAULT_PATH.plus("hooks.gradle") | ||
} |
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 @@ | ||
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 /git-hooks to the .git folder.' | ||
group 'git hooks' | ||
from("${rootDir}/git-hooks/") { | ||
include '**/*.sh' | ||
rename '(.*).sh', '$1' | ||
} | ||
into "${rootDir}/.git/hooks" | ||
onlyIf { isLinuxOrMacOs() } | ||
} | ||
|
||
task installGitHooks(type: Exec) { | ||
description 'Installs the pre-commit git hooks from /git-hooks.' | ||
group 'git hooks' | ||
workingDir rootDir | ||
commandLine 'chmod' | ||
args '-R', '+x', '.git/hooks/' | ||
dependsOn copyGitHooks | ||
onlyIf { isLinuxOrMacOs() } | ||
doLast { | ||
logger.info('Git hook installed successfully.') | ||
} | ||
} |
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,21 @@ | ||
# Git Hooks | ||
|
||
This project has some Git hooks included inside the [git-hooks](/hooks) folder. These hooks can be | ||
installed automatically via the Gradle commands `./gradlew copyGitHooks` | ||
and `./gradlew installGitHooks`. You can find these commands | ||
in [this Gradle file](/buildscripts/githooks.gradle), but it's also good to know that the hooks are | ||
installed automatically just by running a `clean` task. | ||
|
||
## Pre-Commit | ||
|
||
There is a [pre-commit](/hooks/pre-commit.sh) hook that will automatically run Ktlint formatting | ||
over any modified Kotlin files. | ||
This way you can just commit your code and trust that formatting happens behind the scenes, | ||
without having to consciously worry about it. | ||
|
||
## Pre-Push | ||
|
||
There is a [pre-push](/hooks/pre-push.sh) hook that will run static analysis checks before any code | ||
is pushed up to the remote repository. | ||
This way, if you have any code smells, you can be alerted right away without waiting for | ||
some Github Actions to fail. |
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,26 @@ | ||
#!/bin/sh | ||
|
||
######## KTLINT-GRADLE HOOK START ######## | ||
|
||
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.kt/ { print $2}')" | ||
|
||
if [ -z "$CHANGED_FILES" ]; then | ||
echo "No Kotlin staged files." | ||
exit 0 | ||
fi; | ||
|
||
echo "Running ktlint over these files:" | ||
echo "$CHANGED_FILES" | ||
|
||
./gradlew --quiet ktlintFormat -PinternalKtlintGitFilter="$CHANGED_FILES" | ||
|
||
echo "Completed ktlint run." | ||
|
||
echo "$CHANGED_FILES" | while read -r file; do | ||
if [ -f $file ]; then | ||
git add $file | ||
fi | ||
done | ||
|
||
echo "Completed ktlint hook." | ||
######## KTLINT-GRADLE HOOK END ######## |
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,6 @@ | ||
#!/bin/sh | ||
|
||
echo "Running static analysis." | ||
|
||
./gradlew ktlintCheck | ||
./gradlew detektAll |
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,56 @@ | ||
# This takes all ktlint output XML files and combines them into one `ktlint-report.xml` file. | ||
|
||
import sys | ||
import os.path | ||
from xml.etree import ElementTree | ||
|
||
first = None | ||
parentDirectory = "../" | ||
ktlintMain = "/build/reports/ktlint/ktlintMainSourceSetCheck/ktlintMainSourceSetCheck.xml" | ||
ktlintTest = "/build/reports/ktlint/ktlintTestSourceSetCheck/ktlintTestSourceSetCheck.xml" | ||
ktlintAndroidTest = "/build/reports/ktlint/ktlintAndroidTestSourceSetCheck/ktlintAndroidTestSourceSetCheck.xml" | ||
detekt = "/build/reports/detekt/detekt.xml" | ||
lint = "/build/reports/lint-results.xml" | ||
|
||
file_list = [] | ||
|
||
module_list = [ | ||
"app", | ||
"database", | ||
"analytics" | ||
] | ||
|
||
for module in module_list: | ||
file_list.append(parentDirectory + module + ktlintMain) | ||
file_list.append(parentDirectory + module + ktlintTest) | ||
file_list.append(parentDirectory + module + ktlintAndroidTest) | ||
file_list.append(parentDirectory + module + detekt) | ||
|
||
print(file_list) | ||
|
||
ktlintFile = 'ktlint-report-orig.xml' | ||
editedKtlintFile = 'ktlint-report.xml' | ||
|
||
for filename in file_list: | ||
if os.path.isfile(filename): | ||
data = ElementTree.parse(filename).getroot() | ||
if first is None: | ||
first = data | ||
else: | ||
first.extend(data) | ||
if first is not None: | ||
f = open( ktlintFile, 'w+' ) | ||
f.write( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" ) | ||
f.write( ElementTree.tostring(first) ) | ||
f.close() | ||
|
||
delete_list = [] | ||
fin = open(ktlintFile) | ||
fout = open(editedKtlintFile, "w+") | ||
for line in fin: | ||
for word in delete_list: | ||
line = line.replace(word, "") | ||
fout.write(line) | ||
print(line) | ||
fin.close() | ||
fout.close() |