Skip to content

Instantly share code, notes, and snippets.

@skad0
Created March 23, 2018 12:51
Show Gist options
  • Save skad0/573332738718b3307c7282cc5461b22c to your computer and use it in GitHub Desktop.
Save skad0/573332738718b3307c7282cc5461b22c to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Check changed js files using jshint and jscs
#
PATCH_FILE="working-tree.patch"
NPM_BIN="./node_modules/.bin"
function cleanup {
exit_code=$?
if [ -f "$PATCH_FILE" ]; then
patch -p0 < "$PATCH_FILE"
rm "$PATCH_FILE"
fi
exit $exit_code
}
trap cleanup EXIT SIGINT SIGHUP
# Cancel any changes to the working tree that are not going to be committed
git diff --no-prefix > "$PATCH_FILE"
git checkout -- .
git_cached_files=$(git diff --cached --name-only --diff-filter=ACMR | grep -e \.js$ -e \.bemhtml$ -e \.bemtree$ | xargs echo)
if [ "$git_cached_files" ]; then
$NPM_BIN/jshint-groups $git_cached_files || exit 1
$NPM_BIN/jscs $git_cached_files || exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment