Created
August 7, 2015 06:56
-
-
Save viskri/a6c60ba74d5e44de3d8c to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
# Check for JSHint errors | |
function linth { | |
if [[ "$1" == *js ]] | |
then | |
if [ -n "$(type -t jshint)" ]; then | |
printf "\nJSHint results for $1:\n\n" | |
jshint $1 | |
else | |
printf "\n\nJsHint is not found.\nInstall JsHint\nSkipping JSHint check\n" | |
fi | |
fi | |
} | |
# Fix simple JS errors (caught by Closure Linter) using fixjsstyle | |
function fixg { | |
if [ -n "$(type -t fixjsstyle)" ]; then | |
printf "\n\n Running autofix for cosmetic errors using fixjsstyle command on $1\n\n" | |
fixjsstyle --disable 0005,0131 $1 | |
else | |
printf "\n\n fixjsstyle command not found. Skipping auto-fix" | |
fi | |
} | |
# Check for Closure Linter errors | |
function lintg { | |
if [[ "$1" == *js ]] | |
then | |
if [ -n "$(type -t gjslint)" ]; then | |
printf "\n\nClosure Linter Check:\n\n" | |
gjslint --disable 0005,0131 $1 | |
else | |
printf "\n\ngjslint is not found.\nInstall gjslint\nSkipping gjslint check\n" | |
fi | |
fi | |
} | |
# Fix simple errors (caught by JSHint) using fixmyjs | |
function fixh { | |
if [[ "$1" == *js ]] | |
then | |
if [ -n "$(type -t fixmyjs)" ]; then | |
printf "\n\n Running autofix for cosmetic errors using fixmyjs command on $1\n\n" | |
fixmyjs --legacy $1 | |
else | |
printf "\n\n fixmyjs command not found. Skipping auto-fix" | |
fi | |
fi | |
} | |
# Invoke various operations on uncommitted files | |
function ch { | |
printf "\nRunning git status...\n" | |
FILES_CHANGED=`git status -s | cut -c4-` | |
if [[ -z $FILES_CHANGED ]] | |
then | |
printf "No uncommitted files\n" | |
else | |
printf "\nFiles Changed:\n" | |
printf "$FILES_CHANGED \n\n" | |
for FILENAME in $FILES_CHANGED | |
do | |
case $1 in | |
"edit") sublime $FILENAME ;; | |
"sublime") sublime $FILENAME ;; | |
"linth") linth $FILENAME ;; | |
"lintg") lintg $FILENAME ;; | |
"fixh") fixh $FILENAME ;; | |
"fixg") fixg $FILENAME ;; | |
"fixjs") fixh $FILENAME | |
fixg $FILENAME ;; | |
"lintjs") lintg $FILENAME | |
linth $FILENAME ;; | |
"fixo") fixh $FILENAME #Fix simple JS errors and then open in editor | |
fixg $FILENAME | |
sublime $FILENAME;; | |
*) $1 $FILENAME ;; #Runs a command on each file in the change list | |
esac | |
done | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment