Skip to content

Commit 2f6cae9

Browse files
authored
Upgrade go min version and go deps (#56)
Upgrade the Go min version to 1.22. Update golangci-lint to v2 and fix lint warnings.
1 parent 6d2c8b8 commit 2f6cae9

File tree

19 files changed

+972
-2852
lines changed

19 files changed

+972
-2852
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/gen/**/* linguist-generated=true

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
go-version: [1.21.x, 1.22.x, 1.23.x]
18+
go-version: [1.22.x, 1.23.x, 1.24.x]
1919
steps:
2020
- name: Checkout Code
2121
uses: actions/checkout@v4
@@ -32,5 +32,5 @@ jobs:
3232
# conflicting guidance, run only on the most recent supported version.
3333
# For the same reason, only check generated code on the most recent
3434
# supported version.
35-
if: matrix.go-version == '1.23.x'
35+
if: matrix.go-version == '1.24.x'
3636
run: make checkgenerate && make lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/.idea/
12
/.tmp/
23
/internal/cmd/generate-txt-testdata/generate-txt-testdata

.golangci.yml

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,13 @@
1-
linters-settings:
2-
gocyclo:
3-
min-complexity: 15
4-
depguard:
5-
rules:
6-
Main:
7-
files:
8-
- $all
9-
- "!$test"
10-
allow:
11-
- $gostd
12-
- github.com/bufbuild/protoyaml-go/decode
13-
- github.com/bufbuild/protovalidate-go
14-
- buf.build/gen/go/bufbuild/protovalidate
15-
errcheck:
16-
check-type-assertions: true
17-
forbidigo:
18-
forbid:
19-
- '^fmt\.Print'
20-
- '^log\.'
21-
- '^print$'
22-
- '^println$'
23-
- '^panic$'
24-
godox:
25-
# TODO, OPT, etc. comments are fine to commit. Use FIXME comments for
26-
# temporary hacks, and use godox to prevent committing them.
27-
keywords: [FIXME]
28-
varnamelen:
29-
ignore-decls:
30-
- ok bool
31-
- T any
32-
- i int
33-
- wg sync.WaitGroup
1+
version: "2"
342
linters:
35-
enable-all: true
3+
default: all
364
disable:
375
- cyclop # covered by gocyclo
38-
- execinquery # deprecated as of golangci v1.58.0
396
- exhaustive
407
- exhaustruct
41-
- exportloopref # deprecated as of golangci v1.60.2
428
- funlen # rely on code review to limit function length
439
- gochecknoglobals
4410
- gocognit # dubious "cognitive overhead" quantification
45-
- gofumpt # prefer standard gofmt
46-
- goimports # rely on gci instead
47-
- gomnd # some unnamed constants are okay
4811
- ireturn # "accept interfaces, return structs" isn't ironclad
4912
- lll # don't want hard limits for line length
5013
- maintidx # covered by gocyclo
@@ -54,24 +17,68 @@ linters:
5417
- testpackage # internal tests are fine
5518
- wrapcheck # don't _always_ need to wrap errors
5619
- wsl # generous whitespace violates house style
20+
settings:
21+
depguard:
22+
rules:
23+
Main:
24+
files:
25+
- $all
26+
- '!$test'
27+
allow:
28+
- $gostd
29+
- github.com/bufbuild/protoyaml-go/decode
30+
- github.com/bufbuild/protovalidate-go
31+
- buf.build/gen/go/bufbuild/protovalidate
32+
- google.golang.org/protobuf
33+
- gopkg.in/yaml.v3
34+
errcheck:
35+
check-type-assertions: true
36+
forbidigo:
37+
forbid:
38+
- pattern: ^fmt\.Print
39+
- pattern: ^log\.
40+
- pattern: ^print$
41+
- pattern: ^println$
42+
- pattern: ^panic$
43+
gocyclo:
44+
min-complexity: 15
45+
godox:
46+
keywords:
47+
- FIXME
48+
varnamelen:
49+
ignore-decls:
50+
- ok bool
51+
- T any
52+
- i int
53+
- wg sync.WaitGroup
54+
exclusions:
55+
generated: lax
56+
presets:
57+
- comments
58+
- common-false-positives
59+
- legacy
60+
- std-error-handling
61+
rules:
62+
- linters:
63+
- nestif
64+
path: _test.go
65+
- linters:
66+
- depguard
67+
- forbidigo
68+
- revive
69+
path: internal/*
70+
- linters:
71+
- gosec
72+
- gosmopolitan
73+
- prealloc
74+
path: internal/protoyamltest/*
75+
- path: (.+)\.go$
76+
text: do not define dynamic errors.*
5777
issues:
58-
exclude-dirs-use-default: false
59-
exclude:
60-
# Don't ban use of fmt.Errorf to create new errors, but the remaining
61-
# checks from err113 are useful.
62-
- "do not define dynamic errors.*"
63-
# Loosen requirements on tests
64-
exclude-rules:
65-
- path: _test.go
66-
linters:
67-
- nestif
68-
- path: internal/*
69-
linters:
70-
- depguard
71-
- revive
72-
- forbidigo
73-
- path: internal/protoyamltest/*
74-
linters:
75-
- gosec
76-
- gosmopolitan
77-
- prealloc
78+
max-same-issues: 0
79+
formatters:
80+
enable:
81+
- gci
82+
- gofmt
83+
exclusions:
84+
generated: lax

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ build: generate ## Build all packages
3737
.PHONY: lint
3838
lint: $(BIN)/golangci-lint $(BIN)/buf ## Lint
3939
go vet ./...
40+
$(BIN)/golangci-lint fmt --diff
4041
$(BIN)/golangci-lint run
4142
buf lint
4243
buf format -d --exit-code
4344

4445
.PHONY: lintfix
4546
lintfix: $(BIN)/golangci-lint ## Automatically fix some lint errors
47+
$(BIN)/golangci-lint fmt
4648
$(BIN)/golangci-lint run --fix
4749
buf format -w
4850

@@ -79,11 +81,11 @@ $(BIN):
7981
@mkdir -p $(BIN)
8082

8183
$(BIN)/buf: $(BIN) Makefile
82-
go install github.com/bufbuild/buf/cmd/buf@v1.41.0
84+
go install github.com/bufbuild/buf/cmd/buf@v1.51.0
8385

8486
$(BIN)/license-header: $(BIN) Makefile
8587
go install \
86-
github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.41.0
88+
github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.51.0
8789

8890
$(BIN)/golangci-lint: $(BIN) Makefile
89-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
91+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2

buf.gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ managed:
66
except:
77
- buf.build/bufbuild/protovalidate
88
plugins:
9-
- plugin: buf.build/protocolbuffers/go:v1.36.0
9+
- plugin: buf.build/protocolbuffers/go:v1.36.6
1010
out: internal/gen/proto
1111
opt: paths=source_relative

decode.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func (u *unmarshaler) unmarshalInteger(node *yaml.Node, bits int) int64 {
418418

419419
func getFieldNames(fields protoreflect.FieldDescriptors) []protoreflect.Name {
420420
names := make([]protoreflect.Name, 0, fields.Len())
421-
for i := 0; i < fields.Len(); i++ {
421+
for i := range fields.Len() {
422422
names = append(names, fields.Get(i).Name())
423423
if i > 5 {
424424
names = append(names, "...")
@@ -430,7 +430,7 @@ func getFieldNames(fields protoreflect.FieldDescriptors) []protoreflect.Name {
430430

431431
func getEnumValueNames(values protoreflect.EnumValueDescriptors) []protoreflect.Name {
432432
names := make([]protoreflect.Name, 0, values.Len())
433-
for i := 0; i < values.Len(); i++ {
433+
for i := range values.Len() {
434434
names = append(names, values.Get(i).Name())
435435
if i > 5 {
436436
names = append(names, "...")
@@ -549,7 +549,6 @@ func (u *unmarshaler) findField(key string, msgDesc protoreflect.MessageDescript
549549
}
550550
num, err := strconv.ParseInt(key, 10, 32)
551551
if err == nil && num > 0 && num <= math.MaxInt32 {
552-
//nolint:gosec // we just checked on previous line so not overflow risk
553552
if field := fields.ByNumber(protoreflect.FieldNumber(num)); field != nil {
554553
return field, nil
555554
}
@@ -1106,7 +1105,7 @@ func parseFieldPath(path string) ([]string, error) {
11061105
}
11071106

11081107
func parseNextFieldName(path string) (string, string) {
1109-
for i := 0; i < len(path); i++ {
1108+
for i := range len(path) {
11101109
switch path[i] {
11111110
case '.':
11121111
return path[:i], path[i:]
@@ -1124,9 +1123,10 @@ func parseNextValue(path string) (string, string) {
11241123
if path[0] == '"' {
11251124
// Parse string.
11261125
for i := 1; i < len(path); i++ {
1127-
if path[i] == '\\' {
1126+
switch path[i] {
1127+
case '\\':
11281128
i++ // Skip escaped character.
1129-
} else if path[i] == '"' {
1129+
case '"':
11301130
result, err := strconv.Unquote(path[:i+1])
11311131
if err != nil {
11321132
return "", ""
@@ -1137,7 +1137,7 @@ func parseNextValue(path string) (string, string) {
11371137
return path, ""
11381138
}
11391139
// Go til the trailing ']'
1140-
for i := 0; i < len(path); i++ {
1140+
for i := range len(path) {
11411141
if path[i] == ']' {
11421142
return path[:i], path[i+1:]
11431143
}
@@ -1240,7 +1240,7 @@ var unitsNames = []string{"h", "m", "s", "ms", "us", "ns"}
12401240
// parseDurationNest parses a single segment of the duration string.
12411241
func parseDurationNext(str string, totalNanos *big.Int) (string, error) {
12421242
// The next character must be [0-9.]
1243-
if !(str[0] == '.' || '0' <= str[0] && str[0] <= '9') {
1243+
if str[0] != '.' && ('0' > str[0] || str[0] > '9') {
12441244
return "", errors.New("invalid duration")
12451245
}
12461246
var err error

decode_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestParseDuration(t *testing.T) {
7676
{Input: "1.5h1m1.5s1.5h1m1.5s", Expected: &durationpb.Duration{Seconds: 10923}},
7777
{Input: "1h1m1s1ms1us1μs1µs1ns", Expected: &durationpb.Duration{Seconds: 3661, Nanos: 1003001}},
7878
} {
79-
testCase := testCase
8079
t.Run(testCase.Input, func(t *testing.T) {
8180
t.Parallel()
8281
actual, err := ParseDuration(testCase.Input)

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
module buf.build/go/protoyaml
22

3-
go 1.21.1
3+
go 1.22
44

55
require (
6-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.0-20241127180247-a33202765966.1
7-
github.com/bufbuild/protovalidate-go v0.8.0
8-
github.com/google/go-cmp v0.6.0
6+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250307204501-0409229c3780.1
7+
github.com/bufbuild/protovalidate-go v0.9.2
8+
github.com/google/go-cmp v0.7.0
99
github.com/stretchr/testify v1.10.0
10-
google.golang.org/protobuf v1.36.0
10+
google.golang.org/protobuf v1.36.6
1111
gopkg.in/yaml.v3 v3.0.1
1212
)
1313

1414
require (
15-
cel.dev/expr v0.18.0 // indirect
15+
cel.dev/expr v0.19.1 // indirect
1616
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
1717
github.com/davecgh/go-spew v1.1.1 // indirect
18-
github.com/google/cel-go v0.22.1 // indirect
18+
github.com/google/cel-go v0.23.2 // indirect
1919
github.com/pmezard/go-difflib v1.0.0 // indirect
2020
github.com/stoewer/go-strcase v1.3.0 // indirect
2121
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
22-
golang.org/x/text v0.16.0 // indirect
22+
golang.org/x/text v0.21.0 // indirect
2323
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
2424
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
2525
)

go.sum

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.0-20241127180247-a33202765966.1 h1:ntAj16eF7AtUyzOOAFk5gvbAO52QmUKPKk7GmsIEORo=
2-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.0-20241127180247-a33202765966.1/go.mod h1:AxRT+qTj5PJCz2nyQzsR/qxAcveW5USRhJTt/edTO5w=
3-
cel.dev/expr v0.18.0 h1:CJ6drgk+Hf96lkLikr4rFf19WrU0BOWEihyZnI2TAzo=
4-
cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
1+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250130201111-63bb56e20495.1 h1:PDFXknQotVkYBql0DG4ExFM/bemITjovfHwvaUU0IbE=
2+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250130201111-63bb56e20495.1/go.mod h1:avRlCjnFzl98VPaeCtJ24RrV/wwHFzB8sWXhj26+n/U=
3+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250307204501-0409229c3780.1 h1:zgJPqo17m28+Lf5BW4xv3PvU20BnrmTcGYrog22lLIU=
4+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250307204501-0409229c3780.1/go.mod h1:avRlCjnFzl98VPaeCtJ24RrV/wwHFzB8sWXhj26+n/U=
5+
cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4=
6+
cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
57
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
68
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
7-
github.com/bufbuild/protovalidate-go v0.8.0 h1:Xs3kCLCJ4tQiogJ0iOXm+ClKw/KviW3nLAryCGW2I3Y=
8-
github.com/bufbuild/protovalidate-go v0.8.0/go.mod h1:JPWZInGm2y2NBg3vKDKdDIkvDjyLv31J3hLH5GIFc/Q=
9+
github.com/bufbuild/protovalidate-go v0.9.2 h1:dUoPvFimovS74s3eeFNvHQOxFumRPsk390ifkzJCJ/4=
10+
github.com/bufbuild/protovalidate-go v0.9.2/go.mod h1:U9+WHAa6IOrLuqQEWPcxsyE4QEOTwm9fDpVbWXsR0zU=
911
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1012
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1113
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12-
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
13-
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
14-
github.com/google/cel-go v0.22.1 h1:AfVXx3chM2qwoSbM7Da8g8hX8OVSkBFwX+rz2+PcK40=
15-
github.com/google/cel-go v0.22.1/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8=
16-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
17-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
14+
github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8=
15+
github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=
16+
github.com/google/cel-go v0.23.2 h1:UdEe3CvQh3Nv+E/j9r1Y//WO0K0cSyD7/y0bzyLIMI4=
17+
github.com/google/cel-go v0.23.2/go.mod h1:52Pb6QsDbC5kvgxvZhiL9QX1oZEkcUF/ZqaPx1J5Wwo=
18+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
19+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1820
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1921
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2022
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -33,14 +35,14 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
3335
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3436
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
3537
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
36-
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
37-
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
38+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
39+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
3840
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw=
3941
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
4042
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
4143
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
42-
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
43-
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
44+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
45+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
4446
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4547
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
4648
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)