Skip to content

Commit

Permalink
Update Go to 1.23 + golangci-lint to 1.60.2 (#241)
Browse files Browse the repository at this point in the history
Blocking #239
  • Loading branch information
rodaine authored Aug 20, 2024
1 parent 176e0a2 commit d0a45fa
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 48 deletions.
19 changes: 6 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
run:
skip-dirs-use-default: false
linters-settings:
errcheck:
check-type-assertions: true
Expand All @@ -25,35 +23,29 @@ linters:
enable-all: true
disable:
- cyclop # covered by gocyclo
- deadcode # abandoned
- depguard # we can manage dependencies strictly if the need arises in the future
- exhaustivestruct # replaced by exhaustruct
- err113 # internal error causes may be dynamic
- execinquery # deprecated
- exhaustruct # don't _always_ need to exhaustively create struct
- exportloopref # deprecated
- funlen # rely on code review to limit function length
- gocognit # dubious "cognitive overhead" quantification
- gofumpt # prefer standard gofmt
- goerr113 # internal error causes may be dynamic
- goimports # rely on gci instead
- golint # deprecated by Go team
- gomnd # some unnamed constants are okay
- gomoddirectives # we use go modules replacements intentionally
- gomodguard # not compatible with go workspaces
- ifshort # deprecated by author
- 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
- musttag # incompatible with go workspaces
- nlreturn # generous whitespace violates house style
- nonamedreturns # usage of named returns should be selective
- nosnakecase # deprecated in https://github.com/golangci/golangci-lint/pull/3065
- scopelint # deprecated by author
- structcheck # abandoned
- testpackage # internal tests are fine
- varcheck # abandoned
- wrapcheck # don't _always_ need to wrap errors
- wsl # over-generous whitespace violates house style
issues:
exclude-use-default: true
exclude-rules:
# Loosen requirements on test harness
- path: go/v2/internal/cmd/
Expand All @@ -74,6 +66,7 @@ issues:
linters:
- funlen
- maintidx
- mnd
- dupl
- gosmopolitan
# Loosen requirements on tests
Expand Down
8 changes: 4 additions & 4 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ $(BIN)/license-header: $(BIN) Makefile
github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest

$(BIN)/golangci-lint: $(BIN) Makefile
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.2

2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21
go 1.23

use (
./tools
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bufbuild/protovalidate/tools

go 1.21
go 1.23

require (
github.com/bufbuild/protocompile v0.14.0
Expand Down
6 changes: 4 additions & 2 deletions tools/protovalidate-conformance/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -48,8 +49,9 @@ type config struct {
}

func parseFlags() (*config, error) {
const defaultSuiteTimeout = 5 * time.Second
cfg := &config{
suiteTimeout: 5 * time.Second,
suiteTimeout: defaultSuiteTimeout,
}
log.SetFlags(0)

Expand All @@ -76,7 +78,7 @@ func parseFlags() (*config, error) {
args := flag.Args()
if len(args) == 0 {
if !cfg.dump {
return nil, fmt.Errorf("a command must be specified")
return nil, errors.New("a command must be specified")
}
} else {
cfg.cmd = args[0]
Expand Down
22 changes: 11 additions & 11 deletions tools/protovalidate-conformance/internal/results/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s successResult) IsSuccessWith(other Result, options *harness.ResultOption
case successResult:
return s.inner.GetSuccess() == res.inner.GetSuccess()
default:
return !options.Strict && !s.inner.GetSuccess()
return !options.GetStrict() && !s.inner.GetSuccess()
}
}

Expand All @@ -110,11 +110,11 @@ func (v violationsResult) String() string {
_, _ = fmt.Fprintf(bldr, "%d validation error(s)", len(errs))
for i, err := range errs {
forKey := ""
if err.ForKey {
if err.GetForKey() {
forKey = " (key)"
}
_, _ = fmt.Fprintf(bldr, "\n%s %2d. %s%s: %s", resultPadding, i+1, err.FieldPath, forKey, err.ConstraintId)
_, _ = fmt.Fprintf(bldr, "\n%s %s", resultPadding, err.Message)
_, _ = fmt.Fprintf(bldr, "\n%s %2d. %s%s: %s", resultPadding, i+1, err.GetFieldPath(), forKey, err.GetConstraintId())
_, _ = fmt.Fprintf(bldr, "\n%s %s", resultPadding, err.GetMessage())
}
return bldr.String()
}
Expand All @@ -125,21 +125,21 @@ func (v violationsResult) IsSuccessWith(other Result, options *harness.ResultOpt
return res.IsSuccessWith(v, options)
case violationsResult:
got := res.inner.GetValidationError().GetViolations()
if !options.Strict {
if !options.GetStrict() {
return len(got) > 0
}
want := v.inner.GetValidationError().GetViolations()
if len(want) != len(got) {
return false
}
for i := 0; i < len(want); i++ {
matchingField := want[i].FieldPath == got[i].FieldPath && want[i].ForKey == got[i].ForKey
matchingConstraint := want[i].ConstraintId == got[i].ConstraintId
for i := range len(want) {
matchingField := want[i].GetFieldPath() == got[i].GetFieldPath() && want[i].GetForKey() == got[i].GetForKey()
matchingConstraint := want[i].GetConstraintId() == got[i].GetConstraintId()
if !matchingField || !matchingConstraint {
return false
}
if options.StrictMessage && len(want[i].Message) > 0 &&
want[i].Message != got[i].Message {
if options.GetStrictMessage() && len(want[i].GetMessage()) > 0 &&
want[i].GetMessage() != got[i].GetMessage() {
return false
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (c compilationErrorResult) IsSuccessWith(other Result, options *harness.Res
case compilationErrorResult:
return true
case runtimeErrorResult:
return !options.StrictError
return !options.GetStrictError()
default:
return false
}
Expand Down
18 changes: 9 additions & 9 deletions tools/protovalidate-conformance/internal/results/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ type SuiteResults harness.SuiteResults

func (suite *SuiteResults) AddCase(res *harness.CaseResult, verbose bool) {
switch {
case res.Success && !res.ExpectedFailure:
case res.GetSuccess() && !res.GetExpectedFailure():
suite.Successes++
case !res.Success && res.ExpectedFailure:
case !res.GetSuccess() && res.GetExpectedFailure():
suite.ExpectedFailures++
default:
suite.Failures++
}
if verbose || !res.Success {
if verbose || !res.GetSuccess() {
suite.Cases = append(suite.Cases, res)
}
}
Expand All @@ -85,18 +85,18 @@ func (suite *SuiteResults) Print(w io.Writer) {
}

func (suite *SuiteResults) printCase(w io.Writer, testCase *harness.CaseResult) {
res := resultLabel(testCase.Success)
res := resultLabel(testCase.GetSuccess())
_, _ = fmt.Fprintf(w, "%s --- %s: %s\n",
casePadding, res, testCase.Name)
if testCase.Success {
casePadding, res, testCase.GetName())
if testCase.GetSuccess() {
return
}
_, _ = fmt.Fprintf(w, "%sinput: %v\n",
resultPadding, testCase.Input)
resultPadding, testCase.GetInput())
_, _ = fmt.Fprintf(w, "%s want: %v\n",
resultPadding, FromProto(testCase.Wanted))
resultPadding, FromProto(testCase.GetWanted()))
_, _ = fmt.Fprintf(w, "%s got: %v\n",
resultPadding, FromProto(testCase.Got))
resultPadding, FromProto(testCase.GetGot()))
}

func resultLabel(success bool) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *Benchmark) Range(filter *regexp.Regexp, exec func(suiteName string, sui
if filter != nil && !filter.MatchString(suiteName) {
continue
}
for i := 0; i < b.n; i++ {
for i := range b.n {
b.resetTimer()
b.startTimer()
if err := exec(suiteName, suite); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tools/protovalidate-conformance/internal/suites/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s Suite) ProcessResults(
Got: actual.ToProto(),
Input: anyInput,
ExpectedFailure: isSkipped(caseName, skippedCases),
}, options.Verbose)
}, options.GetVerbose())
return nil
})

Expand Down
4 changes: 2 additions & 2 deletions tools/protovalidate-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {

exec := func(suiteName string, suite suites.Suite) error {
req, err := suite.ToRequestProto(cfg.caseFilter)
if err != nil || len(req.Cases) == 0 {
if err != nil || len(req.GetCases()) == 0 {
return err
}

Expand All @@ -64,7 +64,7 @@ func main() {
options,
cfg.expectedFailures[suiteName],
)
res.Fdset = req.Fdset
res.Fdset = req.GetFdset()
resultSet.AddSuite(res, cfg.verbose)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tools/protovalidate-migrate/internal/migrator/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (v *FieldVisitor) buildNameParts(node *ast.OptionNode) (nameParts []ast.Nod
value = node.Val
nameParts = make([]ast.Node, 1, len(node.Name.Parts)*2+1)
nameParts[0] = v.replaceNode(node.Name.Parts[0], "(buf.validate.field)")
for i := 0; i < len(node.Name.Dots); i++ {
for i := range len(node.Name.Dots) {
dot := node.Name.Dots[i]
part := node.Name.Parts[i+1]
switch part.Value() {
Expand Down
3 changes: 2 additions & 1 deletion tools/protovalidate-migrate/internal/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (m *Migrator) OutputMigrate(src os.FileInfo, srcPath, dstPath string) error
}
defer srcFile.Close()

err = os.MkdirAll(filepath.Dir(dstPath), 0o755)
const filePerms = 0o755
err = os.MkdirAll(filepath.Dir(dstPath), filePerms)
if err != nil {
return fmt.Errorf("failed to create output directories for %s: %w", dstPath, err)
}
Expand Down

0 comments on commit d0a45fa

Please sign in to comment.