From d8c8c74c5d37f0009636325caf28af7ba564e2f9 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Wed, 11 Jan 2023 11:53:41 -0800 Subject: [PATCH] golangci-lint: Enable staticcheck Remove staticcheck from the list of disabled linters. It's enabled by default in golangci-lint. This also fixes minor remaining staticcheck issues that don't merit their own pull requests, or opts out of those that cannot be fixed yet. Notably, we're opting out of: - Resource.Name is deprecated (#9469) - github.com/golang/protobuf is deprecated (#11869) - strings.Title has been deprecated (#11870) Besides that, other issues addressed in this change are: ``` // all issues are in pkg codegen/schema/docs_parser.go:103:4: SA4006: this value of `text` is never used (staticcheck) codegen/schema/loader.go:253:3: SA9003: empty branch (staticcheck) resource/deploy/step_executor.go:328:12: SA9003: empty branch (staticcheck) resource/deploy/step_generator.go:141:10: SA9003: empty branch (staticcheck) codegen/pcl/invoke.go:97:10: SA9003: empty branch (staticcheck) codegen/hcl2/model/type_const.go:57:2: SA9003: empty branch (staticcheck) codegen/hcl2/model/type_enum.go:99:9: SA4001: &*x will be simplified to x. It will not copy x. (staticcheck) codegen/go/gen_test.go:399:19: SA4017: HasPrefix is a pure function but its return value is ignored (staticcheck) ``` Depends on #11857, #11858, #11859, #11860, #11862, #11865, #11866, #11867, #11868 Resolves #11808 --- .golangci.yml | 13 +++++++++++-- pkg/codegen/go/gen_test.go | 2 +- pkg/codegen/hcl2/model/type_const.go | 2 -- pkg/codegen/hcl2/model/type_enum.go | 3 ++- pkg/codegen/pcl/invoke.go | 3 +-- pkg/codegen/schema/docs_parser.go | 4 +++- pkg/codegen/schema/loader.go | 5 +---- pkg/resource/deploy/step_executor.go | 2 +- pkg/resource/deploy/step_generator.go | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89846c6c00f5..c04725b2018a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,8 +26,6 @@ linters: - unconvert - unused - paralleltest - disable: - - staticcheck # Disabled due to OOM errors in golangci-lint@v1.18.0 linters-settings: nolintlint: @@ -35,3 +33,14 @@ linters-settings: # pre-emptively. # Don't complain about these. allow-unused: true + +issues: + exclude: + # https://github.com/pulumi/pulumi/issues/9469 + - 'Name is deprecated: Name returns the variable or declaration name of the resource' + + # https://github.com/pulumi/pulumi/issues/11869 + - '"github.com/golang/protobuf/[\w/]+" is deprecated' + + # https://github.com/pulumi/pulumi/issues/11870 + - 'strings.Title has been deprecated' diff --git a/pkg/codegen/go/gen_test.go b/pkg/codegen/go/gen_test.go index d18e40125551..4fa86d96cd6d 100644 --- a/pkg/codegen/go/gen_test.go +++ b/pkg/codegen/go/gen_test.go @@ -398,7 +398,7 @@ loop: break loop case l == "" || strings.HasPrefix(l, "//"): default: - break + break loop } } assert.Truef(t, found, `Didn't find a line that complies with "%v"`, autogenerated) diff --git a/pkg/codegen/hcl2/model/type_const.go b/pkg/codegen/hcl2/model/type_const.go index a00c06a8220e..ac485ed7478a 100644 --- a/pkg/codegen/hcl2/model/type_const.go +++ b/pkg/codegen/hcl2/model/type_const.go @@ -54,8 +54,6 @@ func (t *ConstType) Pretty() pretty.Formatter { case cty.Number: return pretty.FromStringer(t.Value.AsBigFloat()) } - if t.Value.Type() == cty.String { - } return pretty.FromStringer(t) } diff --git a/pkg/codegen/hcl2/model/type_enum.go b/pkg/codegen/hcl2/model/type_enum.go index 081eea450ffd..7cf34769b4a4 100644 --- a/pkg/codegen/hcl2/model/type_enum.go +++ b/pkg/codegen/hcl2/model/type_enum.go @@ -96,7 +96,8 @@ func (t *EnumType) Pretty() pretty.Formatter { // Traverse attempts to traverse the enum type with the given traverser. This always fails. func (t *EnumType) Traverse(traverser hcl.Traverser) (Traversable, hcl.Diagnostics) { - return &*t, nil + out := *t + return &out, nil } // Equals returns true if this type has the same identity as the given type. diff --git a/pkg/codegen/pcl/invoke.go b/pkg/codegen/pcl/invoke.go index 9f7d68dc76e6..12b99af69c09 100644 --- a/pkg/codegen/pcl/invoke.go +++ b/pkg/codegen/pcl/invoke.go @@ -94,8 +94,7 @@ func annotateObjectProperties(modelType model.Type, schemaType schema.Type) { annotateObjectProperties(arg.ElementTypes[1], schemaType) } else if len(arg.ElementTypes) == 2 && arg.ElementTypes[1] == model.NoneType { annotateObjectProperties(arg.ElementTypes[0], schemaType) - } else { - // TODO https://github.com/pulumi/pulumi/issues/10993 + } else { //nolint:staticcheck // TODO https://github.com/pulumi/pulumi/issues/10993 // We need to handle the case where the schema type is a union type. } } diff --git a/pkg/codegen/schema/docs_parser.go b/pkg/codegen/schema/docs_parser.go index 59322630b624..4a73b59e2a56 100644 --- a/pkg/codegen/schema/docs_parser.go +++ b/pkg/codegen/schema/docs_parser.go @@ -100,7 +100,9 @@ func (shortcodeParser) parseShortcode(line []byte, pos int) (int, int, int, bool if inName { nameEnd = pos } - text, pos = text[3:], pos+3 + pos = pos + 3 + // We don't need to update text + // because we return after this break. break } diff --git a/pkg/codegen/schema/loader.go b/pkg/codegen/schema/loader.go index 11c68fe4dbca..9602f15c7d93 100644 --- a/pkg/codegen/schema/loader.go +++ b/pkg/codegen/schema/loader.go @@ -249,10 +249,7 @@ func (l *pluginLoader) loadSchemaBytes(pkg string, version *semver.Version) ([]b } if version == nil { - info, err := provider.GetPluginInfo() - if err != nil { - // Nonfatal - } + info, _ := provider.GetPluginInfo() // nonfatal error version = info.Version } diff --git a/pkg/resource/deploy/step_executor.go b/pkg/resource/deploy/step_executor.go index 2ae12473979b..24475f38c16b 100644 --- a/pkg/resource/deploy/step_executor.go +++ b/pkg/resource/deploy/step_executor.go @@ -325,7 +325,7 @@ func (se *stepExecutor) executeStep(workerID int, step Step) error { } else { if v, has := newState.Outputs[k]; has && !v.IsSecret() { newState.Outputs[k] = resource.MakeSecret(v) - } else if !has { + } else if !has { //nolint:staticcheck // https://github.com/pulumi/pulumi/issues/9926 // TODO (https://github.com/pulumi/pulumi/issues/9926): We want to re-enable this warning // but it requires that providers always return back _every_ output even in preview. We // might need to add a new "unset" PropertyValue to do this as there might be optional diff --git a/pkg/resource/deploy/step_generator.go b/pkg/resource/deploy/step_generator.go index 413d9320dde8..2613c4571832 100644 --- a/pkg/resource/deploy/step_generator.go +++ b/pkg/resource/deploy/step_generator.go @@ -138,7 +138,7 @@ func (sg *stepGenerator) checkParent(parent resource.URN, resourceType tokens.Ty if _, hasParent := sg.urns[parent]; !hasParent { return "", result.Errorf("could not find parent resource %v", parent) } - } else { + } else { //nolint:staticcheck // https://github.com/pulumi/pulumi/issues/10950 // Else try and set it to the root stack // TODO: It looks like this currently has some issues with state ordering (see