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

Update to go1.21 and golangci 1.60.0, test with go1.23 #330

Merged
merged 1 commit into from
Aug 16, 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.20.x,1.21.x,1.22.x]
go-version: [1.21.x,1.22.x,1.23.x]
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -35,12 +35,12 @@ jobs:
run: make test
- name: Benchmarks
# no need to run benchmarks for every Go version
if: matrix.go-version == '1.22.x'
if: matrix.go-version == '1.23.x'
run: make benchmarks
- name: Lint
# Often, lint & gofmt guidelines depend on the Go version. To prevent
# conflicting guidance, run only on the most recent supported version.
# For the same reason, only check generated code on the most recent
# supported version.
if: matrix.go-version == '1.22.x'
if: matrix.go-version == '1.23.x'
run: make checkgenerate lint
23 changes: 7 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
run:
skip-dirs-use-default: false
skip-files:
- ".*\\.y\\.go$"
linters-settings:
errcheck:
check-type-assertions: true
Expand Down Expand Up @@ -51,7 +47,7 @@ linters:
- gochecknoinits
- goconst
- gocyclo
- goerr113
- err113
- interfacebloat
- nestif
- nilerr
Expand All @@ -61,37 +57,32 @@ linters:
- varnamelen
# Other disabled linters
- cyclop # covered by gocyclo
- deadcode # deprecated by author
- exhaustivestruct # replaced by exhaustruct
- execinquery # deprecated in golangci v1.58.0
- funlen # rely on code review to limit function length
- gocognit # dubious "cognitive overhead" quantification
- gofumpt # prefer standard gofmt
- golint # deprecated by Go team
- gomnd # some unnamed constants are okay
- ifshort # deprecated by author
- inamedparam # named params in interface signatures are not always necessary
- interfacer # deprecated by author
- ireturn # "accept interfaces, return structs" isn't ironclad
- lll # don't want hard limits for line length
- maintidx # covered by gocyclo
- maligned # readability trumps efficient struct packing
- mnd # some unnamed constants are okay
- nlreturn # generous whitespace violates house style
- nosnakecase # deprecated in https://github.com/golangci/golangci-lint/pull/3065
- protogetter # lots of false positives: can't use getter to check if field is present
- rowserrcheck # no SQL code in protocompile
- scopelint # deprecated by author
- sqlclosecheck # no SQL code in protocompile
- structcheck # deprecated by author
- testpackage # internal tests are fine
- varcheck # deprecated by author
- wastedassign # not supported with generics
- wrapcheck # don't _always_ need to wrap errors
- wsl # generous whitespace violates house style
issues:
exclude-dirs-use-default: false
exclude-files:
- ".*\\.y\\.go$"
exclude:
# Don't ban use of fmt.Errorf to create new errors, but the remaining
# checks from err113 are useful.
- "err113: do not define dynamic errors.*"
- "do not define dynamic errors.*"
exclude-rules:
# Benchmarks can't be run in parallel
- path: benchmark_test\.go
Expand Down
2 changes: 1 addition & 1 deletion ast/ast_roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func TestASTRoundTrips(t *testing.T) {
t.Parallel()
err := filepath.Walk("../internal/testdata", func(path string, info os.FileInfo, err error) error {
err := filepath.Walk("../internal/testdata", func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion ast/items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestItems(t *testing.T) {
t.Parallel()
err := filepath.Walk("../internal/testdata", func(path string, info os.FileInfo, err error) error {
err := filepath.Walk("../internal/testdata", func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
24 changes: 12 additions & 12 deletions ast/ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,24 @@ type RangeNode struct {
// then so must be exactly one of end or max. If max is non-nil, it indicates a
// "100 to max" style range. But if end is non-nil, the end of the range is a
// literal, such as "100 to 200".
func NewRangeNode(start IntValueNode, to *KeywordNode, end IntValueNode, max *KeywordNode) *RangeNode {
func NewRangeNode(start IntValueNode, to *KeywordNode, end IntValueNode, maxEnd *KeywordNode) *RangeNode {
if start == nil {
panic("start is nil")
}
numChildren := 1
if to != nil {
if end == nil && max == nil {
if end == nil && maxEnd == nil {
panic("to is not nil, but end and max both are")
}
if end != nil && max != nil {
if end != nil && maxEnd != nil {
panic("end and max cannot be both non-nil")
}
numChildren = 3
} else {
if end != nil {
panic("to is nil, but end is not")
}
if max != nil {
if maxEnd != nil {
panic("to is nil, but max is not")
}
}
Expand All @@ -157,7 +157,7 @@ func NewRangeNode(start IntValueNode, to *KeywordNode, end IntValueNode, max *Ke
if end != nil {
children = append(children, end)
} else {
children = append(children, max)
children = append(children, maxEnd)
}
}
return &RangeNode{
Expand All @@ -167,7 +167,7 @@ func NewRangeNode(start IntValueNode, to *KeywordNode, end IntValueNode, max *Ke
StartVal: start,
To: to,
EndVal: end,
Max: max,
Max: maxEnd,
}
}

Expand All @@ -189,8 +189,8 @@ func (n *RangeNode) StartValue() interface{} {
return n.StartVal.Value()
}

func (n *RangeNode) StartValueAsInt32(min, max int32) (int32, bool) {
return AsInt32(n.StartVal, min, max)
func (n *RangeNode) StartValueAsInt32(minVal, maxVal int32) (int32, bool) {
return AsInt32(n.StartVal, minVal, maxVal)
}

func (n *RangeNode) EndValue() interface{} {
Expand All @@ -200,14 +200,14 @@ func (n *RangeNode) EndValue() interface{} {
return n.EndVal.Value()
}

func (n *RangeNode) EndValueAsInt32(min, max int32) (int32, bool) {
func (n *RangeNode) EndValueAsInt32(minVal, maxVal int32) (int32, bool) {
if n.Max != nil {
return max, true
return maxVal, true
}
if n.EndVal == nil {
return n.StartValueAsInt32(min, max)
return n.StartValueAsInt32(minVal, maxVal)
}
return AsInt32(n.EndVal, min, max)
return AsInt32(n.EndVal, minVal, maxVal)
}

// ReservedNode represents reserved declaration, which can be used to reserve
Expand Down
2 changes: 1 addition & 1 deletion ast/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestTokens(t *testing.T) {
t.Parallel()
err := filepath.Walk("../internal/testdata", func(path string, info os.FileInfo, err error) error {
err := filepath.Walk("../internal/testdata", func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions ast/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ type IntValueNode interface {

// AsInt32 range checks the given int value and returns its value is
// in the range or 0, false if it is outside the range.
func AsInt32(n IntValueNode, min, max int32) (int32, bool) {
func AsInt32(n IntValueNode, minVal, maxVal int32) (int32, bool) {
i, ok := n.AsInt64()
if !ok {
return 0, false
}
if i < int64(min) || i > int64(max) {
if i < int64(minVal) || i > int64(maxVal) {
return 0, false
}
return int32(i), true
Expand Down
2 changes: 1 addition & 1 deletion ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (t *AncestorTracker) AsWalkOptions() []WalkOption {
t.ancestors = append(t.ancestors, n)
return nil
}),
WithAfter(func(n Node) error {
WithAfter(func(_ Node) error {
t.ancestors = t.ancestors[:len(t.ancestors)-1]
return nil
}),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bufbuild/protocompile

go 1.20
go 1.21

require (
github.com/google/go-cmp v0.6.0
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.20
go 1.21

use (
.
Expand Down
2 changes: 1 addition & 1 deletion internal/benchmarks/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestMain(m *testing.M) {
return
}

googleapisDir = filepath.Join(dir, fmt.Sprintf("googleapis-%s", googleapisCommit)) + "/"
googleapisDir = filepath.Join(dir, "googleapis-"+googleapisCommit) + "/"
var sourceSize int64
err = filepath.Walk(googleapisDir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/benchmarks/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bufbuild/protocompile/internal/benchmarks

go 1.19
go 1.21

require (
github.com/bufbuild/protocompile v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions internal/editions/editions.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ func asExtensionType(ext protoreflect.ExtensionDescriptor) protoreflect.Extensio
return dynamicpb.NewExtensionType(ext)
}

func computeSupportedEditions(min, max descriptorpb.Edition) map[string]descriptorpb.Edition {
func computeSupportedEditions(minEdition, maxEdition descriptorpb.Edition) map[string]descriptorpb.Edition {
supportedEditions := map[string]descriptorpb.Edition{}
for editionNum := range descriptorpb.Edition_name {
edition := descriptorpb.Edition(editionNum)
if edition >= min && edition <= max {
if edition >= minEdition && edition <= maxEdition {
name := strings.TrimPrefix(edition.String(), "EDITION_")
supportedEditions[name] = edition
}
Expand Down
Loading
Loading