Skip to content
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

Merged
merged 2 commits into from
Aug 8, 2023

Conversation

abhinav
Copy link
Contributor

@abhinav abhinav commented Aug 8, 2023

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 fixed in a separate 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)

Copy link
Contributor Author

abhinav commented Aug 8, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@abhinav abhinav added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Aug 8, 2023
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.
@abhinav abhinav changed the title ci/lint: Eanble staticcheck and other linters ci/lint: Enable staticcheck and other linters Aug 8, 2023
Comment on lines 225 to 230
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))
Copy link
Contributor Author

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@abhinav abhinav requested a review from a team August 8, 2023 19:31
Comment on lines 227 to 230
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]
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

@abhinav abhinav merged commit 062212b into main Aug 8, 2023
4 checks passed
@abhinav abhinav deleted the abhinav/golangci-lint-more branch August 8, 2023 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants