Adding precommit hook
This commit is contained in:
parent
00d6268af9
commit
0921e6a35e
|
@ -15226,6 +15226,39 @@
|
|||
"uniqs": "2.0.0"
|
||||
}
|
||||
},
|
||||
"pre-commit": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/pre-commit/-/pre-commit-1.2.2.tgz",
|
||||
"integrity": "sha1-287g7p3nI15X95xW186UZBpp7sY=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cross-spawn": "5.1.0",
|
||||
"spawn-sync": "1.0.15",
|
||||
"which": "1.2.14"
|
||||
},
|
||||
"dependencies": {
|
||||
"cross-spawn": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
|
||||
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lru-cache": "4.1.1",
|
||||
"shebang-command": "1.2.0",
|
||||
"which": "1.2.14"
|
||||
}
|
||||
},
|
||||
"which": {
|
||||
"version": "1.2.14",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz",
|
||||
"integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"isexe": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"prelude-ls": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
"scripts": {
|
||||
"start": "node scripts/start.js",
|
||||
"build": "node scripts/build.js",
|
||||
"test": "node scripts/test.js --env=jsdom"
|
||||
"test": "node scripts/test.js --env=jsdom",
|
||||
"precommit": "./precommit.sh"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -20,6 +21,9 @@
|
|||
"url": "https://github.com/gnosis/gnosis-team-safe/issues"
|
||||
},
|
||||
"homepage": "https://github.com/gnosis/gnosis-team-safe#readme",
|
||||
"pre-commit": [
|
||||
"precommit"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0-beta.40",
|
||||
"@babel/core": "^7.0.0-beta.40",
|
||||
|
@ -51,6 +55,7 @@
|
|||
"json-loader": "^0.5.7",
|
||||
"postcss-loader": "^2.1.1",
|
||||
"postcss-simple-vars": "^4.1.0",
|
||||
"pre-commit": "^1.2.2",
|
||||
"react": "^16.2.0",
|
||||
"react-dev-utils": "^5.0.0",
|
||||
"react-dom": "^16.2.0",
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
|
||||
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
|
||||
ADD_FILES_TO_COMMIT="git add ."
|
||||
|
||||
if [[ "$STAGED_FILES" = "" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PASS=true
|
||||
|
||||
echo -e "\nValidating Javascript:\n"
|
||||
|
||||
# Check for eslint
|
||||
if [[ ! -x "$ESLINT" ]]; then
|
||||
echo -e "\t\033[41mPlease install ESlint\033[0m (npm i --save-dev eslint)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for FILE in $STAGED_FILES
|
||||
do
|
||||
"$ESLINT" "$FILE" "--fix"
|
||||
|
||||
if [[ "$?" == 0 ]]; then
|
||||
echo -e "\t\033[32mESLint Passed: $FILE\033[0m"
|
||||
else
|
||||
echo -e "\t\033[41mESLint Failed: $FILE\033[0m"
|
||||
PASS=false
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "\nJavascript validation completed!\n"
|
||||
|
||||
if ! $PASS; then
|
||||
echo -e "\033[0;31mCOMMIT FAILED, PLEASE FIX ESLINT ERRORS:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors in a new commit.\n"
|
||||
exit 1
|
||||
else
|
||||
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
|
||||
fi
|
||||
|
||||
eval $ADD_FILES_TO_COMMIT
|
||||
|
||||
exit $?
|
Loading…
Reference in New Issue