From bd32dbab534a761066a2a44fb105b33911caee5c Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Sun, 9 Mar 2025 11:58:30 -0400 Subject: [PATCH] chore: update and appease linters --- Makefile | 7 ++++--- httpbin/handlers_test.go | 2 +- httpbin/helpers.go | 16 ++++++++-------- httpbin/middleware_test.go | 4 ++-- httpbin/websocket/websocket.go | 2 +- internal/testing/assert/assert.go | 10 +++++----- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 7aab102..04a3041 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,10 @@ COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH) TEST_ARGS ?= -race # 3rd party tools -LINT := go run github.com/mgechev/revive@v1.3.4 +FMT := go run mvdan.cc/gofumpt@v0.7.0 +LINT := go run github.com/mgechev/revive@v1.7.0 REFLEX := go run github.com/cespare/reflex@v0.3.1 -STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2023.1.3 +STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2025.1.1 # Host and port to use when running locally via `make run` or `make watch` HOST ?= 127.0.0.1 @@ -66,7 +67,7 @@ testautobahn: .PHONY: autobahntests lint: - test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1) + test -z "$$($(FMT) -d -e .)" || (echo "Error: $(FMT) failed"; $(FMT) -d -e . ; exit 1) go vet ./... $(LINT) -set_exit_status ./... $(STATICCHECK) ./... diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index bfd3360..46b7908 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -3485,7 +3485,7 @@ func newTestServer(handler http.Handler) (*httptest.Server, *http.Client) { srv := httptest.NewServer(handler) client := srv.Client() client.Timeout = 5 * time.Second - client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error { return http.ErrUseLastResponse } return srv, client diff --git a/httpbin/helpers.go b/httpbin/helpers.go index 6890e8f..3f602eb 100644 --- a/httpbin/helpers.go +++ b/httpbin/helpers.go @@ -248,13 +248,13 @@ func parseStatusCode(input string) (int, error) { return parseBoundedStatusCode(input, 100, 599) } -func parseBoundedStatusCode(input string, min, max int) (int, error) { +func parseBoundedStatusCode(input string, minVal, maxVal int) (int, error) { code, err := strconv.Atoi(input) if err != nil { return 0, fmt.Errorf("invalid status code: %q: %w", input, err) } - if code < min || code > max { - return 0, fmt.Errorf("invalid status code: %d not in range [%d, %d]", code, min, max) + if code < minVal || code > maxVal { + return 0, fmt.Errorf("invalid status code: %d not in range [%d, %d]", code, minVal, maxVal) } return code, nil } @@ -276,16 +276,16 @@ func parseDuration(input string) (time.Duration, error) { // parseBoundedDuration parses a time.Duration from user input and ensures that // it is within a given maximum and minimum time -func parseBoundedDuration(input string, min, max time.Duration) (time.Duration, error) { +func parseBoundedDuration(input string, minVal, maxVal time.Duration) (time.Duration, error) { d, err := parseDuration(input) if err != nil { return 0, err } - if d > max { - err = fmt.Errorf("duration %s longer than %s", d, max) - } else if d < min { - err = fmt.Errorf("duration %s shorter than %s", d, min) + if d > maxVal { + err = fmt.Errorf("duration %s longer than %s", d, maxVal) + } else if d < minVal { + err = fmt.Errorf("duration %s shorter than %s", d, minVal) } return d, err } diff --git a/httpbin/middleware_test.go b/httpbin/middleware_test.go index 0610774..85886ae 100644 --- a/httpbin/middleware_test.go +++ b/httpbin/middleware_test.go @@ -17,8 +17,8 @@ func TestTestMode(t *testing.T) { // will cause a panic. This happens most often when we forget to return // early after writing an error response, and has helped identify and fix // some subtly broken error handling. - observer := func(r Result) {} - handler := observe(observer, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + observer := func(_ Result) {} + handler := observe(observer, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusOK) })) diff --git a/httpbin/websocket/websocket.go b/httpbin/websocket/websocket.go index 8a6643b..d462f75 100644 --- a/httpbin/websocket/websocket.go +++ b/httpbin/websocket/websocket.go @@ -75,7 +75,7 @@ type Handler func(ctx context.Context, msg *Message) (*Message, error) // EchoHandler is a Handler that echoes each incoming message back to the // client. -var EchoHandler Handler = func(ctx context.Context, msg *Message) (*Message, error) { +var EchoHandler Handler = func(_ context.Context, msg *Message) (*Message, error) { return msg, nil } diff --git a/internal/testing/assert/assert.go b/internal/testing/assert/assert.go index 08b14b1..de92597 100644 --- a/internal/testing/assert/assert.go +++ b/internal/testing/assert/assert.go @@ -122,19 +122,19 @@ func BodySize(t *testing.T, resp *http.Response, want int) { } // DurationRange asserts that a duration is within a specific range. -func DurationRange(t *testing.T, got, min, max time.Duration) { +func DurationRange(t *testing.T, got, minVal, maxVal time.Duration) { t.Helper() - if got < min || got > max { - t.Fatalf("expected duration between %s and %s, got %s", min, max, got) + if got < minVal || got > maxVal { + t.Fatalf("expected duration between %s and %s, got %s", minVal, maxVal, got) } } -type Number interface { +type number interface { ~int64 | ~float64 } // RoughlyEqual asserts that a numeric value is within a certain tolerance. -func RoughlyEqual[T Number](t *testing.T, got, want T, epsilon T) { +func RoughlyEqual[T number](t *testing.T, got, want T, epsilon T) { t.Helper() if got < want-epsilon || got > want+epsilon { t.Fatalf("expected value between %v and %v, got %v", want-epsilon, want+epsilon, got)