From 153b2062606925b996751d78f43b929f195de2df Mon Sep 17 00:00:00 2001
From: MetaPrime <metaprime@users.noreply.github.com>
Date: Mon, 19 Jun 2017 10:45:11 -0700
Subject: [PATCH] Add style check utilities.

---
 utils/style.sh    | 27 +++++++++++++++++++++++++++
 utils/stylefix.sh | 17 +++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 utils/style.sh
 create mode 100644 utils/stylefix.sh

diff --git a/utils/style.sh b/utils/style.sh
new file mode 100644
index 00000000..45bb40e9
--- /dev/null
+++ b/utils/style.sh
@@ -0,0 +1,27 @@
+echo ""
+echo "====================================================="
+echo "Tabs are not allowed"
+echo "-----------------------------------------------------"
+git grep -n -P "\t" -- :/*.java | sed -e "s/\t/\x1b[7m--->\x1b[m/g"
+echo "====================================================="
+
+echo ""
+echo "====================================================="
+echo "Trailing whitespace is not allowed"
+echo "-----------------------------------------------------"
+git grep -n -P "[ \t]+$" -- :/*.java | sed -e "s/\t/\x1b[7m--->\x1b[m/g" | sed -e "s/ /\x1b[7m.\x1b[m/g" | sed -e "s/$/\x1b[7m$\x1b[m/g"
+echo "====================================================="
+
+echo ""
+echo "====================================================="
+echo "'){' is not allowed. Place a space between ')' and '{', i.e. 'if (a) {'"
+echo "-----------------------------------------------------"
+git grep -n -P "\)\{" -- :/*.java
+echo "====================================================="
+
+echo ""
+echo "====================================================="
+echo "A space is required after keywords (if|else|for|while|do|try|catch|finally)"
+echo "-----------------------------------------------------"
+git grep -n -P "(\b(if|for|while|catch)\b[(])|(\b(else|do|try|finally)\b[{])" -- :/*.java | sed -r -e "s/(\b(if|for|while|catch)\b[(])|(\b(else|do|try|finally)\b[{])/\x1b[7m\0\x1b[m/g"
+echo "====================================================="
diff --git a/utils/stylefix.sh b/utils/stylefix.sh
new file mode 100644
index 00000000..dbfad1e1
--- /dev/null
+++ b/utils/stylefix.sh
@@ -0,0 +1,17 @@
+echo ""
+echo "====================================================="
+echo "Tabs are not allowed (please manually fix tabs)"
+echo "-----------------------------------------------------"
+git grep -n -P "\t" -- :/*.java | sed -e "s/\t/\x1b[7m--->\x1b[m/g"
+echo "====================================================="
+
+echo "Removing trailing whitespace..."
+git grep -l -P "[ \t]+$" -- :/*.java | xargs -I % sed -i -r -e "s/[ \t]+$//g" %
+
+echo "Replacing '){' with ') {'..."
+git grep -l -P "\)\{" -- :/*.java | xargs -I % sed -i -r -e "s/\)\{/) {/g" %
+
+echo "Adding space between keywords and punctuation..."
+git grep -l -P "(\b(if|for|while|catch)\b[(])" -- :/*.java | xargs -I % sed -i -r -e "s/(\b(if|for|while|catch)\b[(])/\2 (/g" %
+git grep -l -P "(\b(else|do|try|finally)\b[{])" -- :/*.java | xargs -I % sed -i -r -e "s/(\b(else|do|try|finally)\b[{])/\2 {/g" %
+