-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci/lint: Enable staticcheck and other linters #487
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
Enables nearly all the same linters that are used in pulumi/pulumi, disabling deprecated or unused linters (per pulumi/pulumi). The following linters were not enabled: - lll, gofumpt: These may cause more code churn than desirable in this commit. They may be enabled in the future. - prealloc: This has been a source of many nil-vs-empty-slice bugs. Enabling this would increase the risk of this commit. Fixes the following issues as part of enabling the linters: ``` pkg/pulumiyaml/ast/template.go:67:34: S1019: should use make([]*StringExpr, list.Len()) instead (gosimple) pkg/pulumiyaml/ast/template.go:102:36: S1019: should use make([]ConfigMapEntry, obj.Len()) instead (gosimple) pkg/pulumiyaml/ast/template.go:157:39: S1019: should use make([]VariablesMapEntry, obj.Len()) instead (gosimple) pkg/pulumiyaml/ast/template.go:199:39: S1019: should use make([]ResourcesMapEntry, obj.Len()) instead (gosimple) pkg/pulumiyaml/ast/template.go:251:38: S1019: should use make([]PropertyMapEntry, obj.Len()) instead (gosimple) pkg/pulumiyaml/ast/template.go:618:25: SA6005: should use strings.EqualFold instead (staticcheck) pkg/pulumiyaml/diags/utils.go:47:2: S1001: should use copy(to, from) instead of a loop (gosimple) pkg/pulumiyaml/diags/diags.go:125:12: S1039: unnecessary use of fmt.Sprintf (gosimple) pkg/pulumiyaml/diags/diags.go:143:14: S1039: unnecessary use of fmt.Sprintf (gosimple) pkg/pulumiyaml/syntax/diags.go:91:19: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple) pkg/pulumiyaml/packages.go:161:63: S1039: unnecessary use of fmt.Sprintf (gosimple) pkg/pulumiyaml/analyser.go:1225:2: S1008: should use 'return e.VisitExpr(ctx, x)' instead of 'if !e.VisitExpr(ctx, x) { return false }; return true' (gosimple) pkg/pulumiyaml/run.go:12:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) pkg/pulumiyaml/analyser.go:800:8: SA6005: should use strings.EqualFold instead (staticcheck) pkg/pulumiyaml/codegen/load.go:715:2: S1023: redundant `return` statement (gosimple) pkg/pulumiyaml/codegen/gen_program.go:531:9: nilness: panic with nil value (govet) pkg/pulumiyaml/codegen/gen_program.go:181:21: SA5009: couldn't parse format string (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:168:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:203:3: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:229:4: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:732:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:733:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:739:3: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/load.go:519:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/load.go:630:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/load.go:723:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/load.go:896:2: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/load.go:1071:3: SA1019: contract.Assert is deprecated: Use Assertf. (staticcheck) pkg/pulumiyaml/codegen/gen_program.go:10:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) pkg/tests/example_transpile_test.go:8:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) pkg/tests/example_test.go:86:65: SA4009: argument err is overwritten before first use (staticcheck) pkg/tests/example_test.go:96:5: SA4009(related information): assignment to err (staticcheck) pkg/tests/example_test.go:103:5: directive `// nolint:gosec // temporary file, no secrets, non-executable` should be written without leading space as `//nolint:gosec // temporary file, no secrets, non-executable` (nolintlint) ``` The following issues were NOT fixed in this commit because they appear to have some bearing on logic and may represent bugs in pulumi-yaml. ``` pkg/pulumiyaml/codegen/gen_program.go:230:24: SA4010: this result of append is never used, except maybe in other appends (staticcheck) pkg/pulumiyaml/codegen/load.go:569:19: SA4010: this result of append is never used, except maybe in other appends (staticcheck) ``` Fixes for those two are commited separately to allow for easier discussion.
Fixes the following lint issues by deleting the unused slices. ``` pkg/pulumiyaml/codegen/gen_program.go:230:24: SA4010: this result of append is never used, except maybe in other appends (staticcheck) pkg/pulumiyaml/codegen/load.go:569:19: SA4010: this result of append is never used, except maybe in other appends (staticcheck) ``` This commit is kept separate from the other lint fixes because we need someone with more familiarity with this code to explicitly confirm that this is not a bug in pulumi-yaml.
fbe518e
to
ac830e1
Compare
var additionalSecrets []*syn.StringNode | ||
for i, input := range n.Inputs { | ||
value := input.Value | ||
if f, ok := value.(*model.FunctionCallExpression); ok && f.Name == "secret" { | ||
contract.Assertf(len(f.Args) == 1, "Expected exactly one argument to secret, got %d", len(f.Args)) | ||
additionalSecrets = append(additionalSecrets, syn.String(input.Name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Frassle @Zaid-Ajaj these slices were unused.
Highlighting this to make sure this information wasn't intended to be used.
@@ -566,7 +565,6 @@ func (imp *importer) getResourceRefList(optionField ast.Expr, name string, field | |||
continue | |||
} | |||
resourceName := sym.Property.Accessors[0].(*ast.PropertyName).Name | |||
resourceNames = append(resourceNames, resourceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
if f, ok := value.(*model.FunctionCallExpression); ok && f.Name == "secret" { | ||
contract.Assert(len(f.Args) == 1) | ||
additionalSecrets = append(additionalSecrets, syn.String(input.Name)) | ||
contract.Assertf(len(f.Args) == 1, "Expected exactly one argument to secret, got %d", len(f.Args)) | ||
value = f.Args[0] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine this whole branch can go. Just let the secret function be eval'd by g.expr below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'll error out because generator.function
doesn't recognize the "secret"
function.
That's fixable but I don't think this PR should do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... that's probably why this was supposed to be doing something with additionalSecrets.
Well this is no more broken than it was before, we'll have to fix this somehow later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. Created #488 to track follow up
Enables nearly all the same linters that are used in pulumi/pulumi,
disabling deprecated or unused linters (per pulumi/pulumi).
The following linters were not enabled:
These may cause more code churn than desirable in this commit.
They may be enabled in the future.
This has been a source of many nil-vs-empty-slice bugs.
Enabling this would increase the risk of this commit.
Fixes the following issues as part of enabling the linters:
The following issues were fixed in a separate commit
because they appear to have some bearing on logic
and may represent bugs in pulumi-yaml.