运行方法:
./pre-commit.sh # 安装 pre-commit
git commit ... # 自动检查代码是否符合 standard js 标准
CHECK=0 git commit ... # 不检查代码
if [ "`which standard`" = "" ] | |
then | |
npm install standard -g | |
fi | |
if [ "`which snazzy`" = "" ] | |
then | |
npm install snazzy -g | |
fi | |
echo '#!/bin/sh | |
# Ensure all javascript files staged for commit pass standard code style | |
if [ "$CHECK" = "0" ] | |
then | |
echo "ignore pre commit check" | |
exit | |
fi | |
git diff --name-only --cached --relative | grep "\.jsx\?$" | xargs standard --verbose | snazzy | |
if [ $? -ne 0 ]; then exit 1; fi | |
' > .git/hooks/pre-commit | |
chmod +x .git/hooks/pre-commit |