-
Notifications
You must be signed in to change notification settings - Fork 27
/
lint.sh
executable file
·66 lines (60 loc) · 1.74 KB
/
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
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -e
function abspath {
cd "$1"
pwd
}
# Automatically install this script as a pre-commit hook
if [[ -d .git/ && ! -f .git/hooks/pre-commit ]]; then
mkdir -p .git/hooks/
cat <<EOF > .git/hooks/pre-commit
#!/usr/bin/env bash
set -e
$(abspath "$(dirname "$0")")/lint.sh
EOF
chmod +x .git/hooks/pre-commit
fi
stack test :hlint
if [[ "$(stack exec scan -- -v)" = "" ]]; then
stack install scan
fi
scan=(stack exec scan --)
# Haskell style scanner doesn't provide proper exit code ---
# it always exists with zero even if it found errors.
scanout="$(mktemp)"
(find src test -name '*.hs' -and -not -exec grep -q TemplateHaskell {} \; \
-print0 | \
xargs -0 "${scan[@]}" -t -j false -c false | \
grep -v 'back slash at line end .may disturb cpp.' || true) > "$scanout"
cat "$scanout"
if [[ "$(cat "$scanout")" != "" ]]; then
exit 1
fi
if command -v shellcheck > /dev/null; then
shellcheck ./*.sh
else
echo "Seems shellcheck is not installed; skipped linting shell scripts..."
echo "Recommend to install shellcheck:"
if command -v apt-get > /dev/null; then
echo " apt-get install shellcheck"
elif command -v pacman > /dev/null; then
echo " pacman -S shellcheck"
elif command -v brew > /dev/null; then
echo " brew install shellcheck"
else
echo " https://github.com/koalaman/shellcheck"
fi
fi
if command -v hadolint > /dev/null; then
hadolint Dockerfile
else
echo "Seems hadolint is not installed; skipped linting Dockerfile..."
echo "Recommend to install hadolint:"
if command -v pacman > /dev/null; then
echo " pacman -S hadolint-git"
elif command -v brew > /dev/null; then
echo " brew install hadolint"
else
echo " https://github.com/hadolint/hadolint"
fi
fi