Skip to content

Commit

Permalink
Chore upgrade linter
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
emcfarlane committed Jun 12, 2024
1 parent aba3ff5 commit 3e8cdb4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
12 changes: 3 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion connect_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions duplex_http_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package connect
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package connect

import (
"context"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

var (
//nolint:gochecknoglobals
protocolHeaders = map[string]struct{}{
// HTTP headers.
headerContentType: {},
Expand Down
2 changes: 2 additions & 0 deletions protocol_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
5 changes: 4 additions & 1 deletion protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
}
)
Expand Down

0 comments on commit 3e8cdb4

Please sign in to comment.