Skip to content

Commit

Permalink
🐛 Bug: Fix issues introduced in linting PR (#2319)
Browse files Browse the repository at this point in the history
* internal: revert linting changes

Changes to the internal package should not have been made in 167a8b5.

* middleware/monitor: revert changes to exported field "ChartJSURL"

This is a breaking change introduced in 167a8b5.

* middleware/monitor: fix error checking

Fix the errorenous error checking introduced in 167a8b5.

* 🐛 Bug: Fix issues introduced in linting PR #2319

* 🐛 Bug: Fix issues introduced in linting PR #2319

* Bug: Fix issues introduced in linting PR #2319

---------

Co-authored-by: René Werner <rene@gofiber.io>
  • Loading branch information
leonklingele and ReneWerner87 committed Feb 2, 2023
1 parent 44d0920 commit ac4ce21
Show file tree
Hide file tree
Showing 111 changed files with 98 additions and 9,594 deletions.
67 changes: 1 addition & 66 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@ run:
modules-download-mode: readonly
skip-dirs-use-default: false
skip-dirs:
- internal # TODO: Also apply proper linting for internal dir
- internal

This comment has been minimized.

Copy link
@leonklingele

leonklingele Feb 2, 2023

Author Member

Eventually, the internal package should be linted as well imo.


output:
sort-results: true

linters-settings:
# TODO: Eventually enable these checks
# depguard:
# include-go-root: true
# packages:
# - flag
# - io/ioutil
# - reflect
# - unsafe
# 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'
# - reflect: '`reflect` package is dangerous to use'
# - unsafe: '`unsafe` package is dangerous to use'

errcheck:
check-type-assertions: true
check-blank: true
Expand All @@ -44,15 +30,6 @@ linters-settings:
# - 'time\.Sleep'
# - 'panic'

gci:

This comment has been minimized.

Copy link
@leonklingele

leonklingele Feb 2, 2023

Author Member

I'd love to keep this linter active, it's so much nicer to have ordered imports than a random order.

sections:
- standard
- prefix(github.com/gofiber/fiber)
- default
- blank
- dot
custom-order: true

gocritic:
disabled-checks:
- ifElseChain
Expand Down Expand Up @@ -162,86 +139,47 @@ linters:
- bodyclose
- containedctx
- contextcheck
# - cyclop
# - deadcode
# - decorder
- depguard
- dogsled
# - dupl
# - dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
# - exhaustivestruct
# - exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
# - funlen
- gci
- gochecknoglobals
- gochecknoinits
# - gocognit
- goconst
- gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
- gofmt
- gofumpt
# - goheader
- goimports
# - golint
- gomnd
- gomoddirectives
# - gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
# - ifshort
# - importas
- ineffassign

This comment has been minimized.

Copy link
@leonklingele

leonklingele Feb 2, 2023

Author Member

This linter should not have been removed.

# - interfacebloat
# - interfacer
# - ireturn
# - lll
- loggercheck
# - maintidx
# - makezero
# - maligned
- misspell
- nakedret
# - nestif
- nilerr
- nilnil
# - nlreturn
- noctx
- nolintlint
- nonamedreturns
# - nosnakecase
- nosprintfhostport
# - paralleltest # TODO: Enable once https://github.com/gofiber/fiber/issues/2254 is implemented

This comment has been minimized.

Copy link
@leonklingele

leonklingele Feb 2, 2023

Author Member

This should not have been removed.

# - prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
# - scopelint
- sqlclosecheck
- staticcheck
# - structcheck
- stylecheck
- tagliatelle
# - tenv # TODO: Enable once we drop support for Go 1.16

This comment has been minimized.

Copy link
@leonklingele

leonklingele Feb 2, 2023

Author Member

This should not have been removed.

# - testableexamples
# - testpackage # TODO: Enable once https://github.com/gofiber/fiber/issues/2252 is implemented
- thelper
# - tparallel # TODO: Enable once https://github.com/gofiber/fiber/issues/2254 is implemented
Expand All @@ -250,9 +188,6 @@ linters:
- unparam
- unused
- usestdlibvars
# - varcheck
# - varnamelen
- wastedassign
- whitespace
- wrapcheck
# - wsl
2 changes: 0 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ const (
)

// HTTP methods enabled by default
//
//nolint:gochecknoglobals // Using a global var is fine here
var DefaultMethods = []string{
MethodGet,
MethodHead,
Expand Down
2 changes: 0 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Args = fasthttp.Args
// Copy from fasthttp
type RetryIfFunc = fasthttp.RetryIfFunc

//nolint:gochecknoglobals // TODO: Do not use a global var here
var defaultClient Client

// Client implements http client.
Expand Down Expand Up @@ -859,7 +858,6 @@ func (a *Agent) reset() {
a.formFiles = a.formFiles[:0]
}

//nolint:gochecknoglobals // TODO: Do not use global vars here
var (
clientPool sync.Pool
agentPool = sync.Pool{
Expand Down
2 changes: 0 additions & 2 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ type Colors struct {
}

// DefaultColors Default color codes
//
//nolint:gochecknoglobals // Using a global var is fine here
var DefaultColors = Colors{
Black: "\u001b[90m",
Red: "\u001b[91m",
Expand Down
9 changes: 3 additions & 6 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"text/template"
"time"

"github.com/gofiber/fiber/v2/internal/dictpool"
"github.com/gofiber/fiber/v2/internal/schema"
"github.com/gofiber/fiber/v2/utils"

"github.com/savsgio/dictpool"
"github.com/valyala/bytebufferpool"
"github.com/valyala/fasthttp"
)
Expand All @@ -51,15 +51,13 @@ const (
// userContextKey define the key name for storing context.Context in *fasthttp.RequestCtx
const userContextKey = "__local_user_context__"

//nolint:gochecknoglobals // TODO: Do not use global vars here
var (
// decoderPoolMap helps to improve BodyParser's, QueryParser's and ReqHeaderParser's performance
decoderPoolMap = map[string]*sync.Pool{}
// tags is used to classify parser's pool
tags = []string{queryTag, bodyTag, reqHeaderTag, paramsTag}
)

//nolint:gochecknoinits // init() is used to initialize a global map variable
func init() {
for _, tag := range tags {
decoderPoolMap[tag] = &sync.Pool{New: func() interface{} {
Expand Down Expand Up @@ -730,7 +728,7 @@ iploop:
var v4, v6 bool

// Manually splitting string without allocating slice, working with parts directly
i, j = j+1, j+2 //nolint:gomnd // Using these values is fine
i, j = j+1, j+2

if j > len(headerValue) {
break
Expand Down Expand Up @@ -780,7 +778,7 @@ func (c *Ctx) extractIPFromHeader(header string) string {
var v4, v6 bool

// Manually splitting string without allocating slice, working with parts directly
i, j = j+1, j+2 //nolint:gomnd // Using these values is fine
i, j = j+1, j+2

if j > len(headerValue) {
break
Expand Down Expand Up @@ -1559,7 +1557,6 @@ func (c *Ctx) Send(body []byte) error {
return nil
}

//nolint:gochecknoglobals // TODO: Do not use global vars here
var (
sendFileOnce sync.Once
sendFileFS *fasthttp.FS
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/gofiber/fiber/v2
go 1.19

require (
github.com/google/uuid v1.3.0
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.17
github.com/mattn/go-runewidth v0.0.14
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94
github.com/tinylib/msgp v1.1.6
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v1.44.0
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
Expand All @@ -14,6 +17,8 @@ require (
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
)
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -9,17 +11,38 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.44.0 h1:R+gLUhldIsfg1HokMuQjdQ5bh9nuXHPIfvkYUu9eR5Q=
github.com/valyala/fasthttp v1.44.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -28,6 +51,13 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 3 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ func (app *App) isEtagStale(etag string, noneMatchBytes []byte) bool {
// https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L110
for i := range noneMatchBytes {
switch noneMatchBytes[i] {
case 0x20: //nolint:gomnd // This is a space (" ")
case 0x20:
if start == end {
start = i + 1
end = i + 1
}
case 0x2c: //nolint:gomnd // This is a comma (",")
case 0x2c:
if matchEtag(app.getString(noneMatchBytes[start:end]), etag) {
return false
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func getBytesImmutable(s string) []byte {
func (app *App) methodInt(s string) int {
// For better performance
if len(app.configured.RequestMethods) == 0 {
//nolint:gomnd // TODO: Use iota instead
// TODO: Use iota instead
switch s {
case MethodGet:
return 0
Expand Down
Loading

0 comments on commit ac4ce21

Please sign in to comment.