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

Fix linter deprecation warnings and enhance coverage #241

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

- govet
- ineffassign
- lll
- misspell
- nakedret
- unconvert
- paralleltest
- staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

- 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")
Comment on lines +326 to +328
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly easier to just use an empty struct since you don't need to do anything with it. Zero bytes as a bonus.

var migrationsKey struct{}


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
Loading