Skip to content

Commit d1e4da9

Browse files
Migrate golangci lint (#3097)
Upgrade the linter to V2 and fix various issues discovered by the new version. V1 has some non-determinism with its lints causing PRs to pass the linter and then it fails on master, for example: #3096 The changes are mostly making the imports consistent and removing double-imports. I've also used the chance to add a rule to import some common libraries with the same alias.
1 parent 221bd11 commit d1e4da9

File tree

68 files changed

+732
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+732
-733
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ jobs:
219219
cache-dependency-path: |
220220
**/go.sum
221221
- name: Install golangci-lint
222-
uses: golangci/golangci-lint-action@v6
222+
uses: golangci/golangci-lint-action@v8
223223
with:
224224
skip-cache: true
225-
version: v1.64.7
225+
version: v2.1
226226
- name: Lint
227227
run: make lint
228228
version-check:

.github/workflows/weekly-pulumi-update.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
cache-dependency-path: |
3636
**/go.sum
3737
- name: Install golangci-lint
38-
uses: golangci/golangci-lint-action@v6
38+
uses: golangci/golangci-lint-action@v8
3939
with:
4040
skip-cache: true
41-
version: v1.62
41+
version: v2.1
4242
- name: Update Pulumi/Pulumi
4343
id: gomod
4444
run: >-

.golangci.yml

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,99 @@
1-
run:
2-
timeout: 10m
3-
1+
version: "2"
42
linters:
5-
enable-all: false
63
enable:
74
- durationcheck
8-
- errcheck
9-
- gci
10-
- gofumpt
115
- goheader
126
- goprintffuncname
137
- gosec
14-
- gosimple
15-
- govet
168
- importas
17-
- ineffassign
189
- lll
1910
- misspell
2011
- nakedret
2112
- nolintlint
13+
- paralleltest
2214
- revive
23-
- staticcheck
24-
- tenv
2515
- unconvert
26-
- unused
27-
- paralleltest
2816
- wastedassign
2917
- whitespace
30-
issues:
31-
exclude-rules:
32-
# Exclude some linters from running on tests files.
33-
- path: pkg/pf/tests
34-
linters:
35-
- lll
36-
- paralleltest
37-
- path: pkg/tests
38-
linters:
39-
- lll
40-
- path: pkg/pf/tests
41-
linters:
42-
- lll
43-
- paralleltest
44-
exclude:
45-
- "unused-parameter: parameter"
46-
- "redefines-builtin-id:"
47-
- "exhaustive"
48-
exclude-dirs:
49-
- pkg/tf2pulumi/internal/addrs
50-
- pkg/tf2pulumi/internal/config
51-
- pkg/tf2pulumi/internal/configs
52-
- pkg/vendored
53-
# TODO(https://github.com/pulumi/pulumi-terraform-bridge/issues/2474)
54-
linters-settings:
55-
gci:
56-
sections:
57-
- standard
58-
- default
59-
- prefix(github.com/pulumi/pulumi-terraform-bridge)
60-
skip-generated: true
61-
paralleltest:
62-
ignore-missing-subtests: true
63-
nakedret:
64-
# Make an issue if func has more lines of code than this setting, and it has naked returns.
65-
# Default: 30
66-
max-func-lines: 60
67-
govet:
68-
enable:
69-
- nilness
70-
# Reject comparisons of reflect.Value with DeepEqual or '=='.
71-
- reflectvaluecompare
72-
# Reject sort.Slice calls with a non-slice argument.
73-
- sortslice
74-
# Detect write to struct/arrays by-value that aren't read again.
75-
- unusedwrite
76-
importas:
77-
alias:
78-
- pkg: github.com/pulumi/pulumi/sdk/v3/proto/go
79-
alias: pulumirpc
18+
settings:
19+
govet:
20+
enable:
21+
- nilness
22+
- reflectvaluecompare
23+
- sortslice
24+
- unusedwrite
25+
importas:
26+
alias:
27+
- pkg: github.com/pulumi/pulumi/sdk/v3/proto/go
28+
alias: pulumirpc
29+
- pkg: github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/providerbuilder
30+
alias: pb
31+
- pkg: github.com/hashicorp/terraform-plugin-framework/resource/schema
32+
alias: rschema
33+
- pkg: github.com/hashicorp/terraform-plugin-framework/provider/schema
34+
alias: prschema
35+
- pkg: github.com/hashicorp/terraform-plugin-framework/datasource/schema
36+
alias: dschema
37+
- pkg: github.com/pulumi/pulumi/pkg/v3/codegen/schema
38+
alias: pschema
39+
nakedret:
40+
max-func-lines: 60
41+
paralleltest:
42+
ignore-missing-subtests: true
43+
staticcheck:
44+
checks:
45+
- 'SA1019'
46+
- '-ST1005' # error strings should not be capitalized
47+
exclusions:
48+
generated: lax
49+
presets:
50+
- comments
51+
- common-false-positives
52+
- legacy
53+
- std-error-handling
54+
rules:
55+
- linters:
56+
- lll
57+
- paralleltest
58+
path: pkg/pf/tests
59+
- linters:
60+
- lll
61+
path: pkg/tests
62+
- linters:
63+
- lll
64+
- paralleltest
65+
path: pkg/pf/tests
66+
- path: (.+)\.go$
67+
text: 'unused-parameter: parameter'
68+
- path: (.+)\.go$
69+
text: 'redefines-builtin-id:'
70+
- path: (.+)\.go$
71+
text: exhaustive
72+
paths:
73+
- pkg/tf2pulumi/internal/addrs
74+
- pkg/tf2pulumi/internal/config
75+
- pkg/tf2pulumi/internal/configs
76+
- pkg/vendored
77+
- third_party$
78+
- builtin$
79+
- examples$
80+
formatters:
81+
enable:
82+
- gci
83+
- gofumpt
84+
settings:
85+
gci:
86+
sections:
87+
- standard
88+
- default
89+
- prefix(github.com/pulumi/pulumi-terraform-bridge)
90+
exclusions:
91+
generated: lax
92+
paths:
93+
- pkg/tf2pulumi/internal/addrs
94+
- pkg/tf2pulumi/internal/config
95+
- pkg/tf2pulumi/internal/configs
96+
- pkg/vendored
97+
- third_party$
98+
- builtin$
99+
- examples$

pkg/convert/convert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func arrayPV[T any](topv func(T) resource.PropertyValue) func(data []T) resource
293293

294294
func mapPV[T any](topv func(T) resource.PropertyValue) func(data map[string]T) resource.PropertyValue {
295295
return func(data map[string]T) resource.PropertyValue {
296-
var entries resource.PropertyMap = make(resource.PropertyMap)
296+
entries := make(resource.PropertyMap)
297297
for k, v := range data {
298298
entries[resource.PropertyKey(k)] = topv(v)
299299
}

pkg/convert/infer_object_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestInferType(t *testing.T) {
2929
elem interface{}
3030
}
3131

32-
var res shim.Resource = (&schema.Resource{
32+
res := (&schema.Resource{
3333
Schema: &schema.SchemaMap{
3434
"x": (&schema.Schema{Type: shim.TypeString}).Shim(),
3535
"y": (&schema.Schema{Type: shim.TypeInt, Optional: true}).Shim(),

pkg/pf/internal/check/check_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ func (i testIDResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
374374
resp.Schema = schema.Schema{
375375
Attributes: map[string]schema.Attribute{
376376
"id": schema.StringAttribute{
377-
Computed: i.idSchema.computed,
378-
Required: i.idSchema.required,
379-
Optional: i.idSchema.optional,
377+
Computed: i.computed,
378+
Required: i.required,
379+
Optional: i.optional,
380380
},
381381
},
382382
}

pkg/pf/internal/pfutils/attr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/hashicorp/terraform-plugin-framework/attr"
2121
dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
22-
pschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
22+
prschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
2323
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
2424
"github.com/hashicorp/terraform-plugin-go/tftypes"
2525
)
@@ -53,7 +53,7 @@ type AttrLike interface {
5353
GetType() attr.Type
5454
}
5555

56-
func FromProviderAttribute(x pschema.Attribute) Attr {
56+
func FromProviderAttribute(x prschema.Attribute) Attr {
5757
return FromAttrLike(x)
5858
}
5959

pkg/pf/internal/pfutils/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/hashicorp/terraform-plugin-framework/attr"
2323
dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
24-
pschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
24+
prschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
2525
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
2626
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2727
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
@@ -46,7 +46,7 @@ type BlockLike interface {
4646
Type() attr.Type
4747
}
4848

49-
func FromProviderBlock(x pschema.Block) Block {
49+
func FromProviderBlock(x prschema.Block) Block {
5050
return FromBlockLike(x)
5151
}
5252

pkg/pf/internal/pfutils/proposed_new_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"testing"
2020

21-
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2221
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
2322
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
2423
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -808,7 +807,7 @@ func TestProposedNewWithPortedCases(t *testing.T) {
808807
"bloop": rschema.SetNestedAttribute{
809808
NestedObject: rschema.NestedAttributeObject{
810809
Attributes: map[string]rschema.Attribute{
811-
"blop": schema.StringAttribute{
810+
"blop": rschema.StringAttribute{
812811
Required: true,
813812
},
814813
},

pkg/pf/internal/pfutils/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/hashicorp/terraform-plugin-framework/attr"
2121
dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
22-
pschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
22+
prschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
2323
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
2424
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
2525
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -48,7 +48,7 @@ type Schema interface {
4848
ResourceProtoSchema(ctx context.Context) (*tfprotov6.Schema, error)
4949
}
5050

51-
func FromProviderSchema(x pschema.Schema) Schema {
51+
func FromProviderSchema(x prschema.Schema) Schema {
5252
attrs := convertMap(FromProviderAttribute, x.Attributes)
5353
blocks := convertMap(FromProviderBlock, x.Blocks)
5454
return newSchemaAdapter(x, x.Type(), x.DeprecationMessage, attrs, blocks, nil)

0 commit comments

Comments
 (0)