Skip to content

Commit

Permalink
Fix linter deprecation warnings and enhance coverage (#241)
Browse files Browse the repository at this point in the history
Fix some linter deprecation warnings and add the gosimple linter. Can be
reviewed commit by commit.

- **Silence golangci-lint warnings**

> WARN [config_reader] The configuration option `run.skip-dirs` is
deprecated, please use `issues.exclude-dirs`.
> WARN [config_reader] The configuration option
`run.skip-dirs-use-default` is deprecated, please use
`issues.exclude-dirs-use-default`.
> WARN [lintersdb] The linter named "megacheck" is deprecated. It has
been split into: gosimple, staticcheck, unused.

- **Add gosimple linter. Enabled linters now add up to the previous
megacheck.**
- **Fix gosimple warnings in the code base**
  • Loading branch information
thomas11 authored Jun 1, 2024
1 parent 8a3ebc8 commit 2bf8636
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stage-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:

jobs:
lint:
container: golangci/golangci-lint:v1.54.2
container: golangci/golangci-lint:v1.59
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand Down
9 changes: 5 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
run:
timeout: 10m
issues:
# Enable checking the by default skipped "examples" dirs
skip-dirs:
exclude-dirs-use-default: false
exclude-dirs:
- vendor$
- third_party$
- testdata$
- Godeps$
- builtin$
skip-dirs-use-default: false
linters:
enable-all: false
enable:
Expand All @@ -16,15 +17,15 @@ linters:
- gofmt
- revive
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- unconvert
- paralleltest
- staticcheck
- stylecheck
- unused
disable:
- staticcheck # Disabled due to OOM errors in golangci-lint@v1.18.0
- megacheck # Disabled due to OOM errors in golangci-lint@v1.18.0
6 changes: 3 additions & 3 deletions infer/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ func (o Options) dispatch() dispatch.Options {
functions := map[tokens.Type]t.Invoke{}
for _, r := range o.Functions {
typ, err := r.GetToken()
contract.AssertNoError(err)
contract.AssertNoErrorf(err, "failed to get token for function %v", r)
functions[typ] = r
}
customs := map[tokens.Type]t.CustomResource{}
for _, r := range o.Resources {
typ, err := r.GetToken()
contract.AssertNoError(err)
contract.AssertNoErrorf(err, "failed to get token for resource %v", r)
customs[typ] = r
}
components := map[tokens.Type]t.ComponentResource{}
for _, r := range o.Components {
typ, err := r.GetToken()
contract.AssertNoError(err)
contract.AssertNoErrorf(err, "failed to get token for component %v", r)
components[typ] = r
}
return dispatch.Options{
Expand Down
12 changes: 4 additions & 8 deletions infer/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ func (g *fieldGenerator) ensureDefaultSecrets() {

args, ok, err := g.argsMatcher.TargetStructFields(g.args)
contract.Assertf(ok, "we match by construction")
contract.AssertNoError(err)
contract.AssertNoErrorf(err, "TargetStructFields on %v", g.args)

state, ok, err := g.stateMatcher.TargetStructFields(g.state)
contract.Assertf(ok, "we match by construction")
contract.AssertNoError(err)
contract.AssertNoErrorf(err, "TargetStructFields on %v", g.state)

for _, f := range state {
if f.Internal {
Expand Down Expand Up @@ -705,9 +705,7 @@ func (i *inputField) Computed() InputField {
input.kind = inputComputed
// Copy input fields
input.fields = make([]introspect.FieldTag, len(i.fields))
for i, f := range i.fields {
input.fields[i] = f
}
copy(input.fields, i.fields)
return input
}

Expand All @@ -716,9 +714,7 @@ func (i *inputField) Secret() InputField {
input.kind = inputSecret
// Copy input fields
input.fields = make([]introspect.FieldTag, len(i.fields))
for i, f := range i.fields {
input.fields[i] = f
}
copy(input.fields, i.fields)
return input
}

Expand Down
8 changes: 6 additions & 2 deletions infer/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,14 @@ func (ctx testContext) RuntimeInformation() p.RunInfo {
return p.RunInfo{}
}

type contextKey string

var migrationsKey = contextKey("migrations")

type CustomHydrateFromState[O any] struct{}

func (CustomHydrateFromState[O]) StateMigrations(ctx context.Context) []StateMigrationFunc[O] {
return ctx.Value("migrations").([]StateMigrationFunc[O])
return ctx.Value(migrationsKey).([]StateMigrationFunc[O])
}

func testHydrateFromState[O any](
Expand All @@ -338,7 +342,7 @@ func testHydrateFromState[O any](

ctx := testContext{
//nolint:revive
Context: context.WithValue(context.Background(), "migrations", migrations),
Context: context.WithValue(context.Background(), migrationsKey, migrations),
}

enc, actual, err := hydrateFromState[CustomHydrateFromState[O], struct{}, O](ctx, oldState)
Expand Down
4 changes: 0 additions & 4 deletions infer/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ func TestInvalidOptionalProperty(t *testing.T) {
type invalidContainsOptionalEnum struct {
Foo MyEnum `pulumi:"name,optional"`
}
type validContainsEnum struct {
Foo MyEnum `pulumi:"name"`
}

type testInner struct {
Foo string `pulumi:"foo"`
}
Expand Down
5 changes: 0 additions & 5 deletions middleware/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ type state struct {
innerGetSchema func(ctx context.Context, req p.GetSchemaRequest) (p.GetSchemaResponse, error)
}

func (s *state) invalidateCache() {
s.schema = nil
s.combinedSchema = nil
}

type Options struct {
Metadata
// Resources from which to derive the schema
Expand Down
5 changes: 2 additions & 3 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ func GetSchema(ctx context.Context, name, version string, provider Provider) (sc
if err != nil {
errs.Errors = append(errs.Errors, err)
}
for _, err := range collectingDiag.errs.Errors {
errs.Errors = append(errs.Errors, err)
}
errs.Errors = append(errs.Errors, collectingDiag.errs.Errors...)

spec := schema.PackageSpec{}
if err := errs.ErrorOrNil(); err != nil {
return spec, err
Expand Down

0 comments on commit 2bf8636

Please sign in to comment.