mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
aa062db4e0
A user would struggle to determine what the error was if `ktLintFormat` failed `-q` (error only) is overkill as it removes useful output, but there is a large amount of warnings in the current version of the ktLint plugin GitHub ref: JLLeitschuh/ktlint-gradle/issues/457 This can be converted to `-w` (warnings only) afterwards A typical error is: ``` KtLint found code style violations. Please see the following reports: - C:\\...\ktlintTestSourceSetFormat\ktlintTestSourceSetFormat.txt ``` After adding `-w`, we'd also get the more useful: ``` CriticalExceptionTest.kt:19:1 Wildcard import (cannot be auto-corrected) ``` https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_logging Fixes #9093
26 lines
788 B
Bash
Executable File
26 lines
788 B
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
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. Hence, skipping pre-commit Ktlint run."
|
|
exit 0
|
|
fi;
|
|
|
|
echo "Running Ktlint over these files:"
|
|
echo "$CHANGED_FILES"
|
|
|
|
# -q removes noise from the output if it fails.
|
|
# TODO: -w is better, but https://github.com/JLLeitschuh/ktlint-gradle/issues/457 adds noise
|
|
# -w should display: "CriticalExceptionTest.kt:19:1 Wildcard import (cannot be auto-corrected)"
|
|
./gradlew -q ktlintFormat
|
|
|
|
echo "Completed ./gradlew ktlintFormat run."
|
|
echo "$CHANGED_FILES" | while read -r file; do
|
|
if [ -f "$file" ]; then
|
|
git add "$file"
|
|
fi
|
|
done
|
|
echo "Completed the pre-commit hook."
|