-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit-reject-forbidden-code
More file actions
53 lines (45 loc) · 1.09 KB
/
pre-commit-reject-forbidden-code
File metadata and controls
53 lines (45 loc) · 1.09 KB
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
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#
# Configs
#
forbidden_code=( "console.log" "console.info" "console.error" "console.warn" "debugger" "var_dump" "print_r" "fdescribe" "fit" "ddescribe" "iit")
#
# Color Definitions
#
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
reset=`tput sgr0`
#
# error variable
#
error_found=false
echo -e "${cyan}""[ >>> BEGIN PRE-COMMIT FORBIDDEN CODE CHECK ]""${reset}"
for file in $(git diff --cached --name-only); do
#
# Test for debug calls
#
for (( i=0; i<${#forbidden_code[@]}; i++ )); do
if [ -e $file ] ; then
grep "${forbidden_code[$i]}" $file | grep -vq "//"
if [ $? -ne 1 ] ; then
echo "${red}FAILURE${reset}: You left a ${yellow}${forbidden_code[$i]}${reset} in ${cyan}$file${reset}"
error_found=true
fi
fi
done
#
#
#
done
if $error_found ; then
echo -e "${red}[ >>> COMMIT REJECTED ]"
echo -e "${red}""If you absolutely need to commit this use git commit --no-verify (-n)"${reset}""
exit 1
else
echo -e "${green}""[ >>> PRE-COMMIT FORBIDDEN CODE CHECK COMPLETE ]""${reset}"
exit 0
fi