diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 7e48e4f90615..a688b517dffb 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -191,7 +191,7 @@ jobs: - name: "Code consistency checks" run: | - make fmtcheck importscheck copyright generate staticcheck exhaustive protobuf + make fmtcheck importscheck vetcheck copyright generate staticcheck exhaustive protobuf if [[ -n "$(git status --porcelain)" ]]; then echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate' and 'make protobuf' locally and then commit the updated files." git >&2 status --porcelain diff --git a/Makefile b/Makefile index cc659d305328..3253d8f23ad9 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,10 @@ fmtcheck: importscheck: "$(CURDIR)/scripts/goimportscheck.sh" +vetcheck: + @echo "==> Checking that the code complies with go vet requirements" + @go vet ./... + staticcheck: "$(CURDIR)/scripts/staticcheck.sh" @@ -52,4 +56,4 @@ website/build-local: # under parallel conditions. .NOTPARALLEL: -.PHONY: fmtcheck importscheck generate protobuf staticcheck syncdeps website website/local website/build-local +.PHONY: fmtcheck importscheck vetcheck generate protobuf staticcheck syncdeps website website/local website/build-local diff --git a/internal/addrs/module_instance_test.go b/internal/addrs/module_instance_test.go index bcf809e0137e..82e5c7a65aa9 100644 --- a/internal/addrs/module_instance_test.go +++ b/internal/addrs/module_instance_test.go @@ -84,14 +84,14 @@ func TestModuleInstanceEqual_false(t *testing.T) { func BenchmarkStringShort(b *testing.B) { addr, _ := ParseModuleInstanceStr(`module.foo`) for n := 0; n < b.N; n++ { - addr.String() + _ = addr.String() } } func BenchmarkStringLong(b *testing.B) { addr, _ := ParseModuleInstanceStr(`module.southamerica-brazil-region.module.user-regional-desktops.module.user-name`) for n := 0; n < b.N; n++ { - addr.String() + _ = addr.String() } } diff --git a/internal/addrs/module_test.go b/internal/addrs/module_test.go index 3daa1c3c4dc2..ed7a90decc7b 100644 --- a/internal/addrs/module_test.go +++ b/internal/addrs/module_test.go @@ -87,13 +87,13 @@ func TestModuleString(t *testing.T) { func BenchmarkModuleStringShort(b *testing.B) { module := Module{"a", "b"} for n := 0; n < b.N; n++ { - module.String() + _ = module.String() } } func BenchmarkModuleStringLong(b *testing.B) { module := Module{"southamerica-brazil-region", "user-regional-desktop", "user-name"} for n := 0; n < b.N; n++ { - module.String() + _ = module.String() } } diff --git a/internal/command/apply_test.go b/internal/command/apply_test.go index d304095b436f..794a76651eab 100644 --- a/internal/command/apply_test.go +++ b/internal/command/apply_test.go @@ -293,6 +293,10 @@ func TestApply_parallelism(t *testing.T) { // to proceed in unison. beginCtx, begin := context.WithCancel(context.Background()) + // This just makes go vet happy, in reality the function will never exit if + // begin() isn't called inside ApplyResourceChangeFn. + defer begin() + // Since our mock provider has its own mutex preventing concurrent calls // to ApplyResourceChange, we need to use a number of separate providers // here. They will all have the same mock implementation function assigned diff --git a/internal/command/plan_test.go b/internal/command/plan_test.go index 12643e5659b4..e8ac2155e1c1 100644 --- a/internal/command/plan_test.go +++ b/internal/command/plan_test.go @@ -1429,6 +1429,10 @@ func TestPlan_parallelism(t *testing.T) { // to proceed in unison. beginCtx, begin := context.WithCancel(context.Background()) + // This just makes go vet happy, in reality the function will never exit if + // begin() isn't called inside ApplyResourceChangeFn. + defer begin() + // Since our mock provider has its own mutex preventing concurrent calls // to ApplyResourceChange, we need to use a number of separate providers // here. They will all have the same mock implementation function assigned diff --git a/internal/configs/config.go b/internal/configs/config.go index f911eb58434e..eada09d56a25 100644 --- a/internal/configs/config.go +++ b/internal/configs/config.go @@ -229,7 +229,6 @@ func (c *Config) TargetExists(target addrs.Targetable) bool { default: panic(fmt.Errorf("unrecognized targetable type: %d", target.AddrType())) } - return true } // EntersNewPackage returns true if this call is to an external module, either diff --git a/internal/grpcwrap/provider6.go b/internal/grpcwrap/provider6.go index 1935527c8ef3..ccc08e23aac3 100644 --- a/internal/grpcwrap/provider6.go +++ b/internal/grpcwrap/provider6.go @@ -519,7 +519,6 @@ func (p *provider6) CloseEphemeralResource(_ context.Context, req *tfplugin6.Clo func (p *provider6) GetFunctions(context.Context, *tfplugin6.GetFunctions_Request) (*tfplugin6.GetFunctions_Response, error) { panic("unimplemented") - return nil, nil } func (p *provider6) CallFunction(_ context.Context, req *tfplugin6.CallFunction_Request) (*tfplugin6.CallFunction_Response, error) { diff --git a/internal/moduletest/hcl/variable_cache_test.go b/internal/moduletest/hcl/variable_cache_test.go index ed5e4c39ce78..2ab73160fcae 100644 --- a/internal/moduletest/hcl/variable_cache_test.go +++ b/internal/moduletest/hcl/variable_cache_test.go @@ -68,7 +68,7 @@ func TestFileVariables(t *testing.T) { FileVariables: func() map[string]hcl.Expression { vars := make(map[string]hcl.Expression) for name, value := range tc.Values { - expr, diags := hclsyntax.ParseExpression([]byte(value), "test.tf", hcl.Pos{0, 0, 0}) + expr, diags := hclsyntax.ParseExpression([]byte(value), "test.tf", hcl.Pos{Line: 0, Column: 0, Byte: 0}) if len(diags) > 0 { t.Fatalf("unexpected errors: %v", diags) }