Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active October 9, 2015 03:27
Show Gist options
  • Select an option

  • Save geta6/6a3bf657d675a775e1c5 to your computer and use it in GitHub Desktop.

Select an option

Save geta6/6a3bf657d675a775e1c5 to your computer and use it in GitHub Desktop.
#/!bin/bash
__chmod=`which chmod`
pushd `dirname $0` >/dev/null 2>&1
[ $? -eq 1 ] && exit 1
__script_dir=`pwd`
popd >/dev/null 2>&1
__base_dir=`dirname ${__script_dir}`
GIT_HOOKS_DIR=".git/hooks"
__hooks_dir=${__base_dir}/${GIT_HOOKS_DIR}
if [ ! -d $__hooks_dir ]; then
echo "[INFO] make hooks directory"
mkdir $__hooks_dir
fi
__pre_commit_path=${__base_dir}/${GIT_HOOKS_DIR}/pre-commit
echo "[install pre-commit] ${__pre_commit_path}"
cp -f ${__base_dir}/bin/pre-commit ${__pre_commit_path}
${__chmod} +x ${__pre_commit_path}
#!/bin/sh
echo "\nコードがいい感じかどうかチェックするぞー^O^ノ\n"
files=$(git diff --cached --name-only --diff-filter=ACM)
javascripts=$(echo "$files" | grep -e ".jsx\?$")
stylesheets=$(echo "$files" | grep -e ".styl$")
if [ "$javascripts" = "" -a "$stylesheets" = "" ]; then
echo "\n\033[32mNO FILE MATCHED\033[0m\n"
exit 0
fi
warn=false
pass=true
for javascript in ${javascripts}; do
result=$(./node_modules/.bin/eslint ${javascript} -f compact)
if [ "$(echo $result | grep Error)" = "" ]; then
if [ "$(echo $result | grep Warning)" = "" ]; then
echo "\t\033[32m✓ [eslint] ${javascript}\033[0m"
else
warn=true
echo "\t\033[33m✓︎ [eslint] ${javascript}\033[0m"
fi
else
echo "\t\033[31m✗ [eslint] ${javascript}\033[0m"
pass=false
fi
done
for stylesheet in ${stylesheets}; do
result=$(./node_modules/.bin/stylint ${stylesheet})
if [ "$(echo $result | grep Error)" = "" ]; then
if [ "$(echo $result | grep Warning)" = "" ]; then
echo "\t\033[32m✓ [stylint] ${stylesheet}\033[0m"
else
warn=true
echo "\t\033[33m✓︎ [stylint] ${stylesheet}\033[0m"
fi
else
echo "\t\033[31m✗ [stylint] ${stylesheet}\033[0m"
pass=false
fi
done
if ! $pass; then
echo "\n\033[31mLintコケたのでコミットできませんでした\033[0m\n"
exit 1
elif $warn; then
echo "\n\033[33mコミットしたけどLintでwarningでてます、特に理由が無ければ直してください\033[0m\n"
else
echo "\n\033[32mコミットした!\033[0m\n"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment