From ee48586fb2884dc2c05a43e86b0560735e488fed Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 11 Dec 2018 13:30:47 -0800 Subject: [PATCH] Add gometalinter (#2627) Parallel to https://github.com/terraform-providers/terraform-provider-azurerm/pull/2116 We need to run `gofmt -s` to switch over to the `gofmt` rule, and MM is going to complicate that. Once `1.20.0` is done, I'll run that command on flat MM files & add a `gofmt -s` step to MM generation (goimports does gofmt but doesn't do the s flag for silly reasons). I'll duplicate this over to tpgb once this PR is merged. --- .gometalinter.json | 15 +++++++++++++++ .travis.yml | 4 ++-- GNUmakefile | 24 +++++++++++------------- scripts/errcheck.sh | 24 ------------------------ 4 files changed, 28 insertions(+), 39 deletions(-) create mode 100644 .gometalinter.json delete mode 100755 scripts/errcheck.sh diff --git a/.gometalinter.json b/.gometalinter.json new file mode 100644 index 00000000..235b9f58 --- /dev/null +++ b/.gometalinter.json @@ -0,0 +1,15 @@ +{ + "Deadline": "10m", + "Enable": [ + "vet" + ], + "EnableGC": true, + "Linters": { + }, + "Sort": [ + "path", + "line" + ], + "Vendor": true, + "WarnUnmatchedDirective": true +} diff --git a/.travis.yml b/.travis.yml index f1374f28..1b90529d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,12 @@ install: # packages that live there. # See: https://github.com/golang/go/issues/12933 - bash scripts/gogetcookie.sh -- go get github.com/kardianos/govendor +- make tools script: +- make lint - make test - make vendor-status -- make vet - make website-test branches: diff --git a/GNUmakefile b/GNUmakefile index 679fb6bd..02879ebd 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,4 @@ TEST?=$$(go list ./... |grep -v 'vendor') -GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) WEBSITE_REPO=github.com/hashicorp/terraform-website PKG_NAME=google @@ -16,23 +15,22 @@ test: fmtcheck testacc: fmtcheck TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -ldflags="-X=github.com/terraform-providers/terraform-provider-google/version.ProviderVersion=acc" -vet: - @echo "go vet ." - @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ - echo ""; \ - echo "Vet found suspicious constructs. Please check the reported constructs"; \ - echo "and fix them if necessary before submitting the code for review."; \ - exit 1; \ - fi - fmt: - gofmt -w $(GOFMT_FILES) + @echo "==> Fixing source code with gofmt..." + gofmt -w ./$(PKG_NAME) +# Currently required by tf-deploy compile fmtcheck: @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" -errcheck: - @sh -c "'$(CURDIR)/scripts/errcheck.sh'" +lint: + @echo "==> Checking source code against linters..." + @gometalinter ./$(PKG_NAME) + tools: + @echo "==> installing required tooling..." + go get -u github.com/kardianos/govendor + go get -u github.com/alecthomas/gometalinter + gometalinter --install vendor-status: @govendor status diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh deleted file mode 100755 index 15464f5a..00000000 --- a/scripts/errcheck.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking for unchecked errors..." - -if ! which errcheck > /dev/null; then - echo "==> Installing errcheck..." - go get -u github.com/kisielk/errcheck -fi - -err_files=$(errcheck -ignoretests \ - -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \ - -ignore 'bytes:.*' \ - -ignore 'io:Close|Write' \ - $(go list ./...| grep -v /vendor/)) - -if [[ -n ${err_files} ]]; then - echo 'Unchecked errors found in the following places:' - echo "${err_files}" - echo "Please handle returned errors. You can check directly with \`make errcheck\`" - exit 1 -fi - -exit 0