Skip to content

Commit

Permalink
Add style check utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaprime committed Jun 19, 2017
1 parent 93a7400 commit 153b206
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions utils/style.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions utils/stylefix.sh
Original file line number Diff line number Diff line change
@@ -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" %

0 comments on commit 153b206

Please sign in to comment.