mirror of https://github.com/gofiber/fiber.git
Bump golangci-lint to v1.62.0 (#3196)
parent
7126e484c9
commit
dcdd2eb2c6
|
@ -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
|
||||
|
|
2
Makefile
2
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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
10
ctx_test.go
10
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")))
|
||||
}
|
||||
|
||||
|
|
|
@ -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]))
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue