Skip to content

Commit

Permalink
Update gometalinter for modules, add staticcheck (hashicorp#2908)
Browse files Browse the repository at this point in the history
This isn't working locally, but it matches the changes made in hashicorp/terraform-provider-azurerm#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.
  • Loading branch information
rileykarson authored Feb 5, 2019
1 parent 222c287 commit 8a237de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Enable": [
"gofmt",
"misspell",
"staticcheck",
"structcheck",
"unconvert",
"varcheck",
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,9 +21,6 @@ script:
- make test
- make website-test

env:
- GO111MODULE=off

branches:
only:
- master
Expand Down
13 changes: 7 additions & 6 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

4 changes: 2 additions & 2 deletions scripts/affectedtests/affectedtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func main() {
}
}
testnames := []string{}
for tn, _ := range tests {
for tn := range tests {
testnames = append(testnames, tn)
}
sort.Strings(testnames)
Expand Down Expand Up @@ -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 + `\(\)`)
Expand Down
19 changes: 19 additions & 0 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
checks = [
"all",
"-S1002",
"-S1007",
"-S1008",
"-S1009",
"-S1019",
"-S1021",
"-S1025",
"-S1034",
"-ST1000",
"-ST1003",
"-ST1005",
"-ST1017",
"-SA4006",
"-SA4010",
"-SA6000",
"-SA6005"
]

0 comments on commit 8a237de

Please sign in to comment.