-
Notifications
You must be signed in to change notification settings - Fork 3
/
format_and_lint.bash
executable file
·51 lines (46 loc) · 1.31 KB
/
format_and_lint.bash
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
#!/usr/bin/env bash
# shfmt - beautify scripts
if command -v shfmt 1>| /dev/null; then
printf "Beautifying scripts with shfmt... \n"
for i in *.bash; do
if ! shfmt -w "${i}"; then
printf "%s\n\n" "${i}: ERROR"
format_status=1
else
printf "%s\n" "${i}: SUCCESS"
fi
done
format_status="${format_status:-0}"
printf "\n"
else
printf 'Install shfmt to format script\n\n'
printf 'Check https://github.com/mvdan/sh/releases\n\n'
fi
# shell check - lint script
if command -v shellcheck 1>| /dev/null; then
printf "Linting scripts with shellcheck... \n"
for i in *.bash; do
if ! shellcheck "${i}"; then
printf "\n%s\n\n" "${i}: ERROR"
lint_status=1
else
printf "%s\n" "${i}: SUCCESS"
fi
done
lint_status="${lint_status:-0}"
printf "\n"
else
printf 'Install shellcheck to lint script.\n'
printf 'Check https://www.shellcheck.net/ or https://github.com/koalaman/shellcheck\n\n'
fi
case "${format_status}" in
1) printf "Error: Some files not formatted succesfully.\n" ;;
esac
case "${lint_status}" in
1) printf "Error: Some shellcheck warnings need to be fixed.\n" ;;
esac
if [[ "${lint_status}" = 1 || "${format_status}" = 1 ]]; then
exit 1
else
exit 0
fi