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" % +