From 3e8cdb40c9dbeda9ec3272af4db0049efa596682 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Wed, 12 Jun 2024 16:14:41 -0400 Subject: [PATCH] Chore upgrade linter Upgrades the linter version to the latest fixing small issues. For readability nolint global directives have been brought inline to avoid misuse. As a small cleanup the buf version has been bumped too. Signed-off-by: Edward McFarlane --- .golangci.yml | 12 +++--------- Makefile | 7 ++++--- connect_ext_test.go | 2 +- duplex_http_call.go | 5 ++--- handler.go | 5 ++--- header.go | 1 + protocol_connect.go | 2 ++ protocol_grpc.go | 5 ++++- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d94bf062..2f9b8162 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -76,12 +76,6 @@ issues: # We need to init a global in-mem HTTP server for testable examples. - linters: [gochecknoinits, gochecknoglobals] path: example_init_test.go - # We need to initialize default grpc User-Agent - - linters: [gochecknoglobals] - path: protocol_grpc.go - # We need to initialize default connect User-Agent - - linters: [gochecknoglobals] - path: protocol_connect.go # We purposefully do an ineffectual assignment for an example. - linters: [ineffassign] path: client_example_test.go @@ -132,6 +126,6 @@ issues: # We want to show examples with http.Get - linters: [noctx] path: internal/memhttp/memhttp_test.go - # We need to initialize a map of all protocol headers - - linters: [gochecknoglobals] - path: header.go + # Allow fmt.Sprintf for cmd/protoc-gen-connect-go for consistency + - linters: [perfsprint] + path: cmd/protoc-gen-connect-go/main.go diff --git a/Makefile b/Makefile index 46a21425..d0315e71 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ export PATH := $(BIN):$(PATH) export GOBIN := $(abspath $(BIN)) COPYRIGHT_YEARS := 2021-2024 LICENSE_IGNORE := --ignore /testdata/ +BUF_VERSION := 1.32.2 .PHONY: help help: ## Describe useful make targets @@ -100,15 +101,15 @@ $(BIN)/protoc-gen-connect-go: $(BIN)/buf: Makefile @mkdir -p $(@D) - go install github.com/bufbuild/buf/cmd/buf@v1.32.0 + go install github.com/bufbuild/buf/cmd/buf@v${BUF_VERSION} $(BIN)/license-header: Makefile @mkdir -p $(@D) - go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.32.0 + go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${BUF_VERSION} $(BIN)/golangci-lint: Makefile @mkdir -p $(@D) - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 $(BIN)/protoc-gen-go: Makefile go.mod @mkdir -p $(@D) diff --git a/connect_ext_test.go b/connect_ext_test.go index 81ea030a..b93c5708 100644 --- a/connect_ext_test.go +++ b/connect_ext_test.go @@ -2969,7 +2969,7 @@ func (d *deflateReader) Reset(reader io.Reader) error { if resetter, ok := d.r.(flate.Resetter); ok { return resetter.Reset(reader, nil) } - return fmt.Errorf("flate reader should implement flate.Resetter") + return errors.New("flate reader should implement flate.Resetter") } var _ connect.Decompressor = (*deflateReader)(nil) diff --git a/duplex_http_call.go b/duplex_http_call.go index a1f8f36a..78bf13c2 100644 --- a/duplex_http_call.go +++ b/duplex_http_call.go @@ -17,7 +17,6 @@ package connect import ( "context" "errors" - "fmt" "io" "net/http" "net/url" @@ -131,7 +130,7 @@ func (d *duplexHTTPCall) sendUnary(payload messagePayload) (int64, error) { // Unary messages are sent as a single HTTP request. We don't need to use a // pipe for the request body and we don't need to send headers separately. if !d.requestSent.CompareAndSwap(false, true) { - return 0, fmt.Errorf("request already sent") + return 0, errors.New("request already sent") } payloadLength := int64(payload.Len()) if payloadLength > 0 { @@ -141,7 +140,7 @@ func (d *duplexHTTPCall) sendUnary(payload messagePayload) (int64, error) { d.request.ContentLength = payloadLength d.request.GetBody = func() (io.ReadCloser, error) { if !payloadBody.Rewind() { - return nil, fmt.Errorf("payload cannot be retried") + return nil, errors.New("payload cannot be retried") } return payloadBody, nil } diff --git a/handler.go b/handler.go index 5eab6c71..9f95627b 100644 --- a/handler.go +++ b/handler.go @@ -16,7 +16,6 @@ package connect import ( "context" - "fmt" "net/http" ) @@ -53,7 +52,7 @@ func NewUnaryHandler[Req, Res any]( if res == nil && err == nil { // This is going to panic during serialization. Debugging is much easier // if we panic here instead, so we can include the procedure name. - panic(fmt.Sprintf("%s returned nil *connect.Response and nil error", procedure)) //nolint: forbidigo + panic(procedure + " returned nil *connect.Response and nil error") //nolint: forbidigo } return res, err }) @@ -107,7 +106,7 @@ func NewClientStreamHandler[Req, Res any]( if res == nil { // This is going to panic during serialization. Debugging is much easier // if we panic here instead, so we can include the procedure name. - panic(fmt.Sprintf("%s returned nil *connect.Response and nil error", procedure)) //nolint: forbidigo + panic(procedure + " returned nil *connect.Response and nil error") //nolint: forbidigo } mergeHeaders(conn.ResponseHeader(), res.header) mergeHeaders(conn.ResponseTrailer(), res.trailer) diff --git a/header.go b/header.go index b3f05432..9958be28 100644 --- a/header.go +++ b/header.go @@ -20,6 +20,7 @@ import ( ) var ( + //nolint:gochecknoglobals protocolHeaders = map[string]struct{}{ // HTTP headers. headerContentType: {}, diff --git a/protocol_connect.go b/protocol_connect.go index bf26f1aa..26f18b06 100644 --- a/protocol_connect.go +++ b/protocol_connect.go @@ -60,6 +60,8 @@ const ( ) // defaultConnectUserAgent returns a User-Agent string similar to those used in gRPC. +// +//nolint:gochecknoglobals var defaultConnectUserAgent = fmt.Sprintf("connect-go/%s (%s)", Version, runtime.Version()) type protocolConnect struct{} diff --git a/protocol_grpc.go b/protocol_grpc.go index 5addf31e..e10ecad7 100644 --- a/protocol_grpc.go +++ b/protocol_grpc.go @@ -63,8 +63,11 @@ var ( // in heterogeneous environments. The following structure is recommended to library developers: // // User-Agent → "grpc-" Language ?("-" Variant) "/" Version ?( " (" *(AdditionalProperty ";") ")" ) + // + //nolint:gochecknoglobals defaultGrpcUserAgent = fmt.Sprintf("grpc-go-connect/%s (%s)", Version, runtime.Version()) - grpcAllowedMethods = map[string]struct{}{ + //nolint:gochecknoglobals + grpcAllowedMethods = map[string]struct{}{ http.MethodPost: {}, } )