Skip to content

Commit

Permalink
Bump golangci-lint to v1.59.1 (gofiber#3029)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby authored Jun 11, 2024
1 parent e561026 commit 46fffe4
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
# NOTE: Keep this in sync with the version from .golangci.yml
version: v1.57.1
version: v1.59.1
8 changes: 3 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ linters-settings:
time-layout: false # TODO: Set to true
crypto-hash: true
default-rpc-path: true
os-dev-null: true
sql-isolation-level: true
tls-signature-scheme: true
constant-kind: true
syslog-priority: true

wrapcheck:
ignorePackageGlobs:
Expand All @@ -256,7 +254,7 @@ issues:
- internal # TODO: Do not ignore interal packages
exclude-rules:
- linters:
- goerr113
- err113
text: 'do not define dynamic errors, use wrapped static errors instead*'
- path: log/.*\.go
linters:
Expand All @@ -265,6 +263,7 @@ issues:
- path: _test\.go
linters:
- bodyclose
- err113
# fix: true

linters:
Expand All @@ -286,7 +285,6 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
# - exhaustivestruct
# - exhaustruct
Expand All @@ -306,7 +304,7 @@ linters:
# - gocyclo
# - godot
# - godox
- goerr113
- err113
- gofmt
- gofumpt
# - goheader
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ format:
## lint: 🚨 Run lint checks
.PHONY: 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
.PHONY: test
Expand Down
4 changes: 2 additions & 2 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4274,11 +4274,11 @@ func Test_Ctx_BodyStreamWriter(t *testing.T) {
ctx := &fasthttp.RequestCtx{}

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 {
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())
Expand Down
47 changes: 29 additions & 18 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,32 +351,38 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
out = colorable.NewNonColorable(os.Stdout)
}

_, _ = fmt.Fprintf(out, "%s\n", fmt.Sprintf(figletFiberText, colors.Red+"v"+Version+colors.Reset))
_, _ = fmt.Fprintf(out, strings.Repeat("-", 50)+"\n")
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") //nolint:errcheck,revive // ignore error

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",
colors.Green, colors.Reset, colors.Blue, scheme, port, colors.Reset, port)
} else {
_, _ = fmt.Fprintf(out,
//nolint:errcheck,revive // ignore error
fmt.Fprintf(out,
"%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)
}

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",
colors.Green, colors.Reset, colors.Blue, strconv.Itoa(int(app.handlersCount)), colors.Reset)

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 {
_, _ = 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 {
// Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs
Expand All @@ -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)
rowTotalPidCount := 10

for i := 0; i < totalPids; i += rowTotalPidCount {
start := i
end := i + rowTotalPidCount

if end > totalPids {
end = totalPids
}

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]) {
_, _ = 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
_, _ = 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
Expand Down Expand Up @@ -449,10 +458,12 @@ func (app *App) printRoutesMessage() {
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, "%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, "%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) //nolint:errcheck,revive // ignore error

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
Expand Down
4 changes: 2 additions & 2 deletions log/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (l *defaultLogger) privateLogf(lv Level, format string, fmtArgs []any) {
buf.WriteString(level)

if len(fmtArgs) > 0 {
_, _ = fmt.Fprintf(buf, format, fmtArgs...)
_, _ = fmt.Fprintf(buf, format, fmtArgs...) //nolint: errcheck // It is fine to ignore the error
} 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
Expand Down
31 changes: 16 additions & 15 deletions middleware/adaptor/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"github.com/gofiber/fiber/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
)
Expand Down Expand Up @@ -42,31 +43,31 @@ func Test_HTTPHandler(t *testing.T) {
callsCount := 0
nethttpH := func(w http.ResponseWriter, r *http.Request) {
callsCount++
require.Equal(t, expectedMethod, r.Method, "Method")
require.Equal(t, expectedProto, r.Proto, "Proto")
require.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
require.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
require.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
require.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
require.Empty(t, r.TransferEncoding, "TransferEncoding")
require.Equal(t, expectedHost, r.Host, "Host")
require.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
assert.Equal(t, expectedMethod, r.Method, "Method")
assert.Equal(t, expectedProto, r.Proto, "Proto")
assert.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
assert.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
assert.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
assert.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
assert.Empty(t, r.TransferEncoding, "TransferEncoding")
assert.Equal(t, expectedHost, r.Host, "Host")
assert.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")

body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.Equal(t, expectedBody, string(body), "Body")
require.Equal(t, expectedURL, r.URL, "URL")
require.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
assert.NoError(t, err)
assert.Equal(t, expectedBody, string(body), "Body")
assert.Equal(t, expectedURL, r.URL, "URL")
assert.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")

for k, expectedV := range expectedHeader {
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("Header2", "value2")
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 = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)
Expand Down
2 changes: 1 addition & 1 deletion middleware/logger/default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func writeLog(w io.Writer, msg []byte) {
// Write error to output
if _, err := w.Write([]byte(err.Error())); err != nil {
// 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
}
}
}
4 changes: 2 additions & 2 deletions middleware/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Test_Logger_Done(t *testing.T) {

require.NoError(t, err)
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
Expand Down Expand Up @@ -625,7 +625,7 @@ func Test_Logger_ByteSent_Streaming(t *testing.T) {
for {
i++
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()
if err != nil {
break
Expand Down

0 comments on commit 46fffe4

Please sign in to comment.