Commit a08fe20b authored by 胡小根's avatar 胡小根

add pre-commit

parent ca09517f
#!/usr/bin/env bash
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
echo "\n验证 Javascript:\n"
# Check for eslint
which eslint &> /dev/null
if [[ "$?" == 1 ]]; then
echo "\t\033[41m请安装ESlint\033[0m"
exit 1
fi
for FILE in $STAGED_FILES
do
eslint "$FILE"
if [[ "$?" == 0 ]]; then
echo "\t\033[32mESLint 通过: $FILE\033[0m"
else
echo "\t\033[41mESLint 失败: $FILE\033[0m"
PASS=false
fi
done
echo "\nJavascript 验证完成!\n"
if ! $PASS; then
echo "\033[41m提交失败:\033[0m 你的代码没有通过ESLint规范,请修改ESLint错误并重试。\n"
exit 1
else
echo "\033[42m提交成功\033[0m\n"
fi
exit $?
\ No newline at end of file
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
"build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js", "build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
"build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js", "build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
"lint": "eslint --ext .js,.vue src", "lint": "eslint --ext .js,.vue src",
"test": "npm run lint", "test": "npm run lint"
"postinstall": "cp .hooks/* .git/hooks/"
}, },
"dependencies": { "dependencies": {
"axios": "0.17.1", "axios": "0.17.1",
...@@ -46,6 +45,9 @@ ...@@ -46,6 +45,9 @@
"vuex": "3.0.1", "vuex": "3.0.1",
"xlsx": "^0.11.16" "xlsx": "^0.11.16"
}, },
"pre-commit": {
"run": ["lint"]
},
"devDependencies": { "devDependencies": {
"autoprefixer": "7.2.3", "autoprefixer": "7.2.3",
"babel-core": "6.26.0", "babel-core": "6.26.0",
...@@ -78,6 +80,7 @@ ...@@ -78,6 +80,7 @@
"postcss-import": "11.0.0", "postcss-import": "11.0.0",
"postcss-loader": "2.0.9", "postcss-loader": "2.0.9",
"postcss-url": "7.3.0", "postcss-url": "7.3.0",
"pre-commit": "^1.2.2",
"pushstate-server": "3.0.1", "pushstate-server": "3.0.1",
"rimraf": "2.6.2", "rimraf": "2.6.2",
"sass-loader": "6.0.6", "sass-loader": "6.0.6",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment