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

Chore upgrade linter #751

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -360,7 +360,7 @@
})
t.Run("middleware_errors_unary", func(t *testing.T) {
request := connect.NewRequest(&pingv1.PingRequest{})
request.Header().Set(clientMiddlewareErrorHeader, headerValue)

Check failure on line 363 in connect_ext_test.go

View workflow job for this annotation

GitHub Actions / ci (1.22.x)

const "clientMiddlewareErrorHeader" used as a key at http.Header, but "Connect-Trigger-HTTP-Error" is not canonical, want "Connect-Trigger-Http-Error" (canonicalheader)
_, err := client.Ping(context.Background(), request)
assertIsHTTPMiddlewareError(t, err)
})
Expand Down Expand Up @@ -2969,7 +2969,7 @@
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 @@
)

// 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 Expand Up @@ -1069,7 +1071,7 @@
return &url
}

func (m *connectUnaryRequestMarshaler) writeWithGet(url *url.URL) *Error {

Check failure on line 1074 in protocol_connect.go

View workflow job for this annotation

GitHub Actions / ci (1.22.x)

(*connectUnaryRequestMarshaler).writeWithGet - result 0 (*connectrpc.com/connect.Error) is always nil (unparam)
delHeaderCanonical(m.header, connectHeaderProtocolVersion)
delHeaderCanonical(m.header, headerContentType)
delHeaderCanonical(m.header, headerContentEncoding)
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
Loading