Debian Codegraph @

scripts/go-vet-harder

raw
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 GREEN=$'\E[00;32m'
6 RED=$'\E[00;31m'
7 RESET=$'\E[0m'
8 if [ ! -t 1 ]; then
9 GREEN=''
10 RED=''
11 RESET=''
12 fi
13
14 VETTOOLS=(
15 # fieldalignment: noisy and not useful here
16 findcall
17 ifaceassert
18 lostcancel
19 nilness
20 shadow
21 stringintconv
22 unmarshal
23 unusedresult
24 )
25
26 DIR="$(mktemp -d -t 'go-vet-')"
27 trap 'rm -r $DIR' EXIT
28
29 touch "$DIR/vet"
30 go vet ./... >"$DIR/vet" 2>&1 &
31
32 for tool in "${VETTOOLS[@]}"; do
33 touch "$DIR/$tool"
34 "$tool" ./... >"$DIR/$tool" 2>&1 &
35 done
36
37 wait
38
39 if hash escape-regex 2>/dev/null; then
40 REPLACE="$(escape-regex -s "$(pwd)"/)"
41 else
42 REPLACE=''
43 fi
44
45 VETTOOLS+=(vet)
46 ERRORS=0
47 for tool in "${VETTOOLS[@]}"; do
48 if [[ -s "$DIR/$tool" ]]; then
49 printf "%s: ${RED}error${RESET}\n" "$tool"
50 if [[ -n $REPLACE ]]; then
51 sed "s/$REPLACE//g" "$DIR/$tool" | pr -o4 -t -
52 else
53 pr -o4 -t - "$DIR/$tool"
54 fi
55 ERRORS=1
56 else
57 printf "%s: ${GREEN}pass${RESET}\n" "$tool"
58 fi
59 done
60
61 exit $ERRORS