Add style check utilities.

This commit is contained in:
MetaPrime 2017-06-19 10:45:11 -07:00
parent 93a7400a7c
commit 153b206260
2 changed files with 44 additions and 0 deletions

27
utils/style.sh Normal file
View File

@ -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 "====================================================="

17
utils/stylefix.sh Normal file
View File

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