From 965c0f3f919b006321339ca3358913f96b4cc046 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 12 Oct 2021 11:09:00 -0700 Subject: [PATCH] build: Run staticcheck with "go run" Running the tool this way ensures that we'll always run the version selected by our go.mod file, rather than whatever happened to be available in $GOPATH/bin on the system where we're running this. This change caused some contexts to now be using a newer version of staticcheck with additional checks, and so this commit also includes some changes to quiet the new warnings without any change in overall behavior. --- internal/lang/funcs/cidr_test.go | 2 +- internal/plugin/discovery/find.go | 4 +--- scripts/staticcheck.sh | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/lang/funcs/cidr_test.go b/internal/lang/funcs/cidr_test.go index 524653111..cb8d810a9 100644 --- a/internal/lang/funcs/cidr_test.go +++ b/internal/lang/funcs/cidr_test.go @@ -246,7 +246,7 @@ func TestCidrSubnet(t *testing.T) { }, { // fractions are Not Ok cty.StringVal("10.256.0.0/8"), - cty.NumberFloatVal(2 / 3), + cty.NumberFloatVal(2.0 / 3.0), cty.NumberFloatVal(.75), cty.UnknownVal(cty.String), true, diff --git a/internal/plugin/discovery/find.go b/internal/plugin/discovery/find.go index f053312b0..027a887eb 100644 --- a/internal/plugin/discovery/find.go +++ b/internal/plugin/discovery/find.go @@ -154,9 +154,7 @@ func ResolvePluginPaths(paths []string) PluginMetaSet { // Trim the .exe suffix used on Windows before we start wrangling // the remainder of the path. - if strings.HasSuffix(baseName, ".exe") { - baseName = baseName[:len(baseName)-4] - } + baseName = strings.TrimSuffix(baseName, ".exe") parts := strings.SplitN(baseName, "_v", 2) name := parts[0] diff --git a/scripts/staticcheck.sh b/scripts/staticcheck.sh index 66c47092f..2dd08309a 100755 --- a/scripts/staticcheck.sh +++ b/scripts/staticcheck.sh @@ -13,4 +13,4 @@ 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} +go run honnef.co/go/tools/cmd/staticcheck -checks 'all,-ST*' ${packages}