Skip to content

Commit

Permalink
Merge #11871
Browse files Browse the repository at this point in the history
11871: golangci-lint: Enable staticcheck r=RobbieMcKinstry a=abhinav

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

---

**NOTE**: This PR's base branch is currently #11868.
The base branch will be updated when that lands.

Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
  • Loading branch information
bors[bot] and abhinav committed Jan 15, 2023
2 parents cd19833 + d8c8c74 commit 8b7e084
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
13 changes: 11 additions & 2 deletions .golangci.yml
Expand Up @@ -26,12 +26,21 @@ linters:
- unconvert
- unused
- paralleltest
disable:
- staticcheck # Disabled due to OOM errors in golangci-lint@v1.18.0

linters-settings:
nolintlint:
# Some linter exclusions are added to generated or templated files
# 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'
2 changes: 1 addition & 1 deletion pkg/codegen/go/gen_test.go
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkg/codegen/hcl2/model/type_const.go
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/codegen/hcl2/model/type_enum.go
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions pkg/codegen/pcl/invoke.go
Expand Up @@ -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.
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/codegen/schema/docs_parser.go
Expand Up @@ -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
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/codegen/schema/loader.go
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/deploy/step_executor.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/deploy/step_generator.go
Expand Up @@ -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
Expand Down

0 comments on commit 8b7e084

Please sign in to comment.