Skip to content

Commit 3714dd2

Browse files
committed
Added --enable arg for new shellcheck optional checks
1 parent 246348a commit 3714dd2

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

hooks/shellcheck.sh

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,47 @@ set -e
88
export PATH=$PATH:/usr/local/bin
99

1010
exit_status=0
11+
ENABLE_LIST=""
1112

12-
for file in "$@"; do
13-
if (head -1 "$file" |grep '^#!.*sh'>/dev/null); then
13+
# Arguments
14+
parse_arguments() {
15+
while [ $# -gt 0 ]; do
16+
# Get param and value using parameter expansion, splitting on = or " "
17+
param="${1%[ =]*}"
18+
value="${1#*[ =]}"
19+
if [ "$param" = "$value" ]; then value="$2"; fi
20+
shift
21+
case "$param" in
22+
--enable)
23+
ENABLE_LIST="$ENABLE_LIST $value"
24+
;;
25+
-*)
26+
echo "Error: Unknown option: $param" >&2
27+
exit 1
28+
;;
29+
*)
30+
PARAMS="$PARAMS $param"
31+
;;
32+
esac
33+
done
34+
ENABLE_LIST="${ENABLE_LIST## }" # remove preceeding space
35+
}
1436

15-
if ! shellcheck "$file"; then
16-
exit_status=1
37+
parse_arguments "$@"
38+
39+
for file in $PARAMS; do
40+
if (head -1 "$file" | grep '^#!.*sh'>/dev/null); then
41+
SHELLCHECK_ARGS=""
42+
if [ "$ENABLE_LIST" != "" ]; then
43+
SHELLCHECK_ARGS+="--enable=\"$ENABLE_LIST\" "
1744
fi
18-
elif [[ "$file" =~ \.sh$|bash$ ]]; then
19-
echo "$file: missing shebang"
45+
if ! eval "shellcheck $SHELLCHECK_ARGS\"$file\""; then
2046
exit_status=1
21-
fi
47+
fi
48+
elif [[ "$file" =~ \.sh$|bash$ ]]; then
49+
echo "$file: missing shebang"
50+
exit_status=1
51+
fi
2252
done
2353

2454
exit $exit_status

0 commit comments

Comments
 (0)