summaryrefslogtreecommitdiffhomepage
path: root/android/scripts/tidy.sh
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-04-24 16:19:33 +0200
committerAlbin <albin@mullvad.net>2023-04-24 16:19:33 +0200
commit1fbbf6517c9948c53689d2b1847c8adc2aa404ea (patch)
tree0915f9b5de9c38b6641262f8546d7e2c586b9d1e /android/scripts/tidy.sh
parentc826091de45ae9af387472d24ecebb7ad5600fad (diff)
parentbc3bb75d1f0d7646b50e06a3e3bd8117c076e4f0 (diff)
downloadmullvadvpn-1fbbf6517c9948c53689d2b1847c8adc2aa404ea.tar.xz
mullvadvpn-1fbbf6517c9948c53689d2b1847c8adc2aa404ea.zip
Merge branch 'restructure-tidy-script-droid-119'
Diffstat (limited to 'android/scripts/tidy.sh')
-rwxr-xr-xandroid/scripts/tidy.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/android/scripts/tidy.sh b/android/scripts/tidy.sh
new file mode 100755
index 0000000000..8e0546046b
--- /dev/null
+++ b/android/scripts/tidy.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+# CI/Developer script to format
+# Relies on Tidy - https://github.com/htacg/tidy-html5
+
+set -eu
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$SCRIPT_DIR"
+
+function main {
+ case ${1:-""} in
+ format) format;;
+ formatAndCheckDiff) format && checkDiff;;
+ "")
+ echo "Available subcommands: format, formatAndCheckDiff"
+ ;;
+ *)
+ echo "Unknown parameter: $1"
+ exit 1
+ ;;
+ esac
+}
+
+# Autoformats Android XML files
+function format {
+ tidy -xml \
+ -m \
+ -i \
+ -w 100 \
+ -utf8 \
+ --quiet yes \
+ --indent-attributes yes \
+ --indent-spaces 4 \
+ --literal-attributes yes \
+ ../app/src/main/AndroidManifest.xml \
+ ../app/src/main/res/anim*/*.xml \
+ ../app/src/main/res/drawable*/*.xml \
+ ../app/src/main/res/layout*/*.xml \
+ ../app/src/main/res/values/*.xml
+
+ # FIXME - when tidy learns to not leave whitespace around, remove the line below - https://github.com/htacg/tidy-html5/issues/864
+ find ../app/src/main/ -name '*.xml' -exec sed -i -e 's/[ \t]*$//' '{}' ';'
+}
+
+function checkDiff {
+ if git diff --exit-code -- ../app/src/main/AndroidManifest.xml ../app/src/main/res; then
+ echo "Android XML files are correctly formatted"
+ return 0
+ else
+ echo "Android XML files are NOT correctly formatted"
+ return 1
+ fi
+}
+
+main "$@"