diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 3defb963..21016895 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -26,4 +26,4 @@ jobs: uses: golangci/golangci-lint-action@v3 with: # NOTE: Keep this in sync with the version from .golangci.yml - version: v1.51.0 + version: v1.55.2 diff --git a/.golangci.yml b/.golangci.yml index 92c13eba..5d40f30f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,18 +39,20 @@ linters-settings: extra-rules: true gosec: + excludes: + - G104 config: global: audit: true depguard: - include-go-root: true - packages: - - flag - - io/ioutil - packages-with-error-message: - - flag: '`flag` package is only allowed in main.go' - - io/ioutil: '`io/ioutil` package is deprecated, use the `io` and `os` package instead' + rules: + main: + deny: + - pkg: flag + desc: '`flag` package is only allowed in main.go' + - pkg: io/ioutil + desc: '`io/ioutil` package is deprecated, use the `io` and `os` package instead' govet: check-shadowing: true @@ -93,6 +95,8 @@ linters-settings: disabled: true - name: cognitive-complexity disabled: true + - name: comment-spacings + disabled: true # TODO https://github.com/gofiber/fiber/issues/2816 - name: cyclomatic disabled: true - name: early-return @@ -100,6 +104,8 @@ linters-settings: disabled: true - name: exported disabled: true + arguments: + - disableStutteringCheck # TODO https://github.com/gofiber/fiber/issues/2816 - name: file-header disabled: true - name: function-result-limit @@ -116,6 +122,8 @@ linters-settings: disabled: true - name: package-comments disabled: true + - name: unchecked-type-assertion + disabled: true # TODO https://github.com/gofiber/fiber/issues/2816 stylecheck: checks: @@ -164,7 +172,8 @@ linters: - exportloopref - forbidigo - forcetypeassert - - goconst + # - gochecksumtype # TODO https://github.com/gofiber/fiber/issues/2816 + # - goconst # TODO https://github.com/gofiber/fiber/issues/2816 - gocritic - gofmt - gofumpt @@ -173,9 +182,12 @@ linters: - goprintffuncname - gosec - gosimple + # - gosmopolitan # TODO https://github.com/gofiber/fiber/issues/2816 - govet - grouper + # - inamedparam # TODO https://github.com/gofiber/fiber/issues/2816 - loggercheck + # - mirror # TODO https://github.com/gofiber/fiber/issues/2816 - misspell - nakedret - nilerr @@ -184,6 +196,7 @@ linters: - nolintlint - nonamedreturns - nosprintfhostport + # - perfsprint # TODO https://github.com/gofiber/fiber/issues/2816 - predeclared - promlinter - reassign @@ -192,7 +205,9 @@ linters: - sqlclosecheck - staticcheck - stylecheck + # - tagalign # TODO https://github.com/gofiber/fiber/issues/2816 - tagliatelle + - testifylint # - testpackage # TODO: Enable once https://github.com/gofiber/fiber/issues/2252 is implemented - thelper - tparallel @@ -201,7 +216,7 @@ linters: - unparam - unused - usestdlibvars - - wastedassign + # - wastedassign # TODO https://github.com/gofiber/fiber/issues/2816 - whitespace - wrapcheck - tenv diff --git a/binder/mapping.go b/binder/mapping.go index e37d06c6..0a027d7e 100644 --- a/binder/mapping.go +++ b/binder/mapping.go @@ -136,7 +136,7 @@ func parseParamSquareBrackets(k string) (string, error) { for i, b := range kbytes { if b == '[' && kbytes[i+1] != ']' { if err := bb.WriteByte('.'); err != nil { - return "", err //nolint:wrapchec,wrapcheck // unnecessary to wrap it + return "", err //nolint:wrapcheck // unnecessary to wrap it } } @@ -145,7 +145,7 @@ func parseParamSquareBrackets(k string) (string, error) { } if err := bb.WriteByte(b); err != nil { - return "", err //nolint:wrapchec,wrapcheck // unnecessary to wrap it + return "", err //nolint:wrapcheck // unnecessary to wrap it } } diff --git a/error.go b/error.go index ea7a96d3..13b7e58f 100644 --- a/error.go +++ b/error.go @@ -1,19 +1,19 @@ package fiber import ( - errors "encoding/json" - stdErrors "errors" + "encoding/json" + "errors" "github.com/gofiber/fiber/v3/internal/schema" ) // Wrap and return this for unreachable code if panicking is undesirable (i.e., in a handler). // Unexported because users will hopefully never need to see it. -var errUnreachable = stdErrors.New("fiber: unreachable code, please create an issue at github.com/gofiber/fiber") +var errUnreachable = errors.New("fiber: unreachable code, please create an issue at github.com/gofiber/fiber") // Graceful shutdown errors var ( - ErrGracefulTimeout = stdErrors.New("shutdown: graceful timeout has been reached, exiting") + ErrGracefulTimeout = errors.New("shutdown: graceful timeout has been reached, exiting") ) // Fiber redirection errors @@ -23,17 +23,17 @@ var ( // Range errors var ( - ErrRangeMalformed = stdErrors.New("range: malformed range header string") - ErrRangeUnsatisfiable = stdErrors.New("range: unsatisfiable range") + ErrRangeMalformed = errors.New("range: malformed range header string") + ErrRangeUnsatisfiable = errors.New("range: unsatisfiable range") ) // Binder errors -var ErrCustomBinderNotFound = stdErrors.New("binder: custom binder not found, please be sure to enter the right name") +var ErrCustomBinderNotFound = errors.New("binder: custom binder not found, please be sure to enter the right name") // Format errors var ( // ErrNoHandlers is returned when c.Format is called with no arguments. - ErrNoHandlers = stdErrors.New("format: at least one handler is required, but none were set") + ErrNoHandlers = errors.New("format: at least one handler is required, but none were set") ) // gorilla/schema errors @@ -52,21 +52,21 @@ type ( type ( // An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. // (The argument to Unmarshal must be a non-nil pointer.) - InvalidUnmarshalError = errors.InvalidUnmarshalError + InvalidUnmarshalError = json.InvalidUnmarshalError // A MarshalerError represents an error from calling a MarshalJSON or MarshalText method. - MarshalerError = errors.MarshalerError + MarshalerError = json.MarshalerError // A SyntaxError is a description of a JSON syntax error. - SyntaxError = errors.SyntaxError + SyntaxError = json.SyntaxError // An UnmarshalTypeError describes a JSON value that was // not appropriate for a value of a specific Go type. - UnmarshalTypeError = errors.UnmarshalTypeError + UnmarshalTypeError = json.UnmarshalTypeError // An UnsupportedTypeError is returned by Marshal when attempting // to encode an unsupported value type. - UnsupportedTypeError = errors.UnsupportedTypeError + UnsupportedTypeError = json.UnsupportedTypeError - UnsupportedValueError = errors.UnsupportedValueError + UnsupportedValueError = json.UnsupportedValueError ) diff --git a/middleware/adaptor/adaptor_test.go b/middleware/adaptor/adaptor_test.go index b170f816..198a25ee 100644 --- a/middleware/adaptor/adaptor_test.go +++ b/middleware/adaptor/adaptor_test.go @@ -76,7 +76,7 @@ func Test_HTTPHandler(t *testing.T) { req.Header.SetMethod(expectedMethod) req.SetRequestURI(expectedRequestURI) req.Header.SetHost(expectedHost) - req.BodyWriter().Write([]byte(expectedBody)) //nolint:errcheck, gosec // not needed + req.BodyWriter().Write([]byte(expectedBody)) //nolint:errcheck // not needed for k, v := range expectedHeader { req.Header.Set(k, v) } diff --git a/redirect_test.go b/redirect_test.go index 7ae0ce2a..f3b1e7ca 100644 --- a/redirect_test.go +++ b/redirect_test.go @@ -342,7 +342,7 @@ func Benchmark_Redirect_Route(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - c.Redirect().Route("user", RedirectConfig{ //nolint:errcheck,gosec,revive // we don't need to handle error here + c.Redirect().Route("user", RedirectConfig{ //nolint:errcheck,revive // we don't need to handle error here Params: Map{ "name": "fiber", }, @@ -366,7 +366,7 @@ func Benchmark_Redirect_Route_WithQueries(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - c.Redirect().Route("user", RedirectConfig{ //nolint:errcheck,gosec,revive // we don't need to handle error here + c.Redirect().Route("user", RedirectConfig{ //nolint:errcheck,revive // we don't need to handle error here Params: Map{ "name": "fiber", }, @@ -395,7 +395,7 @@ func Benchmark_Redirect_Route_WithFlashMessages(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - c.Redirect().With("success", "1").With("message", "test").Route("user") //nolint:errcheck,gosec,revive // we don't need to handle error here + c.Redirect().With("success", "1").With("message", "test").Route("user") //nolint:errcheck,revive // we don't need to handle error here } require.Equal(b, 302, c.Response().StatusCode())