Created
April 13, 2015 06:29
-
-
Save evalphobia/cf79c1911df7a5ae3f00 to your computer and use it in GitHub Desktop.
golint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #=================== | |
| # Config | |
| #=================== | |
| REPO_ROOT=`git rev-parse --show-toplevel` | |
| GOLINT_TMP="/tmp/.golint.txt" | |
| TSLINT_TMP="/tmp/.tslint.txt" | |
| TSLINT_CONF="$REPO_ROOT/resources/lint/tslint.json" | |
| if git rev-parse --verify HEAD >/dev/null 2>&1 | |
| then | |
| against=HEAD | |
| else | |
| against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
| fi | |
| exec 1>&2 | |
| #=================== | |
| # Functions | |
| #=================== | |
| # Go file | |
| function isGoFile() { | |
| echo "$1" | egrep '\.go$' > /dev/null | |
| } | |
| # TypeScript file | |
| function isTypeScriptFile() { | |
| echo "$1" | egrep '\.ts$' > /dev/null | |
| } | |
| #=================== | |
| # Main | |
| #=================== | |
| IS_ERROR=0 | |
| FILES=`git diff-index --name-status $against --` | |
| NEW_FILES=`echo -n "$FILES"| egrep '^A' | cut -c3-` | |
| MODIFIED_FILES=`echo -n "$FILES"| egrep '^M' | cut -c3-` | |
| # Modified files | |
| for FILE in `echo -n "$MODIFIED_FILES" `; do | |
| isGoFile $FILE | |
| if [ "$?" -eq 0 ]; then | |
| echo "[$FILE]" | |
| golint $FILE | |
| echo "" | |
| continue | |
| fi | |
| isTypeScriptFile $FILE | |
| if [ "$?" -eq 0 ]; then | |
| echo "[$FILE]" | |
| tslint -c $TSLINT_CONF -f $FILE | |
| echo "" | |
| continue | |
| fi | |
| done | |
| # New files | |
| for FILE in `echo -n "$NEW_FILES" `; do | |
| isGoFile $FILE | |
| if [ "$?" -eq 0 ]; then | |
| echo "[$FILE]" | |
| golint $FILE | tee $GOLINT_TMP | |
| echo "" | |
| continue | |
| fi | |
| isTypeScriptFile $FILE | |
| if [ "$?" -eq 0 ]; then | |
| echo "[$FILE]" | |
| tslint -c $TSLINT_CONF -f $FILE | tee $TSLINT_TMP | |
| echo "" | |
| continue | |
| fi | |
| done | |
| if [ -s "$GOLINT_TMP" ]; then | |
| echo "" | |
| echo "[Go LINT Problem] Fix above lint problems" | |
| rm $GOLINT_TMP | |
| IS_ERROR=1 | |
| fi | |
| if [ -s "$TSLINT_TMP" ]; then | |
| echo "" | |
| echo "[TypeScript LINT Problem] Fix above lint problems" | |
| rm $TSLINT_TMP | |
| IS_ERROR=1 | |
| fi | |
| exit $IS_ERROR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment