-
Notifications
You must be signed in to change notification settings - Fork 1
/
superlint
executable file
·82 lines (72 loc) · 2.04 KB
/
superlint
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
75
76
77
78
79
80
81
82
#!/bin/bash
set -eu
cmd(){ echo $(basename $0); }
show_help() {
echo "\
Usage:
$(cmd) [OPTION...]
-r, --remote; Set remote to diff against when determining which files to lint
-b, --branch; Set the base remote branch to diff against, default is the HEAD branch
-a, --lint-all; Ignore diff and lint entire code base
" | column -t -s ";"
}
UPSTREAM=origin
LINT_ALL=false
BRANCH=
while test $# -gt 0; do
case "$1" in
-h|-\?|--help)
show_help
exit
;;
-r|--remote)
if [ "$2" ]; then
UPSTREAM=$2
shift
else
echo 'ERROR: "--remote" requires a non-empty option argument.'
exit 1
fi
;;
-b|--branch)
if [ "$2" ]; then
BRANCH=$2
shift
else
echo 'ERROR: "--branch" requires a non-empty option argument.'
exit 1
fi
;;
-a|--lint-all)
LINT_ALL=true
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
esac
shift
done
SUPER_LINTER_DIR=$(echo ${BASH_SOURCE[0]} | sed 's/\/superlint//')
echo "rebuilding the super-linter image..."
docker build -t super-linter $SUPER_LINTER_DIR >/dev/null
GIT_ROOT=$(git rev-parse --show-toplevel)
MAIN_BRANCH=${BRANCH:-$(git remote show $UPSTREAM | grep "HEAD branch" | sed 's/.*: //')}
if ${LINT_ALL}; then
MOUNTS="-v ${GIT_ROOT}:/tmp/lint/"
echo "super-linter will lint all files in: $GIT_ROOT"
else
MOUNTS="-v ${GIT_ROOT}/.git:/tmp/lint/.git"
echo "super-linter will lint the following files:"
DIFF=$(git diff --name-only $MAIN_BRANCH)
for FILE in $DIFF;
do
echo " ${GIT_ROOT}/${FILE}"
MOUNTS="$MOUNTS -v ${GIT_ROOT}/${FILE}:/tmp/lint/${FILE}"
done
fi
echo "--- Running super-linter"
exec docker run --rm -e LOG_LEVEL=ERROR -e RUN_LOCAL=true $MOUNTS super-linter