Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update golangci-lint to enable more lint rules #2923

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -217,9 +214,6 @@ linters-settings:

testifylint:
enable-all: true
# TODO: Do not disable any options
disable:
- go-require

testpackage:
skip-regexp: "^$"
Expand Down
3 changes: 1 addition & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions client/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 1 addition & 8 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ParamsParser test is skipped with a comment indicating it's not ready for v3. This might be an oversight or an unfinished task.

Would you like me to help finalize the implementation or remove the placeholder if it's no longer needed?

// t.Parallel()
// withValues(t, func(c Ctx, testStruct *TestStruct) error {
// c.route = &Route{Params: []string{"name", "name2", "class", "class2"}}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions middleware/keyauth/keyauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions middleware/logger/default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions middleware/session/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@
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

Check warning on line 77 in middleware/session/store.go

View check run for this annotation

Codecov / codecov/patch

middleware/session/store.go#L76-L77

Added lines #L76 - L77 were not covered by tests

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
}
Expand Down
Loading