mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-06 20:31:35 +00:00
chore: Update golangci-lint to enable more lint rules (#2923)
* chore(lint): enable ifElseChange and clean up config a bit * chore(lint): enable gocritic diagnostic checks
This commit is contained in:
parent
5449b04101
commit
82070cb4c8
@ -72,17 +72,12 @@ linters-settings:
|
||||
|
||||
gocritic:
|
||||
# TODO: Uncomment the following lines
|
||||
# enabled-tags:
|
||||
# - diagnostic
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
# - style
|
||||
# - performance
|
||||
# - experimental
|
||||
# - opinionated
|
||||
disabled-checks:
|
||||
- ifElseChain # TODO: Do not disable
|
||||
# - hugeParam
|
||||
# - rangeExprCopy
|
||||
# - rangeValCopy
|
||||
settings:
|
||||
captLocal:
|
||||
paramsOnly: false
|
||||
@ -195,6 +190,8 @@ linters-settings:
|
||||
disabled: true
|
||||
- name: unchecked-type-assertion
|
||||
disabled: true # TODO: Do not disable
|
||||
- name: unhandled-error
|
||||
arguments: ['bytes\.Buffer\.Write']
|
||||
|
||||
stylecheck:
|
||||
checks:
|
||||
@ -217,9 +214,6 @@ linters-settings:
|
||||
|
||||
testifylint:
|
||||
enable-all: true
|
||||
# TODO: Do not disable any options
|
||||
disable:
|
||||
- go-require
|
||||
|
||||
testpackage:
|
||||
skip-regexp: "^$"
|
||||
|
3
app.go
3
app.go
@ -988,8 +988,7 @@ func (app *App) Test(req *http.Request, timeout ...time.Duration) (*http.Respons
|
||||
|
||||
type disableLogger struct{}
|
||||
|
||||
func (*disableLogger) Printf(_ string, _ ...any) {
|
||||
// fmt.Println(fmt.Sprintf(format, args...))
|
||||
func (*disableLogger) Printf(string, ...any) {
|
||||
}
|
||||
|
||||
func (app *App) init() *App {
|
||||
|
@ -1316,13 +1316,11 @@ func Test_App_Group(t *testing.T) {
|
||||
resp, err := app.Test(httptest.NewRequest(MethodPost, "/test/v1/", nil))
|
||||
require.NoError(t, err, "app.Test(req)")
|
||||
require.Equal(t, 200, resp.StatusCode, "Status code")
|
||||
// require.Equal(t, "/test/v1", resp.Header.Get("Location"), "Location")
|
||||
|
||||
api.Get("/users", dummyHandler)
|
||||
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test/v1/UsErS", nil))
|
||||
require.NoError(t, err, "app.Test(req)")
|
||||
require.Equal(t, 200, resp.StatusCode, "Status code")
|
||||
// require.Equal(t, "/test/v1/users", resp.Header.Get("Location"), "Location")
|
||||
}
|
||||
|
||||
func Test_App_Route(t *testing.T) {
|
||||
|
@ -714,7 +714,6 @@ func Benchmark_Bind_Query_Comma(b *testing.B) {
|
||||
}
|
||||
c.Request().SetBody([]byte(``))
|
||||
c.Request().Header.SetContentType("")
|
||||
// c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball&hobby=football")
|
||||
c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball,football")
|
||||
q := new(Query)
|
||||
b.ReportAllocs()
|
||||
|
@ -183,11 +183,12 @@ func Test_Parser_Request_URL(t *testing.T) {
|
||||
|
||||
flag1, flag2, flag3 := false, false, false
|
||||
for _, v := range values["bar"] {
|
||||
if v == "foo1" {
|
||||
switch v {
|
||||
case "foo1":
|
||||
flag1 = true
|
||||
} else if v == "foo2" {
|
||||
case "foo2":
|
||||
flag2 = true
|
||||
} else if v == "foo" {
|
||||
case "foo":
|
||||
flag3 = true
|
||||
}
|
||||
}
|
||||
|
@ -1435,6 +1435,7 @@ func Test_Ctx_Parsers(t *testing.T) {
|
||||
})
|
||||
t.Run("ParamsParser", func(t *testing.T) {
|
||||
t.Skip("ParamsParser is not ready for v3")
|
||||
//nolint:gocritic // TODO: uncomment
|
||||
// t.Parallel()
|
||||
// withValues(t, func(c Ctx, testStruct *TestStruct) error {
|
||||
// c.route = &Route{Params: []string{"name", "name2", "class", "class2"}}
|
||||
@ -4758,8 +4759,6 @@ func TestCtx_ParamsInt(t *testing.T) {
|
||||
// For the user id I will use the number 1111, so I should be able to get the number
|
||||
// 1111 from the Ctx
|
||||
app.Get("/test/:user", func(c Ctx) error {
|
||||
// require.Equal(t, "john", c.Params("user"))
|
||||
|
||||
num, err := c.ParamsInt("user")
|
||||
|
||||
// Check the number matches
|
||||
@ -4774,8 +4773,6 @@ func TestCtx_ParamsInt(t *testing.T) {
|
||||
// In this test case, there will be a bad request where the expected number is NOT
|
||||
// a number in the path
|
||||
app.Get("/testnoint/:user", func(c Ctx) error {
|
||||
// require.Equal(t, "john", c.Params("user"))
|
||||
|
||||
num, err := c.ParamsInt("user")
|
||||
|
||||
// Check the number matches
|
||||
@ -4790,8 +4787,6 @@ func TestCtx_ParamsInt(t *testing.T) {
|
||||
// For the user id I will use the number 2222, so I should be able to get the number
|
||||
// 2222 from the Ctx even when the default value is specified
|
||||
app.Get("/testignoredefault/:user", func(c Ctx) error {
|
||||
// require.Equal(t, "john", c.Params("user"))
|
||||
|
||||
num, err := c.ParamsInt("user", 1111)
|
||||
|
||||
// Check the number matches
|
||||
@ -4806,8 +4801,6 @@ func TestCtx_ParamsInt(t *testing.T) {
|
||||
// In this test case, there will be a bad request where the expected number is NOT
|
||||
// a number in the path, default value of 1111 should be used instead
|
||||
app.Get("/testdefault/:user", func(c Ctx) error {
|
||||
// require.Equal(t, "john", c.Params("user"))
|
||||
|
||||
num, err := c.ParamsInt("user", 1111)
|
||||
|
||||
// Check the number matches
|
||||
|
10
helpers.go
10
helpers.go
@ -94,7 +94,6 @@ func readContent(rf io.ReaderFrom, name string) (int64, error) {
|
||||
// quoteString escape special characters in a given string
|
||||
func (app *App) quoteString(raw string) string {
|
||||
bb := bytebufferpool.Get()
|
||||
// quoted := string(fasthttp.AppendQuotedArg(bb.B, getBytes(raw)))
|
||||
quoted := app.getString(fasthttp.AppendQuotedArg(bb.B, app.getBytes(raw)))
|
||||
bytebufferpool.Put(bb)
|
||||
return quoted
|
||||
@ -462,13 +461,14 @@ func getOffer(header []byte, isAccepted func(spec, offer string, specParams head
|
||||
// Get specificity
|
||||
var specificity int
|
||||
// check for wildcard this could be a mime */* or a wildcard character *
|
||||
if string(spec) == "*/*" || string(spec) == "*" {
|
||||
switch {
|
||||
case string(spec) == "*/*" || string(spec) == "*":
|
||||
specificity = 1
|
||||
} else if bytes.HasSuffix(spec, []byte("/*")) {
|
||||
case bytes.HasSuffix(spec, []byte("/*")):
|
||||
specificity = 2
|
||||
} else if bytes.IndexByte(spec, '/') != -1 {
|
||||
case bytes.IndexByte(spec, '/') != -1:
|
||||
specificity = 3
|
||||
} else {
|
||||
default:
|
||||
specificity = 4
|
||||
}
|
||||
|
||||
|
@ -89,15 +89,16 @@ func TestAuthSources(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// setup the apikey for the different auth schemes
|
||||
if authSource == "header" {
|
||||
switch authSource {
|
||||
case "header":
|
||||
req.Header.Set(test.authTokenName, test.APIKey)
|
||||
} else if authSource == "cookie" {
|
||||
case "cookie":
|
||||
req.Header.Set("Cookie", test.authTokenName+"="+test.APIKey)
|
||||
} else if authSource == "query" || authSource == "form" {
|
||||
case "query", "form":
|
||||
q := req.URL.Query()
|
||||
q.Add(test.authTokenName, test.APIKey)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
} else if authSource == "param" {
|
||||
case "param":
|
||||
r := req.URL.Path
|
||||
r += url.PathEscape(test.APIKey)
|
||||
req.URL.Path = r
|
||||
|
@ -108,11 +108,12 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
|
||||
var err error
|
||||
// Loop over template parts execute dynamic parts and add fixed parts to the buffer
|
||||
for i, logFunc := range data.LogFuncChain {
|
||||
if logFunc == nil {
|
||||
switch {
|
||||
case logFunc == nil:
|
||||
buf.Write(data.TemplateChain[i])
|
||||
} else if data.TemplateChain[i] == nil {
|
||||
case data.TemplateChain[i] == nil:
|
||||
_, err = logFunc(buf, c, data, "")
|
||||
} else {
|
||||
default:
|
||||
_, err = logFunc(buf, c, data, utils.UnsafeString(data.TemplateChain[i]))
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -72,18 +72,20 @@ func (s *Store) Get(c fiber.Ctx) (*Session, error) {
|
||||
if loadData {
|
||||
raw, err := s.Storage.Get(id)
|
||||
// Unmarshal if we found data
|
||||
if raw != nil && err == nil {
|
||||
switch {
|
||||
case err != nil:
|
||||
return nil, err
|
||||
|
||||
case raw != nil:
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
_, _ = sess.byteBuffer.Write(raw) // Ignore error, this will never fail
|
||||
sess.byteBuffer.Write(raw)
|
||||
encCache := gob.NewDecoder(sess.byteBuffer)
|
||||
err := encCache.Decode(&sess.data.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode session data: %w", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
default:
|
||||
// both raw and err is nil, which means id is not in the storage
|
||||
sess.fresh = true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user