Bump golangci-lint to v1.59.1 (#3029)

pull/3031/head^2
Juan Calderon-Perez 2024-06-11 02:52:49 -04:00 committed by GitHub
parent e561026384
commit 46fffe4397
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 57 additions and 47 deletions

View File

@ -33,4 +33,4 @@ jobs:
uses: golangci/golangci-lint-action@v6 uses: golangci/golangci-lint-action@v6
with: with:
# NOTE: Keep this in sync with the version from .golangci.yml # NOTE: Keep this in sync with the version from .golangci.yml
version: v1.57.1 version: v1.59.1

View File

@ -236,11 +236,9 @@ linters-settings:
time-layout: false # TODO: Set to true time-layout: false # TODO: Set to true
crypto-hash: true crypto-hash: true
default-rpc-path: true default-rpc-path: true
os-dev-null: true
sql-isolation-level: true sql-isolation-level: true
tls-signature-scheme: true tls-signature-scheme: true
constant-kind: true constant-kind: true
syslog-priority: true
wrapcheck: wrapcheck:
ignorePackageGlobs: ignorePackageGlobs:
@ -256,7 +254,7 @@ issues:
- internal # TODO: Do not ignore interal packages - internal # TODO: Do not ignore interal packages
exclude-rules: exclude-rules:
- linters: - linters:
- goerr113 - err113
text: 'do not define dynamic errors, use wrapped static errors instead*' text: 'do not define dynamic errors, use wrapped static errors instead*'
- path: log/.*\.go - path: log/.*\.go
linters: linters:
@ -265,6 +263,7 @@ issues:
- path: _test\.go - path: _test\.go
linters: linters:
- bodyclose - bodyclose
- err113
# fix: true # fix: true
linters: linters:
@ -286,7 +285,6 @@ linters:
- errchkjson - errchkjson
- errname - errname
- errorlint - errorlint
- execinquery
- exhaustive - exhaustive
# - exhaustivestruct # - exhaustivestruct
# - exhaustruct # - exhaustruct
@ -306,7 +304,7 @@ linters:
# - gocyclo # - gocyclo
# - godot # - godot
# - godox # - godox
- goerr113 - err113
- gofmt - gofmt
- gofumpt - gofumpt
# - goheader # - goheader

View File

@ -30,7 +30,7 @@ format:
## lint: 🚨 Run lint checks ## lint: 🚨 Run lint checks
.PHONY: lint .PHONY: lint
lint: lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1 run ./... go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run ./...
## test: 🚦 Execute all tests ## test: 🚦 Execute all tests
.PHONY: test .PHONY: test

View File

@ -4274,11 +4274,11 @@ func Test_Ctx_BodyStreamWriter(t *testing.T) {
ctx := &fasthttp.RequestCtx{} ctx := &fasthttp.RequestCtx{}
ctx.SetBodyStreamWriter(func(w *bufio.Writer) { ctx.SetBodyStreamWriter(func(w *bufio.Writer) {
fmt.Fprintf(w, "body writer line 1\n") fmt.Fprintf(w, "body writer line 1\n") //nolint: errcheck // It is fine to ignore the error
if err := w.Flush(); err != nil { if err := w.Flush(); err != nil {
t.Errorf("unexpected error: %s", err) t.Errorf("unexpected error: %s", err)
} }
fmt.Fprintf(w, "body writer line 2\n") fmt.Fprintf(w, "body writer line 2\n") //nolint: errcheck // It is fine to ignore the error
}) })
require.True(t, ctx.IsBodyStream()) require.True(t, ctx.IsBodyStream())

View File

@ -351,32 +351,38 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
out = colorable.NewNonColorable(os.Stdout) out = colorable.NewNonColorable(os.Stdout)
} }
_, _ = fmt.Fprintf(out, "%s\n", fmt.Sprintf(figletFiberText, colors.Red+"v"+Version+colors.Reset)) fmt.Fprintf(out, "%s\n", fmt.Sprintf(figletFiberText, colors.Red+"v"+Version+colors.Reset)) //nolint:errcheck,revive // ignore error
_, _ = fmt.Fprintf(out, strings.Repeat("-", 50)+"\n") fmt.Fprintf(out, strings.Repeat("-", 50)+"\n") //nolint:errcheck,revive // ignore error
if host == "0.0.0.0" { if host == "0.0.0.0" {
_, _ = fmt.Fprintf(out, //nolint:errcheck,revive // ignore error
fmt.Fprintf(out,
"%sINFO%s Server started on: \t%s%s://127.0.0.1:%s%s (bound on host 0.0.0.0 and port %s)\n", "%sINFO%s Server started on: \t%s%s://127.0.0.1:%s%s (bound on host 0.0.0.0 and port %s)\n",
colors.Green, colors.Reset, colors.Blue, scheme, port, colors.Reset, port) colors.Green, colors.Reset, colors.Blue, scheme, port, colors.Reset, port)
} else { } else {
_, _ = fmt.Fprintf(out, //nolint:errcheck,revive // ignore error
fmt.Fprintf(out,
"%sINFO%s Server started on: \t%s%s%s\n", "%sINFO%s Server started on: \t%s%s%s\n",
colors.Green, colors.Reset, colors.Blue, fmt.Sprintf("%s://%s:%s", scheme, host, port), colors.Reset) colors.Green, colors.Reset, colors.Blue, fmt.Sprintf("%s://%s:%s", scheme, host, port), colors.Reset)
} }
if app.config.AppName != "" { if app.config.AppName != "" {
_, _ = fmt.Fprintf(out, "%sINFO%s Application name: \t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset) fmt.Fprintf(out, "%sINFO%s Application name: \t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset) //nolint:errcheck,revive // ignore error
} }
_, _ = fmt.Fprintf(out,
//nolint:errcheck,revive // ignore error
fmt.Fprintf(out,
"%sINFO%s Total handlers count: \t%s%s%s\n", "%sINFO%s Total handlers count: \t%s%s%s\n",
colors.Green, colors.Reset, colors.Blue, strconv.Itoa(int(app.handlersCount)), colors.Reset) colors.Green, colors.Reset, colors.Blue, strconv.Itoa(int(app.handlersCount)), colors.Reset)
if isPrefork == "Enabled" { if isPrefork == "Enabled" {
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset) fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset) //nolint:errcheck,revive // ignore error
} else { } else {
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset) fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset) //nolint:errcheck,revive // ignore error
} }
_, _ = fmt.Fprintf(out, "%sINFO%s PID: \t\t\t%s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Total process count: \t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset) fmt.Fprintf(out, "%sINFO%s PID: \t\t\t%s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset) //nolint:errcheck,revive // ignore error
fmt.Fprintf(out, "%sINFO%s Total process count: \t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset) //nolint:errcheck,revive // ignore error
if cfg.EnablePrefork { if cfg.EnablePrefork {
// Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs // Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs
@ -387,27 +393,30 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
} }
} }
_, _ = fmt.Fprintf(out, "%sINFO%s Child PIDs: \t\t%s", colors.Green, colors.Reset, colors.Blue) fmt.Fprintf(out, "%sINFO%s Child PIDs: \t\t%s", colors.Green, colors.Reset, colors.Blue) //nolint:errcheck,revive // ignore error
totalPids := len(pidSlice) totalPids := len(pidSlice)
rowTotalPidCount := 10 rowTotalPidCount := 10
for i := 0; i < totalPids; i += rowTotalPidCount { for i := 0; i < totalPids; i += rowTotalPidCount {
start := i start := i
end := i + rowTotalPidCount end := i + rowTotalPidCount
if end > totalPids { if end > totalPids {
end = totalPids end = totalPids
} }
for n, pid := range pidSlice[start:end] { for n, pid := range pidSlice[start:end] {
_, _ = fmt.Fprintf(out, "%s", pid) fmt.Fprintf(out, "%s", pid) //nolint:errcheck,revive // ignore error
if n+1 != len(pidSlice[start:end]) { if n+1 != len(pidSlice[start:end]) {
_, _ = fmt.Fprintf(out, ", ") fmt.Fprintf(out, ", ") //nolint:errcheck,revive // ignore error
} }
} }
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset) fmt.Fprintf(out, "\n%s", colors.Reset) //nolint:errcheck,revive // ignore error
} }
} }
// add new Line as spacer // add new Line as spacer
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset) fmt.Fprintf(out, "\n%s", colors.Reset) //nolint:errcheck,revive // ignore error
} }
// printRoutesMessage print all routes with method, path, name and handlers // printRoutesMessage print all routes with method, path, name and handlers
@ -449,10 +458,12 @@ func (app *App) printRoutesMessage() {
return routes[i].path < routes[j].path return routes[i].path < routes[j].path
}) })
_, _ = fmt.Fprintf(w, "%smethod\t%s| %spath\t%s| %sname\t%s| %shandlers\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) fmt.Fprintf(w, "%smethod\t%s| %spath\t%s| %sname\t%s| %shandlers\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) //nolint:errcheck,revive // ignore error
_, _ = fmt.Fprintf(w, "%s------\t%s| %s----\t%s| %s----\t%s| %s--------\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) fmt.Fprintf(w, "%s------\t%s| %s----\t%s| %s----\t%s| %s--------\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) //nolint:errcheck,revive // ignore error
for _, route := range routes { for _, route := range routes {
_, _ = fmt.Fprintf(w, "%s%s\t%s| %s%s\t%s| %s%s\t%s| %s%s%s\n", colors.Blue, route.method, colors.White, colors.Green, route.path, colors.White, colors.Cyan, route.name, colors.White, colors.Yellow, route.handlers, colors.Reset) //nolint:errcheck,revive // ignore error
fmt.Fprintf(w, "%s%s\t%s| %s%s\t%s| %s%s\t%s| %s%s%s\n", colors.Blue, route.method, colors.White, colors.Green, route.path, colors.White, colors.Cyan, route.name, colors.White, colors.Yellow, route.handlers, colors.Reset)
} }
_ = w.Flush() //nolint:errcheck // It is fine to ignore the error here _ = w.Flush() //nolint:errcheck // It is fine to ignore the error here

View File

@ -53,9 +53,9 @@ func (l *defaultLogger) privateLogf(lv Level, format string, fmtArgs []any) {
buf.WriteString(level) buf.WriteString(level)
if len(fmtArgs) > 0 { if len(fmtArgs) > 0 {
_, _ = fmt.Fprintf(buf, format, fmtArgs...) _, _ = fmt.Fprintf(buf, format, fmtArgs...) //nolint: errcheck // It is fine to ignore the error
} else { } else {
_, _ = fmt.Fprint(buf, fmtArgs...) _, _ = fmt.Fprint(buf, fmtArgs...) //nolint: errcheck // It is fine to ignore the error
} }
_ = l.stdlog.Output(l.depth, buf.String()) //nolint:errcheck // It is fine to ignore the error _ = l.stdlog.Output(l.depth, buf.String()) //nolint:errcheck // It is fine to ignore the error

View File

@ -13,6 +13,7 @@ import (
"testing" "testing"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
@ -42,31 +43,31 @@ func Test_HTTPHandler(t *testing.T) {
callsCount := 0 callsCount := 0
nethttpH := func(w http.ResponseWriter, r *http.Request) { nethttpH := func(w http.ResponseWriter, r *http.Request) {
callsCount++ callsCount++
require.Equal(t, expectedMethod, r.Method, "Method") assert.Equal(t, expectedMethod, r.Method, "Method")
require.Equal(t, expectedProto, r.Proto, "Proto") assert.Equal(t, expectedProto, r.Proto, "Proto")
require.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor") assert.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
require.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor") assert.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
require.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI") assert.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
require.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength") assert.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
require.Empty(t, r.TransferEncoding, "TransferEncoding") assert.Empty(t, r.TransferEncoding, "TransferEncoding")
require.Equal(t, expectedHost, r.Host, "Host") assert.Equal(t, expectedHost, r.Host, "Host")
require.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr") assert.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
body, err := io.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
require.NoError(t, err) assert.NoError(t, err)
require.Equal(t, expectedBody, string(body), "Body") assert.Equal(t, expectedBody, string(body), "Body")
require.Equal(t, expectedURL, r.URL, "URL") assert.Equal(t, expectedURL, r.URL, "URL")
require.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context") assert.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
for k, expectedV := range expectedHeader { for k, expectedV := range expectedHeader {
v := r.Header.Get(k) v := r.Header.Get(k)
require.Equal(t, expectedV, v, "Header") assert.Equal(t, expectedV, v, "Header")
} }
w.Header().Set("Header1", "value1") w.Header().Set("Header1", "value1")
w.Header().Set("Header2", "value2") w.Header().Set("Header2", "value2")
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "request body is %q", body) fmt.Fprintf(w, "request body is %q", body) //nolint:errcheck // not needed
} }
fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH)) fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH))
fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue) fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)

View File

@ -161,7 +161,7 @@ func writeLog(w io.Writer, msg []byte) {
// Write error to output // Write error to output
if _, err := w.Write([]byte(err.Error())); err != nil { if _, err := w.Write([]byte(err.Error())); err != nil {
// There is something wrong with the given io.Writer // There is something wrong with the given io.Writer
_, _ = fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) _, _ = fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) //nolint: errcheck // It is fine to ignore the error
} }
} }
} }

View File

@ -128,7 +128,7 @@ func Test_Logger_Done(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, fiber.StatusOK, resp.StatusCode) require.Equal(t, fiber.StatusOK, resp.StatusCode)
require.Greater(t, buf.Len(), 0) require.Positive(t, buf.Len(), 0)
} }
// go test -run Test_Logger_ErrorTimeZone // go test -run Test_Logger_ErrorTimeZone
@ -625,7 +625,7 @@ func Test_Logger_ByteSent_Streaming(t *testing.T) {
for { for {
i++ i++
msg := fmt.Sprintf("%d - the time is %v", i, time.Now()) msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
fmt.Fprintf(w, "data: Message: %s\n\n", msg) fmt.Fprintf(w, "data: Message: %s\n\n", msg) //nolint:errcheck // ignore error
err := w.Flush() err := w.Flush()
if err != nil { if err != nil {
break break