From 1dd251f4e9085c35d2759b6a2ce1c5777fcf4e4c Mon Sep 17 00:00:00 2001 From: Nick Nisi Date: Mon, 17 Aug 2015 09:41:55 -0500 Subject: [PATCH] add jscs pre-commit check --- git/hooks/jscs.pre-commit | 37 +++++++++++++++++++++++++++++++++++++ git/hooks/jshint.pre-commit | 1 - 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 git/hooks/jscs.pre-commit diff --git a/git/hooks/jscs.pre-commit b/git/hooks/jscs.pre-commit new file mode 100755 index 0000000..ffb46ce --- /dev/null +++ b/git/hooks/jscs.pre-commit @@ -0,0 +1,37 @@ +#!/bin/sh +# JSCS Pre-Commit +# If a JavaScript file is trying to be committed and it fails style checking +# then fail the commit + +EXIT_CODE=0 +COLOR_RED="\x1B[31m" +COLOR_YELLOW="\x1B[1;33m" +COLOR_GREEN="\x1B[32m" +COLOR_NONE="\x1B[0m" + +if ! jscs > /dev/null 2>&1; then + echo "${COLOR_YELLOW}JSCS is not installed. Exiting.${COLOR_NONE}" + exit 0 +fi + +repo=$( git rev-parse --show-toplevel ) + +for file in $( exec git diff-index --cached --name-only HEAD ); do + if [ ${file: -3} == ".js" ]; then + status=$( exec git status --porcelain $file ) + + if [[ $status != D* ]]; then + jscs ${repo}/${file} + EXIT_CODE=$((${EXIT_CODE} + $?)) + fi + fi +done + +echo "" +if [[ ${EXIT_CODE} -ne 0 ]]; then + echo "${COLOR_RED}✘ JSCS detected syntax problems.${COLOR_NONE}" +else + echo "${COLOR_GREEN}✔ JSCS detected no errors.${COLOR_NONE}" +fi + +exit $((${EXIT_CODE})) diff --git a/git/hooks/jshint.pre-commit b/git/hooks/jshint.pre-commit index 9b51971..8e4590d 100755 --- a/git/hooks/jshint.pre-commit +++ b/git/hooks/jshint.pre-commit @@ -21,7 +21,6 @@ for file in $( exec git diff-index --cached --name-only HEAD ); do status=$( exec git status --porcelain $file ) if [[ $status != D* ]]; then - # ${jshint} ${repo}/${file} >/dev/null 2>&1 jshint ${repo}/${file} EXIT_CODE=$((${EXIT_CODE} + $?)) fi