From 8c55cdd3d579c674b044c918b53e8382547d84ab Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Tue, 6 Jun 2017 02:48:46 -0400 Subject: [PATCH] js linting script for precommit hook --- _tests/git hooks/precommit | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 _tests/git hooks/precommit diff --git a/_tests/git hooks/precommit b/_tests/git hooks/precommit new file mode 100755 index 0000000..92009a9 --- /dev/null +++ b/_tests/git hooks/precommit @@ -0,0 +1,17 @@ +#!/bin/bash +jsfiles=$(git diff --cached --name-only --diff-filter=M | grep '\.js\?$') +jsfailed=0 + +if [[ $jsfiles != "" ]] ; then + for file in ${jsfiles}; do + git show :$file | eslint --stdin --stdin-filename "$file" + if [[ $? != 0 ]] ; then + jsfailed=1 + fi + done; +fi + +if [[ $jsfailed != 0 ]] ; then + echo "🚫🚫🚫ESLint must pass before committing .js files" + exit 1 +fi