Skip to content

Commit

Permalink
Enable linters for more directories (#2635)
Browse files Browse the repository at this point in the history
This enables the golangci-lint linters for more directories, notably
`pkg/pf` which wasn't linted before

fixes #2474
  • Loading branch information
VenelinMartinov authored Nov 19, 2024
1 parent 9f433fd commit adb0275
Show file tree
Hide file tree
Showing 130 changed files with 548 additions and 474 deletions.
21 changes: 14 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ linters:
- wastedassign
- whitespace
issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: pkg/pf/tests
linters:
- lll
- paralleltest
- path: pkg/tests
linters:
- lll
- paralleltest
- path: pkg/pf/tests
linters:
- lll
- paralleltest
exclude:
- "unused-parameter: parameter"
- "redefines-builtin-id:"
Expand All @@ -38,13 +52,6 @@ issues:
- pkg/tf2pulumi/internal/configs
- pkg/vendored
# TODO(https://github.com/pulumi/pulumi-terraform-bridge/issues/2474)
- pkg/pf/tests
- pkg/tests
- pkg/x/testing
- pkg/x/muxer/tests
- pf
- x/muxer
- testing
linters-settings:
gci:
sections:
Expand Down
16 changes: 8 additions & 8 deletions pkg/pf/internal/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (m *mockSchema) Computed() bool {
}

func TestIsInputProperty(t *testing.T) {
t.Parallel()
t.Parallel()
tests := []struct {
name string
schema shim.Schema
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestIsInputProperty(t *testing.T) {
}

func TestMissingIDProperty(t *testing.T) {
t.Parallel()
t.Parallel()
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{missingID: true}),
})
Expand All @@ -108,7 +108,7 @@ func TestMissingIDProperty(t *testing.T) {
}

func TestMissingIDWithOverride(t *testing.T) {
t.Parallel()
t.Parallel()
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{missingID: true}),
Resources: map[string]*tfbridge.ResourceInfo{
Expand All @@ -123,7 +123,7 @@ func TestMissingIDWithOverride(t *testing.T) {
}

func TestMissingIDUnmapped(t *testing.T) {
t.Parallel()
t.Parallel()
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{missingID: true}),
IgnoreMappings: []string{"test_res"},
Expand All @@ -134,7 +134,7 @@ func TestMissingIDUnmapped(t *testing.T) {
}

func TestSensitiveID(t *testing.T) {
t.Parallel()
t.Parallel()
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{sensitiveID: true}),
})
Expand All @@ -145,7 +145,7 @@ func TestSensitiveID(t *testing.T) {
}

func TestSensitiveIDWithOverride(t *testing.T) {
t.Parallel()
t.Parallel()
t.Run("false", func(t *testing.T) {
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(testProvider{sensitiveID: true}),
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestSensitiveIDWithOverride(t *testing.T) {
}

func TestInvalidInputID(t *testing.T) {
t.Parallel()
t.Parallel()
tests := []struct {
name string
idSchema idSchema
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestInvalidInputID(t *testing.T) {
}

func TestMuxedProvider(t *testing.T) {
t.Parallel()
t.Parallel()
stderr, err := test(t, tfbridge.ProviderInfo{
P: pfbridge.MuxShimWithPF(context.Background(),
sdkv2.NewProvider(testSDKv2Provider()),
Expand Down
1 change: 1 addition & 0 deletions pkg/pf/internal/check/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (err errWrongIDType) Error() string {
type errMissingIDAttribute struct{}

func (errMissingIDAttribute) Error() string {
//nolint:lll
return `no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID to a valid field on the upstream resource`
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/pf/internal/check/not_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func notSupported(sink diag.Sink, prov tfbridge.ProviderInfo, isPFResource, isPF
" pf/tfbridge.ShimProvider or pf/tfbridge.ShimProviderWithContext.\nMuxed SDK and" +
" Plugin Framework based providers must have ProviderInfo.P be created from" +
" pf/tfbridge.MuxShimWithPF or pf/tfbridgepf/tfbridge.MuxShimWithDisjointgPF."
u.warn(warning)
u.warnf(warning)
}

if prov.Resources != nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ type notSupportedUtil struct {
sink diag.Sink
}

func (u *notSupportedUtil) warn(format string, arg ...interface{}) {
func (u *notSupportedUtil) warnf(format string, arg ...interface{}) {
u.sink.Warningf(&diag.Diag{Message: format}, arg...)
}

Expand All @@ -92,7 +92,7 @@ func (u *notSupportedUtil) assertIsZero(path string, shouldBeZero interface{}) {
if va.IsZero() {
return
}
u.warn("%s received a non-zero custom value %v that is being ignored."+
u.warnf("%s received a non-zero custom value %v that is being ignored."+
" Plugin Framework based providers do not yet support this feature.",
path, shouldBeZero)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pf/internal/check/not_supported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestZeroRecognizer(t *testing.T) {
t.Parallel()
t.Parallel()
var stdout bytes.Buffer
var stderr bytes.Buffer
u := &notSupportedUtil{
Expand Down
3 changes: 2 additions & 1 deletion pkg/pf/internal/configencoding/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func (p *provider[T]) CheckConfigWithContext(

func (p *provider[T]) DiffConfigWithContext(
ctx context.Context, urn resource.URN, oldInputs, olds, news resource.PropertyMap,
allowUnknowns bool, ignoreChanges []string) (plugin.DiffResult, error) {
allowUnknowns bool, ignoreChanges []string,
) (plugin.DiffResult, error) {
encoding := p.GetConfigEncoding(ctx)
oldInputs, err := encoding.UnfoldProperties(oldInputs)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/pf/internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func getDefaultValue(
for _, n := range defaultInfo.EnvVars {
// Following code in v3/tfbridge, ignoring set but empty env vars.
if str, ok := os.LookupEnv(n); ok && str != "" {

v, err := parseValueFromEnv(fieldSchema, str)
if err != nil {
msg := fmt.Errorf("Cannot parse the value of environment variable '%s'"+
Expand Down
1 change: 0 additions & 1 deletion pkg/pf/internal/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,4 @@ func TestApplyDefaultInfoValues(t *testing.T) {
assert.Equal(t, tc.expected, actual)
})
}

}
2 changes: 0 additions & 2 deletions pkg/pf/internal/muxer/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (m *ProviderShim) ResourceIsPF(token string) bool {
}
_, ok := p.(pf.ShimProvider)
return ok

}
return false
}
Expand All @@ -114,7 +113,6 @@ func (m *ProviderShim) DataSourceIsPF(token string) bool {
}
_, ok := p.(pf.ShimProvider)
return ok

}
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pf/internal/muxer/union_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func TestUnionMap(t *testing.T) {
t.Parallel()
t.Parallel()
m1 := testMap{
"one": "n1",
"two": "n2",
Expand Down
3 changes: 2 additions & 1 deletion pkg/pf/internal/pfutils/eq.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func NonComputedEq(schema tftypes.AttributePathStepper) Eq {
}

func replaceComputedAttributesWithNull(schema tftypes.AttributePathStepper,
offset *tftypes.AttributePath, val tftypes.Value) (tftypes.Value, error) {
offset *tftypes.AttributePath, val tftypes.Value,
) (tftypes.Value, error) {
return tftypes.Transform(val, func(p *tftypes.AttributePath, v tftypes.Value) (tftypes.Value, error) {
realPath := joinPaths(offset, p)
if ab, err := LookupTerraformPath(schema, realPath); err == nil && ab.IsAttr && ab.Attr.IsComputed() {
Expand Down
7 changes: 3 additions & 4 deletions pkg/pf/internal/pfutils/proposed_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type runtimeSchemaAdapter struct{ Schema }
func (runtimeSchemaAdapter) Shim() shim.SchemaMap { panic("UNIMPLEMENTED") }

func TestComputedOptionalBecomingUnknown(t *testing.T) {
t.Parallel()
t.Parallel()
schema := rschema.Schema{Attributes: map[string]rschema.Attribute{
"foo": rschema.SingleNestedAttribute{
Attributes: map[string]rschema.Attribute{
Expand All @@ -65,7 +65,7 @@ func TestComputedOptionalBecomingUnknown(t *testing.T) {
//
// https://github.com/hashicorp/terraform/blob/v1.3.6/internal/plans/objchange/objchange.go
func TestProposedNewBaseCases(t *testing.T) {
t.Parallel()
t.Parallel()
schema := rschema.Schema{Attributes: map[string]rschema.Attribute{
"foo": rschema.StringAttribute{
Optional: true,
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestProposedNewBaseCases(t *testing.T) {
//
// https://github.com/hashicorp/terraform/blob/v1.3.6/internal/plans/objchange/objchange_test.go#L12
func TestProposedNewWithPortedCases(t *testing.T) {
t.Parallel()
t.Parallel()
testAttributes := map[string]rschema.Attribute{
"optional": rschema.StringAttribute{
Optional: true,
Expand All @@ -241,7 +241,6 @@ func TestProposedNewWithPortedCases(t *testing.T) {
}

tests := map[string]testcase{

"empty": {
runtimeSchemaAdapter{
FromResourceSchema(rschema.Schema{Attributes: map[string]rschema.Attribute{}}),
Expand Down
1 change: 0 additions & 1 deletion pkg/pf/internal/plugin/provider_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func (prov *provider) Invoke(
) (plugin.InvokeResponse, error) {
p, f, err := prov.ProviderWithContext.InvokeWithContext(ctx, req.Tok, req.Args)
return plugin.InvokeResponse{Properties: p, Failures: f}, err

}

func (prov *provider) StreamInvoke(
Expand Down
4 changes: 3 additions & 1 deletion pkg/pf/internal/schemashim/attr_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ func (s *attrSchema) Required() bool {
func (*attrSchema) Default() interface{} {
panic("Default() should not be called during schema generation")
}

func (*attrSchema) DefaultFunc() shim.SchemaDefaultFunc {
panic("DefaultFunc() should not be called during schema generation")
}

func (*attrSchema) DefaultValue() (interface{}, error) {
// DefaultValue() should not be called by tfgen, but it currently may be called by ExtractInputsFromOutputs, so
// returning nil is better than a panic.
Expand Down Expand Up @@ -118,8 +120,8 @@ func (*attrSchema) MinItems() int {

func (*attrSchema) ConflictsWith() []string {
panic("ConflictsWith() should not be called during schema generation")

}

func (*attrSchema) ExactlyOneOf() []string {
panic("ExactlyOneOf() should not be called during schema generation")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/pf/internal/schemashim/block_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (s *blockSchema) Description() string {

// Needs to return a shim.Schema, a shim.Resource, or nil. See docstring on shim.Schema.Elem().
func (s *blockSchema) Elem() interface{} {

asObjectType := func(typ any) (shim.Resource, bool) {
if tt, ok := typ.(basetypes.ObjectTypable); ok {
var res shim.Resource = newObjectPseudoResource(tt,
Expand Down
3 changes: 1 addition & 2 deletions pkg/pf/internal/schemashim/custom_object_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestCustomObject(t *testing.T) {
t.Parallel()
t.Parallel()
ctx := context.Background()

obj := newObjectPseudoResource(NewObjectTypeOf[SomeType](ctx), nil, nil)
Expand Down Expand Up @@ -105,7 +105,6 @@ func (t objectTypeOf[T]) ValueFromObject(

func (t objectTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
attrValue, err := t.ObjectType.ValueFromTerraform(ctx, in)

if err != nil {
return nil, err
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/pf/internal/schemashim/custom_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// This example is taken from aws:resourceexplorer/index:Index "timeouts" property.
func TestCustomTypeEmbeddingObjectType(t *testing.T) {
t.Parallel()
t.Parallel()
type timeoutsType struct {
basetypes.ObjectType
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCustomTypeEmbeddingObjectType(t *testing.T) {
}

func TestCustomListType(t *testing.T) {
t.Parallel()
t.Parallel()
ctx := context.Background()

raw := schema.ListNestedBlock{
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestCustomListType(t *testing.T) {
}

func TestCustomListAttribute(t *testing.T) {
t.Parallel()
t.Parallel()
ctx := context.Background()

raw := schema.ListNestedAttribute{
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestCustomListAttribute(t *testing.T) {
}

func TestCustomSetType(t *testing.T) {
t.Parallel()
t.Parallel()
ctx := context.Background()

raw := schema.SetNestedBlock{
Expand Down Expand Up @@ -160,9 +160,7 @@ type setNestedObjectTypeOf[T any] struct {
basetypes.SetType
}

var (
_ basetypes.ListTypable = (*listNestedObjectTypeOf[struct{}])(nil)
)
var _ basetypes.ListTypable = (*listNestedObjectTypeOf[struct{}])(nil)

func newListNestedObjectTypeOf[T any](ctx context.Context, elemType attr.Type) listNestedObjectTypeOf[T] {
return listNestedObjectTypeOf[T]{basetypes.ListType{ElemType: elemType}}
Expand Down
6 changes: 4 additions & 2 deletions pkg/pf/internal/schemashim/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ func (*schemaOnlyDataSource) Timeouts() *shim.ResourceTimeout {
}

func (*schemaOnlyDataSource) InstanceState(id string, object,
meta map[string]interface{}) (shim.InstanceState, error) {
meta map[string]interface{},
) (shim.InstanceState, error) {
panic("schemaOnlyDataSource does not implement runtime operation InstanceState")
}

func (*schemaOnlyDataSource) DecodeTimeouts(
config shim.ResourceConfig) (*shim.ResourceTimeout, error) {
config shim.ResourceConfig,
) (*shim.ResourceTimeout, error) {
panic("schemaOnlyDataSource does not implement runtime operation DecodeTimeouts")
}
Loading

0 comments on commit adb0275

Please sign in to comment.