diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index dc04fec67b..2dc54bc585 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -37,4 +37,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: # NOTE: Keep this in sync with the version from .golangci.yml - version: v1.61.0 + version: v1.62.0 diff --git a/Makefile b/Makefile index 33526991a3..87d4b50db5 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ markdown: ## lint: 🚨 Run lint checks .PHONY: lint lint: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 run ./... + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 run ./... ## test: 🚦 Execute all tests .PHONY: test diff --git a/client/hooks_test.go b/client/hooks_test.go index 359e3184d2..8e91392930 100644 --- a/client/hooks_test.go +++ b/client/hooks_test.go @@ -254,7 +254,7 @@ func Test_Parser_Request_Header(t *testing.T) { err := parserRequestHeader(client, req) require.NoError(t, err) - require.Equal(t, []byte(applicationJSON), req.RawRequest.Header.ContentType()) + require.Equal(t, []byte(applicationJSON), req.RawRequest.Header.ContentType()) //nolint:testifylint // test }) t.Run("auto set xml header", func(t *testing.T) { @@ -297,8 +297,8 @@ func Test_Parser_Request_Header(t *testing.T) { err := parserRequestHeader(client, req) require.NoError(t, err) - require.True(t, strings.Contains(string(req.RawRequest.Header.MultipartFormBoundary()), "--FiberFormBoundary")) - require.True(t, strings.Contains(string(req.RawRequest.Header.ContentType()), multipartFormData)) + require.Contains(t, string(req.RawRequest.Header.MultipartFormBoundary()), "--FiberFormBoundary") + require.Contains(t, string(req.RawRequest.Header.ContentType()), multipartFormData) }) t.Run("ua should have default value", func(t *testing.T) { @@ -436,7 +436,7 @@ func Test_Parser_Request_Body(t *testing.T) { err := parserRequestBody(client, req) require.NoError(t, err) - require.Equal(t, []byte("{\"name\":\"foo\"}"), req.RawRequest.Body()) + require.Equal(t, []byte("{\"name\":\"foo\"}"), req.RawRequest.Body()) //nolint:testifylint // test }) t.Run("xml body", func(t *testing.T) { @@ -489,8 +489,8 @@ func Test_Parser_Request_Body(t *testing.T) { err := parserRequestBody(client, req) require.NoError(t, err) - require.True(t, strings.Contains(string(req.RawRequest.Body()), "----FiberFormBoundary")) - require.True(t, strings.Contains(string(req.RawRequest.Body()), "world")) + require.Contains(t, string(req.RawRequest.Body()), "----FiberFormBoundary") + require.Contains(t, string(req.RawRequest.Body()), "world") }) t.Run("file and form data", func(t *testing.T) { @@ -502,9 +502,9 @@ func Test_Parser_Request_Body(t *testing.T) { err := parserRequestBody(client, req) require.NoError(t, err) - require.True(t, strings.Contains(string(req.RawRequest.Body()), "----FiberFormBoundary")) - require.True(t, strings.Contains(string(req.RawRequest.Body()), "world")) - require.True(t, strings.Contains(string(req.RawRequest.Body()), "bar")) + require.Contains(t, string(req.RawRequest.Body()), "----FiberFormBoundary") + require.Contains(t, string(req.RawRequest.Body()), "world") + require.Contains(t, string(req.RawRequest.Body()), "bar") }) t.Run("raw body", func(t *testing.T) { diff --git a/client/response_test.go b/client/response_test.go index ab22ab388a..0d27ee7ed4 100644 --- a/client/response_test.go +++ b/client/response_test.go @@ -375,7 +375,7 @@ func Test_Response_Save(t *testing.T) { data, err := io.ReadAll(file) require.NoError(t, err) - require.Equal(t, "{\"status\":\"success\"}", string(data)) + require.JSONEq(t, "{\"status\":\"success\"}", string(data)) }) t.Run("io.Writer", func(t *testing.T) { @@ -396,7 +396,7 @@ func Test_Response_Save(t *testing.T) { err = resp.Save(buf) require.NoError(t, err) - require.Equal(t, "{\"status\":\"success\"}", buf.String()) + require.JSONEq(t, "{\"status\":\"success\"}", buf.String()) }) t.Run("error type", func(t *testing.T) { diff --git a/ctx_test.go b/ctx_test.go index 3b6b44ebac..a017fae411 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -1189,7 +1189,7 @@ func Test_Ctx_AutoFormat_Struct(t *testing.T) { c.Request().Header.Set(HeaderAccept, MIMEApplicationJSON) err := c.AutoFormat(data) require.NoError(t, err) - require.Equal(t, + require.JSONEq(t, `{"Sender":"Carol","Recipients":["Alice","Bob"],"Urgency":3}`, string(c.Response().Body()), ) @@ -3549,7 +3549,7 @@ func Test_Ctx_JSON(t *testing.T) { "Age": 20, }) require.NoError(t, err) - require.Equal(t, `{"Age":20,"Name":"Grame"}`, string(c.Response().Body())) + require.JSONEq(t, `{"Age":20,"Name":"Grame"}`, string(c.Response().Body())) require.Equal(t, "application/json", string(c.Response().Header.Peek("content-type"))) // Test with ctype @@ -3558,7 +3558,7 @@ func Test_Ctx_JSON(t *testing.T) { "Age": 20, }, "application/problem+json") require.NoError(t, err) - require.Equal(t, `{"Age":20,"Name":"Grame"}`, string(c.Response().Body())) + require.JSONEq(t, `{"Age":20,"Name":"Grame"}`, string(c.Response().Body())) require.Equal(t, "application/problem+json", string(c.Response().Header.Peek("content-type"))) testEmpty := func(v any, r string) { @@ -3612,7 +3612,7 @@ func Benchmark_Ctx_JSON(b *testing.B) { err = c.JSON(data) } require.NoError(b, err) - require.Equal(b, `{"Name":"Grame","Age":20}`, string(c.Response().Body())) + require.JSONEq(b, `{"Name":"Grame","Age":20}`, string(c.Response().Body())) } // go test -run=^$ -bench=Benchmark_Ctx_JSON_Ctype -benchmem -count=4 @@ -3635,7 +3635,7 @@ func Benchmark_Ctx_JSON_Ctype(b *testing.B) { err = c.JSON(data, "application/problem+json") } require.NoError(b, err) - require.Equal(b, `{"Name":"Grame","Age":20}`, string(c.Response().Body())) + require.JSONEq(b, `{"Name":"Grame","Age":20}`, string(c.Response().Body())) require.Equal(b, "application/problem+json", string(c.Response().Header.Peek("content-type"))) } diff --git a/log/default.go b/log/default.go index a835b3b403..9a3c93b1c2 100644 --- a/log/default.go +++ b/log/default.go @@ -93,7 +93,7 @@ func (l *defaultLogger) privateLogw(lv Level, format string, keysAndValues []any if i > 0 || format != "" { buf.WriteByte(' ') } - buf.WriteString(keysAndValues[i].(string)) //nolint:forcetypeassert // Keys must be strings + buf.WriteString(keysAndValues[i].(string)) //nolint:forcetypeassert,errcheck // Keys must be strings buf.WriteByte('=') buf.WriteString(utils.ToString(keysAndValues[i+1])) } diff --git a/middleware/adaptor/adaptor.go b/middleware/adaptor/adaptor.go index 03c6287e6f..867f440adf 100644 --- a/middleware/adaptor/adaptor.go +++ b/middleware/adaptor/adaptor.go @@ -163,7 +163,7 @@ func handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc { } } - if _, _, err := net.SplitHostPort(r.RemoteAddr); err != nil && err.(*net.AddrError).Err == "missing port in address" { //nolint:errorlint, forcetypeassert // overlinting + if _, _, err := net.SplitHostPort(r.RemoteAddr); err != nil && err.(*net.AddrError).Err == "missing port in address" { //nolint:errorlint,forcetypeassert,errcheck // overlinting r.RemoteAddr = net.JoinHostPort(r.RemoteAddr, "80") } diff --git a/middleware/cache/heap.go b/middleware/cache/heap.go index c5715392ef..bba69fe4f5 100644 --- a/middleware/cache/heap.go +++ b/middleware/cache/heap.go @@ -41,7 +41,7 @@ func (h indexedHeap) Swap(i, j int) { } func (h *indexedHeap) Push(x any) { - h.pushInternal(x.(heapEntry)) //nolint:forcetypeassert // Forced type assertion required to implement the heap.Interface interface + h.pushInternal(x.(heapEntry)) //nolint:forcetypeassert,errcheck // Forced type assertion required to implement the heap.Interface interface } func (h *indexedHeap) Pop() any { diff --git a/middleware/cache/manager.go b/middleware/cache/manager.go index 3a796c7758..7d20c0498e 100644 --- a/middleware/cache/manager.go +++ b/middleware/cache/manager.go @@ -50,7 +50,7 @@ func newManager(storage fiber.Storage) *manager { // acquire returns an *entry from the sync.Pool func (m *manager) acquire() *item { - return m.pool.Get().(*item) //nolint:forcetypeassert // We store nothing else in the pool + return m.pool.Get().(*item) //nolint:forcetypeassert,errcheck // We store nothing else in the pool } // release and reset *entry to sync.Pool diff --git a/middleware/limiter/manager.go b/middleware/limiter/manager.go index ecaee7f127..d004acad0e 100644 --- a/middleware/limiter/manager.go +++ b/middleware/limiter/manager.go @@ -45,7 +45,7 @@ func newManager(storage fiber.Storage) *manager { // acquire returns an *entry from the sync.Pool func (m *manager) acquire() *item { - return m.pool.Get().(*item) //nolint:forcetypeassert // We store nothing else in the pool + return m.pool.Get().(*item) //nolint:forcetypeassert,errcheck // We store nothing else in the pool } // release and reset *entry to sync.Pool diff --git a/middleware/logger/default_logger.go b/middleware/logger/default_logger.go index e359bd4a83..369b2c8580 100644 --- a/middleware/logger/default_logger.go +++ b/middleware/logger/default_logger.go @@ -31,7 +31,7 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error { } buf.WriteString( fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+data.ErrPaddingStr+"s %s\n", - data.Timestamp.Load().(string), //nolint:forcetypeassert // Timestamp is always a string + data.Timestamp.Load().(string), //nolint:forcetypeassert,errcheck // Timestamp is always a string statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset, data.Stop.Sub(data.Start), c.IP(), @@ -61,7 +61,7 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error { } // Timestamp - buf.WriteString(data.Timestamp.Load().(string)) //nolint:forcetypeassert // Timestamp is always a string + buf.WriteString(data.Timestamp.Load().(string)) //nolint:forcetypeassert,errcheck // Timestamp is always a string buf.WriteString(" | ") // Status Code with 3 fixed width, right aligned diff --git a/middleware/logger/logger_test.go b/middleware/logger/logger_test.go index 0bc06531c9..46a435ecc9 100644 --- a/middleware/logger/logger_test.go +++ b/middleware/logger/logger_test.go @@ -305,8 +305,7 @@ func Test_Logger_WithLatency(t *testing.T) { require.Equal(t, fiber.StatusOK, resp.StatusCode) // Assert that the log output contains the expected latency value in the current time unit - require.True(t, bytes.HasSuffix(buff.Bytes(), []byte(tu.unit)), - fmt.Sprintf("Expected latency to be in %s, got %s", tu.unit, buff.String())) + require.True(t, bytes.HasSuffix(buff.Bytes(), []byte(tu.unit)), "Expected latency to be in %s, got %s", tu.unit, buff.String()) // Reset the buffer buff.Reset() @@ -350,8 +349,7 @@ func Test_Logger_WithLatency_DefaultFormat(t *testing.T) { // parse out the latency value from the log output latency := bytes.Split(buff.Bytes(), []byte(" | "))[2] // Assert that the latency value is in the current time unit - require.True(t, bytes.HasSuffix(latency, []byte(tu.unit)), - fmt.Sprintf("Expected latency to be in %s, got %s", tu.unit, latency)) + require.True(t, bytes.HasSuffix(latency, []byte(tu.unit)), "Expected latency to be in %s, got %s", tu.unit, latency) // Reset the buffer buff.Reset() diff --git a/middleware/logger/tags.go b/middleware/logger/tags.go index 8baacfdc09..25f1a48ff5 100644 --- a/middleware/logger/tags.go +++ b/middleware/logger/tags.go @@ -200,7 +200,7 @@ func createTagMap(cfg *Config) map[string]LogFunc { return output.WriteString(fmt.Sprintf("%13v", latency)) }, TagTime: func(output Buffer, _ fiber.Ctx, data *Data, _ string) (int, error) { - return output.WriteString(data.Timestamp.Load().(string)) //nolint:forcetypeassert // We always store a string in here + return output.WriteString(data.Timestamp.Load().(string)) //nolint:forcetypeassert,errcheck // We always store a string in here }, } // merge with custom tags from user diff --git a/router.go b/router.go index 27e3bc7e74..2091cfc6cb 100644 --- a/router.go +++ b/router.go @@ -234,7 +234,7 @@ func (app *App) requestHandler(rctx *fasthttp.RequestCtx) { if app.newCtxFunc != nil { _, err = app.nextCustom(c) } else { - _, err = app.next(c.(*DefaultCtx)) + _, err = app.next(c.(*DefaultCtx)) //nolint:errcheck // It is fine to ignore the error here } if err != nil { if catch := c.App().ErrorHandler(c, err); catch != nil {