-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·74 lines (54 loc) · 1.42 KB
/
pre-commit
File metadata and controls
executable file
·74 lines (54 loc) · 1.42 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# [WHITESPACE] --> Check for whitespace
#
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Magic Initial commit
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
if ! git diff-index --check --cached $against
then
echo "[WHITESPACE] --> 🚫 Can't commit! Check your whitespaces!!!"
exit 1
else
echo "[WHITESPACE] --> 👍 LGTM"
fi
# [ESLINT] --> JavaScript Linter
#
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
which eslint &> /dev/null
if [[ "$?" == 1 ]]; then
echo "⚠️ Please install ESlint and friends globally first via: \"npm install -g eslint babel-eslint eslint-config-airbnb eslint-plugin-react eslint-plugin-import eslint-plugin-babel eslint-plugin-jsx-a11y\""
exit 1
fi
for FILE in $STAGED_FILES
do
eslint "$FILE"
if [[ "$?" == 1 ]]; then
PASS=false
fi
done
if ! $PASS; then
echo "[ESLINT] --> 🚫 Can't commit! Failed ESLint!!!"
exit 1
else
echo "[ESLINT] --> 👍 LGTM"
fi
# [RUBOCOP] --> Ruby style
#
FAILS=`bundle exec rubocop app lib test | grep 'no offenses detected' -o | awk '{print $1}'`
COUNTS=`bundle exec rubocop app lib test | grep -e '\d* offenses detected' -o | awk '{print $1}'`
if [ "$FAILS" == "no" ]; then
echo "[RUBOCOP] --> 👍 LGTM"
exit 0
else
echo "[RUBOCOP] --> 🚫 You've $COUNTS offenses!!!"
exit 1
fi
exit $?