diff --git a/.github/workflows/stage-lint.yml b/.github/workflows/stage-lint.yml index 395f0942..278bbae5 100644 --- a/.github/workflows/stage-lint.yml +++ b/.github/workflows/stage-lint.yml @@ -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 diff --git a/.golangci.yaml b/.golangci.yaml index 13b98841..b55ac7c6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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: @@ -16,6 +17,7 @@ linters: - gofmt - revive - gosec + - gosimple - govet - ineffassign - lll @@ -23,8 +25,7 @@ linters: - 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 diff --git a/infer/provider.go b/infer/provider.go index 32cafdc1..dfe80f00 100644 --- a/infer/provider.go +++ b/infer/provider.go @@ -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{ diff --git a/infer/resource.go b/infer/resource.go index f3f26126..f5890a5c 100644 --- a/infer/resource.go +++ b/infer/resource.go @@ -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 { @@ -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 } @@ -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 } diff --git a/infer/resource_test.go b/infer/resource_test.go index 639703c2..7035edc5 100644 --- a/infer/resource_test.go +++ b/infer/resource_test.go @@ -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]( @@ -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) diff --git a/infer/types_test.go b/infer/types_test.go index 3c86998b..00ab58df 100644 --- a/infer/types_test.go +++ b/infer/types_test.go @@ -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"` } diff --git a/middleware/schema/schema.go b/middleware/schema/schema.go index 57f6c2c2..33258013 100644 --- a/middleware/schema/schema.go +++ b/middleware/schema/schema.go @@ -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 diff --git a/provider.go b/provider.go index 9673b4af..9b17ffb8 100644 --- a/provider.go +++ b/provider.go @@ -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