Skip to content

Commit

Permalink
build: add vet-check
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed May 27, 2020
1 parent fb26b0c commit 8e40ff6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ goimports-check:
fi
.PHONY: goimports-check

vet-check:
./scripts/vet.sh gen
./scripts/vet.sh chk
.PHONY: vet-check

check: fmt-check
check: gendocgo-check
check: goimports-check
check: vet-check
.PHONY: check


Expand Down
62 changes: 62 additions & 0 deletions scripts/vet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

o=_output/_vet/
ALL="$o/vet.txt"


typi() {
local typ="$1"
local fna="$o/vet_$(echo "$typ" | sed -r -e "s/[^a-zA-Z0-9]+/_/g").txt"

grep -F "$typ" "$UNKNOWN" >"$fna"
grep -F -v "$typ" "$UNKNOWN" >""$INTERMEDIATE""
cp "$INTERMEDIATE" "$UNKNOWN"

rm -f "$INTERMEDIATE"
if [ ! -s "$fna" ]; then
rm -f "$fna"
fi
}

typ() {
local UNKNOWN=$o/vet0.txt
local INTERMEDIATE=$o/vet1.txt

cp "$ALL" "$UNKNOWN"
typi "unreachable code"
typi "composite literal uses unkeyed fields"
typi "repeats json tag"
typi "bad syntax for struct tag key"
typi "bad syntax for struct tag value"
typi "pairs not separated by spaces"
typi "bad syntax for struct tag pair"
}

gen() {
rm -rf "$o"
mkdir -p "$o"
go vet ./... 2>"$ALL"

typ
ls -l $o/
}

chki() {
local typ="$1"

if grep -F "$typ" "$ALL"; then
exit 1
fi
}

chk() {
chki "unreachable code"
chki "composite literal uses unkeyed fields"
: chki "repeats json tag"
: chki "bad syntax for struct tag key"
chki "bad syntax for struct tag value"
chki "pairs not separated by spaces"
chki "bad syntax for struct tag pair"
}

"$@"

0 comments on commit 8e40ff6

Please sign in to comment.