Update gometalinter for modules, add staticcheck (#2908)

This isn't working locally, but it matches the changes made in https://github.com/terraform-providers/terraform-provider-azurerm/pull/2722 so maybe something freaky is going on and it will only work in CI?

Edit: This only works in CI (well, at least doesn't work locally for *me*) but the same is true in the Azure provider. Most of those rules can be turned back on provided we make the corresponding code changes, but let's bring back `unused` for now. I'll dupe over to tpgb on approval.
This commit is contained in:
Riley Karson 2019-02-05 11:47:40 -08:00 committed by GitHub
parent 222c287629
commit 8a237de2dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View File

@ -3,6 +3,7 @@
"Enable": [
"gofmt",
"misspell",
"staticcheck",
"structcheck",
"unconvert",
"varcheck",

View File

@ -5,6 +5,8 @@ services:
language: go
go:
- "1.11.x"
env:
- GO111MODULE=off
install:
# This script is used by the Travis build to install a cookie for
@ -19,9 +21,6 @@ script:
- make test
- make website-test
env:
- GO111MODULE=off
branches:
only:
- master

View File

@ -21,16 +21,17 @@ fmt:
# Currently required by tf-deploy compile
fmtcheck:
@echo "==> Checking source code against gofmt..."
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
lint:
@echo "==> Checking source code against linters..."
@gometalinter ./$(PKG_NAME)
tools:
@bash -c "GO111MODULE=off gometalinter -d ./... 2> >(egrep '(^DEBUG.*linter took|^DEBUG.*total elapsed|^[^D])' >&2)"
tools:
@echo "==> installing required tooling..."
go get -u github.com/kardianos/govendor
go get -u github.com/alecthomas/gometalinter
gometalinter --install
GO111MODULE=off go get -u github.com/alecthomas/gometalinter
GO111MODULE=off gometalinter --install
test-compile:
@if [ "$(TEST)" = "./..." ]; then \
@ -54,5 +55,5 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website website-test
.PHONY: build test testacc vet fmt fmtcheck lint tools errcheck test-compile website website-test

View File

@ -91,7 +91,7 @@ func main() {
}
}
testnames := []string{}
for tn, _ := range tests {
for tn := range tests {
testnames = append(testnames, tn)
}
sort.Strings(testnames)
@ -153,7 +153,7 @@ func getResourceName(fName, googleDir string, providerFiles []string) (string, e
}
// Loop through all the top-level objects in the resource file.
// One of them is the resource definition: something like resourceComputeInstance()
for k, _ := range resourceFile.Scope.Objects {
for k := range resourceFile.Scope.Objects {
// Matches the line in the provider file where the resource is defined,
// e.g. "google_compute_instance": resourceComputeInstance()
re := regexp.MustCompile(`"(.*)":\s*` + k + `\(\)`)

19
staticcheck.conf Normal file
View File

@ -0,0 +1,19 @@
checks = [
"all",
"-S1002",
"-S1007",
"-S1008",
"-S1009",
"-S1019",
"-S1021",
"-S1025",
"-S1034",
"-ST1000",
"-ST1003",
"-ST1005",
"-ST1017",
"-SA4006",
"-SA4010",
"-SA6000",
"-SA6005"
]