From 918ddfb59ae227b674afd133073981bbfc00012e Mon Sep 17 00:00:00 2001 From: Rob Lee Date: Fri, 10 Dec 2021 06:03:48 +0000 Subject: [PATCH] =?UTF-8?q?Replace=20`golint`=20with=20`go=20vet`=E2=80=93?= =?UTF-8?q?=20#1743=20(#1744)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set GO111MODULE to auto in golint script– #1743 As mentioned in #1743 the Go modules environment flag is set to `off` in the script which appears to cause a warning message for each module of the codebase that it is "not in GOROOT". Set to `auto` as this allows the same build to be run the original way should someone choose to delete the `go.mod` file from the project root. * Remove redundant code – golint script Go 1.17 ignores `GO111MODULE` and there are no directories in the project root called `mock`. * Replace `golint` with `go vet` `golint` is deprecated (and frozen) replace with the current `go vet`. This reported one issue on `main` branch: ```pkg/stash/with_etcd.go:33:28: loop variable ep captured by func literal``` Fixed loop variable capture with extraction to parameterised anonymous function passed loop variable and passed in to `errgroup.Go` call. --- Makefile | 2 +- pkg/stash/with_etcd.go | 11 +++++++---- scripts/{check_golint.sh => check_govet.sh} | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) rename scripts/{check_golint.sh => check_govet.sh} (57%) diff --git a/Makefile b/Makefile index 422c4cf2..9370f737 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ setup-dev-env: .PHONY: verify verify: ## verify athens codebase ./scripts/check_gofmt.sh - ./scripts/check_golint.sh + ./scripts/check_govet.sh ./scripts/check_deps.sh ./scripts/check_conflicts.sh diff --git a/pkg/stash/with_etcd.go b/pkg/stash/with_etcd.go index 26203e10..3ce65771 100644 --- a/pkg/stash/with_etcd.go +++ b/pkg/stash/with_etcd.go @@ -29,10 +29,13 @@ func WithEtcd(endpoints []string, checker storage.Checker) (Wrapper, error) { } var eg errgroup.Group for _, ep := range endpoints { - eg.Go(func() error { - _, err := c.Status(ctx, ep) - return err - }) + epStat := func(ep string) func() error { + return func() error { + _, err := c.Status(ctx, ep) + return err + } + }(ep) + eg.Go(epStat) } err = eg.Wait() if err != nil { diff --git a/scripts/check_golint.sh b/scripts/check_govet.sh similarity index 57% rename from scripts/check_golint.sh rename to scripts/check_govet.sh index 60d0cf60..4f139895 100755 --- a/scripts/check_golint.sh +++ b/scripts/check_govet.sh @@ -4,4 +4,4 @@ # Run the linter on everything except generated code set -euo pipefail -golint -set_exit_status $(GO111MODULE=off go list ./... | grep -v '/mocks') +go vet ./...