-
Notifications
You must be signed in to change notification settings - Fork 145
/
format_and_lint.sh
57 lines (52 loc) · 1.67 KB
/
format_and_lint.sh
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
#!/usr/bin/env sh
# shfmt - beautify scripts
if command -v shfmt 1>| /dev/null; then
printf "Beautifying scripts with shfmt... \n"
for k in . src/common src/sh src/bash; do
cd "${k}" 2>| /dev/null 1>&2 || exit 1
for i in *.*sh; do
if ! shfmt -w "${i}"; then
printf "%s\n\n" "${k}/${i}: ERROR"
format_status=1
else
printf "%s\n" "${k}/${i}: SUCCESS"
fi
done
cd - 2>| /dev/null 1>&2 || exit 1
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 k in . src/common src/sh src/bash; do
cd "${k}" 2>| /dev/null 1>&2 || exit 1
for i in *.*sh; do
if ! shellcheck -o all -e SC2312 "${i}"; then
printf "\n%s\n\n" "${k}/${i}: ERROR"
lint_status=1
else
printf "%s\n" "${k}/${i}: SUCCESS"
fi
done
cd - 2>| /dev/null 1>&2 || exit 1
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
[ "${format_status}" = 1 ] &&
printf "Error: Some files not formatted succesfully.\n"
[ "${lint_status}" = 1 ] &&
printf "Error: Some shellcheck warnings need to be fixed.\n"
if [ "${lint_status}" = 1 ] || [ "${format_status}" = 1 ]; then
exit 1
else
exit 0
fi