Created
November 21, 2012 06:13
-
-
Save fitorec/4123345 to your computer and use it in GitHub Desktop.
git pre-commit: codeSninfer + wordpress standart
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
#!/bin/bash | |
# | |
# Revisa el código cumpla simples reglas | |
# Mayor información: | |
# http://www.mundosica.com/blog/2012/automatizando-la-validando-sintaxis-y-estandar-de-codigo-wordpress-mediante-el-sistema-de-enganchaje-de-git/ | |
# Lista de colores a utilizar | |
Color_Off='\e[0m' # Resetea el color | |
BRed='\e[1;31m' # Rojo | |
BPurple='\e[1;35m' # Morado | |
error=0; | |
# Revisa que el archivo no contenga espacios en blanco al final de las lineas | |
function revisar_espacios () { | |
grep -qE '\s+$' $1 | |
if [ "$?" -eq "0" ] | |
then | |
let error=error+1 | |
echo -ne "${BRed}Error ${error}:${Color_Off}"; | |
echo -ne " ${BPurple}Espacios al final${Color_Off} -> "; | |
grep -HnEo --color '\s+$' $1 | |
fi; | |
} | |
# Revisa que los archivos en PHP tengan sintaxis correcta. | |
function revisar_sintaxisPHP() { | |
phpcs --standard=WordPress -s $1 | |
} | |
# Concluye el script y muestra el numero de errores(si existen) | |
function salir_y_mostrar_errores() { | |
if [ "$error" -ne "0" ] | |
then | |
echo -e "${BRed}Existen $error errores"; | |
fi; | |
exit $error; | |
} | |
################################################################################# | |
# Apartir de la extensión vamos a validar los archivos por confirmar # | |
################################################################################# | |
for archivo in $(git diff --cached --name-only) | |
do | |
extension=$(basename $archivo | grep -Eo '\.[a-z0-9]+$' | sed 's/\.//g') | |
case $extension in | |
php) | |
revisar_espacios $archivo; | |
revisar_sintaxisPHP $archivo; | |
;; | |
js|json|sql|css|md|txt|html) | |
revisar_espacios $archivo; | |
;; | |
esac | |
done; | |
salir_y_mostrar_errores; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment