ci(lint): enable perfsprint linter (#4090)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2024-11-15 16:51:12 +01:00 committed by GitHub
parent f875d87283
commit 02c1144f31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 22 deletions

View File

@ -16,6 +16,7 @@ linters:
- nakedret - nakedret
- nilerr - nilerr
- nolintlint - nolintlint
- perfsprint
- revive - revive
- testifylint - testifylint
- wastedassign - wastedassign
@ -34,6 +35,13 @@ linters-settings:
- G112 - G112
- G201 - G201
- G203 - G203
perfsprint:
err-error: true
errorf: true
fiximports: true
int-conversion: true
sprintf1: true
strconcat: true
testifylint: testifylint:
enable-all: true enable-all: true

View File

@ -6,7 +6,7 @@ package binding
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "errors"
"mime/multipart" "mime/multipart"
"reflect" "reflect"
"strconv" "strconv"
@ -494,7 +494,7 @@ type customUnmarshalParamType struct {
func (f *customUnmarshalParamType) UnmarshalParam(param string) error { func (f *customUnmarshalParamType) UnmarshalParam(param string) error {
parts := strings.Split(param, ":") parts := strings.Split(param, ":")
if len(parts) != 3 { if len(parts) != 3 {
return fmt.Errorf("invalid format") return errors.New("invalid format")
} }
f.Protocol = parts[0] f.Protocol = parts[0]
f.Path = parts[1] f.Path = parts[1]
@ -556,7 +556,7 @@ func (p *customPath) UnmarshalParam(param string) error {
elems := strings.Split(param, "/") elems := strings.Split(param, "/")
n := len(elems) n := len(elems)
if n < 2 { if n < 2 {
return fmt.Errorf("invalid format") return errors.New("invalid format")
} }
*p = elems *p = elems
@ -600,7 +600,7 @@ func (o *objectID) UnmarshalParam(param string) error {
func convertTo(s string) (objectID, error) { func convertTo(s string) (objectID, error) {
var nilObjectID objectID var nilObjectID objectID
if len(s) != 24 { if len(s) != 24 {
return nilObjectID, fmt.Errorf("invalid format") return nilObjectID, errors.New("invalid format")
} }
var oid [12]byte var oid [12]byte

View File

@ -18,6 +18,7 @@ import (
"net/url" "net/url"
"os" "os"
"reflect" "reflect"
"strconv"
"strings" "strings"
"sync" "sync"
"testing" "testing"
@ -2633,7 +2634,7 @@ func TestContextRenderDataFromReader(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code) assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, body, w.Body.String()) assert.Equal(t, body, w.Body.String())
assert.Equal(t, contentType, w.Header().Get("Content-Type")) assert.Equal(t, contentType, w.Header().Get("Content-Type"))
assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length")) assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))
assert.Equal(t, extraHeaders["Content-Disposition"], w.Header().Get("Content-Disposition")) assert.Equal(t, extraHeaders["Content-Disposition"], w.Header().Get("Content-Disposition"))
} }
@ -2651,7 +2652,7 @@ func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code) assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, body, w.Body.String()) assert.Equal(t, body, w.Body.String())
assert.Equal(t, contentType, w.Header().Get("Content-Type")) assert.Equal(t, contentType, w.Header().Get("Content-Type"))
assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length")) assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))
} }
type TestResponseRecorder struct { type TestResponseRecorder struct {

View File

@ -73,7 +73,7 @@ func TestLoadHTMLGlobDebugMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -131,7 +131,7 @@ func TestLoadHTMLGlobTestMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -151,7 +151,7 @@ func TestLoadHTMLGlobReleaseMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -178,7 +178,7 @@ func TestLoadHTMLGlobUsingTLS(t *testing.T) {
}, },
} }
client := &http.Client{Transport: tr} client := &http.Client{Transport: tr}
res, err := client.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := client.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -198,7 +198,7 @@ func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL)) res, err := http.Get(ts.URL + "/raw")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -229,7 +229,7 @@ func TestLoadHTMLFilesTestMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -249,7 +249,7 @@ func TestLoadHTMLFilesDebugMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -269,7 +269,7 @@ func TestLoadHTMLFilesReleaseMode(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := http.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -296,7 +296,7 @@ func TestLoadHTMLFilesUsingTLS(t *testing.T) {
}, },
} }
client := &http.Client{Transport: tr} client := &http.Client{Transport: tr}
res, err := client.Get(fmt.Sprintf("%s/test", ts.URL)) res, err := client.Get(ts.URL + "/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -316,7 +316,7 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
) )
defer ts.Close() defer ts.Close()
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL)) res, err := http.Get(ts.URL + "/raw")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"strconv"
"strings" "strings"
"testing" "testing"
@ -411,7 +412,7 @@ func exampleFromPath(path string) (string, Params) {
} }
if start >= 0 { if start >= 0 {
if c == '/' { if c == '/' {
value := fmt.Sprint(rand.Intn(100000)) value := strconv.Itoa(rand.Intn(100000))
params = append(params, Param{ params = append(params, Param{
Key: path[start:i], Key: path[start:i],
Value: value, Value: value,
@ -425,7 +426,7 @@ func exampleFromPath(path string) (string, Params) {
} }
} }
if start >= 0 { if start >= 0 {
value := fmt.Sprint(rand.Intn(100000)) value := strconv.Itoa(rand.Intn(100000))
params = append(params, Param{ params = append(params, Param{
Key: path[start:], Key: path[start:],
Value: value, Value: value,

View File

@ -5,7 +5,6 @@
package gin package gin
import ( import (
"fmt"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -33,7 +32,7 @@ func TestPanicClean(t *testing.T) {
}, },
header{ header{
Key: "Authorization", Key: "Authorization",
Value: fmt.Sprintf("Bearer %s", password), Value: "Bearer " + password,
}, },
header{ header{
Key: "Content-Type", Key: "Content-Type",

View File

@ -560,7 +560,7 @@ func TestRouterNotFoundWithRemoveExtraSlash(t *testing.T) {
w := PerformRequest(router, "GET", tr.route) w := PerformRequest(router, "GET", tr.route)
assert.Equal(t, tr.code, w.Code) assert.Equal(t, tr.code, w.Code)
if w.Code != http.StatusNotFound { if w.Code != http.StatusNotFound {
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location"))) assert.Equal(t, tr.location, w.Header().Get("Location"))
} }
} }
} }
@ -590,7 +590,7 @@ func TestRouterNotFound(t *testing.T) {
w := PerformRequest(router, http.MethodGet, tr.route) w := PerformRequest(router, http.MethodGet, tr.route)
assert.Equal(t, tr.code, w.Code) assert.Equal(t, tr.code, w.Code)
if w.Code != http.StatusNotFound { if w.Code != http.StatusNotFound {
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location"))) assert.Equal(t, tr.location, w.Header().Get("Location"))
} }
} }