./pre-commit.sh # 安装 pre-commit
git commit ... # 自动检查代码是否符合 standard js 标准
CHECK=0 git commit ... # 不检查代码-
-
Save GNSubrahmanyam/bc721a2d73665714aea51d3c1f890e10 to your computer and use it in GitHub Desktop.
add Git hook for standard style check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment