add staticcheck make target

cleanup the old fmtcheck script while we're in here
This commit is contained in:
James Bardin 2020-12-02 12:02:33 -05:00
parent 5eb7170f70
commit a3fb07d008
3 changed files with 24 additions and 5 deletions

View File

@ -20,6 +20,9 @@ protobuf:
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
staticcheck:
@sh -c "'$(CURDIR)/scripts/staticcheck.sh'"
website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
@ -46,4 +49,4 @@ endif
# under parallel conditions.
.NOTPARALLEL:
.PHONY: fmtcheck generate protobuf website website-test
.PHONY: fmtcheck generate protobuf website website-test staticcheck

View File

@ -2,11 +2,11 @@
# Check go fmt
echo "==> Checking that code complies with go fmt requirements..."
gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`)
gofmt_files=$(go fmt ./...)
if [[ -n ${gofmt_files} ]]; then
echo 'gofmt needs running on the following files:'
echo "${gofmt_files}"
echo "You can use the command: \`gofmt -w .\` to reformat code."
echo "You can use the command: \`go fmt\` to reformat code."
exit 1
fi

16
scripts/staticcheck.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
echo "==> Checking that code complies with static analysis requirements..."
# Skip legacy code which is frozen, and can be removed once we can refactor the
# remote backends to no longer require it.
skip="internal/legacy|backend/remote-state/"
# Skip generated code for protobufs.
skip=$skip"|internal/planproto|internal/tfplugin5|internal/tfplugin6"
packages=$(go list ./... | egrep -v ${skip})
# We are skipping style-related checks, since terraform intentionally breaks
# some of these. The goal here is to find issues that reduce code clarity, or
# may result in bugs.
staticcheck -checks 'all,-ST*' ${packages}