forked from Gnosis-Auction/auction-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·43 lines (36 loc) · 1.2 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
STAGED_JS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
STAGED_SOL_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".sol$")
PASS=true
# Usage: validate <files> <command> <name>
validate() {
for FILE in $1
do
$2 "$FILE"
if [[ "$?" == 0 ]]; then
printf "\t\033[32m$3 Passed: $FILE\033[0m\n"
else
printf "\t\033[41m$3 Failed: $FILE\033[0m\n"
PASS=false
fi
done
}
if [[ ("$STAGED_JS_FILES" = "") && ("$STAGED_SOL_FILES" = "") ]]; then
exit 0
fi
printf "\nValidating Javascript:\n"
validate "$STAGED_JS_FILES" "npx eslint" "ESLint"
validate "$STAGED_JS_FILES" "npx prettier --check" "Prettier"
printf "\nJavascript validation completed!\n"
printf "\nValidating Solidity:\n"
validate "$STAGED_SOL_FILES" "npx solhint" "Solhint"
validate "$STAGED_SOL_FILES" "npx solium --file" "Solium"
validate "$STAGED_SOL_FILES" "npx prettier --check" "Prettier"
printf "\nSolidity validation completed!\n"
if ! $PASS; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass Linting but do not. Please fix the errors and try again.\n"
exit 1
else
printf "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
exit $?