mirror of https://github.com/gin-gonic/gin.git
ci(lint): enable perfsprint linter (#4090)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
f875d87283
commit
02c1144f31
|
@ -16,6 +16,7 @@ linters:
|
|||
- nakedret
|
||||
- nilerr
|
||||
- nolintlint
|
||||
- perfsprint
|
||||
- revive
|
||||
- testifylint
|
||||
- wastedassign
|
||||
|
@ -34,6 +35,13 @@ linters-settings:
|
|||
- G112
|
||||
- G201
|
||||
- G203
|
||||
perfsprint:
|
||||
err-error: true
|
||||
errorf: true
|
||||
fiximports: true
|
||||
int-conversion: true
|
||||
sprintf1: true
|
||||
strconcat: true
|
||||
testifylint:
|
||||
enable-all: true
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ package binding
|
|||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"errors"
|
||||
"mime/multipart"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
@ -494,7 +494,7 @@ type customUnmarshalParamType struct {
|
|||
func (f *customUnmarshalParamType) UnmarshalParam(param string) error {
|
||||
parts := strings.Split(param, ":")
|
||||
if len(parts) != 3 {
|
||||
return fmt.Errorf("invalid format")
|
||||
return errors.New("invalid format")
|
||||
}
|
||||
f.Protocol = parts[0]
|
||||
f.Path = parts[1]
|
||||
|
@ -556,7 +556,7 @@ func (p *customPath) UnmarshalParam(param string) error {
|
|||
elems := strings.Split(param, "/")
|
||||
n := len(elems)
|
||||
if n < 2 {
|
||||
return fmt.Errorf("invalid format")
|
||||
return errors.New("invalid format")
|
||||
}
|
||||
|
||||
*p = elems
|
||||
|
@ -600,7 +600,7 @@ func (o *objectID) UnmarshalParam(param string) error {
|
|||
func convertTo(s string) (objectID, error) {
|
||||
var nilObjectID objectID
|
||||
if len(s) != 24 {
|
||||
return nilObjectID, fmt.Errorf("invalid format")
|
||||
return nilObjectID, errors.New("invalid format")
|
||||
}
|
||||
|
||||
var oid [12]byte
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
@ -2633,7 +2634,7 @@ func TestContextRenderDataFromReader(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
assert.Equal(t, body, w.Body.String())
|
||||
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"))
|
||||
}
|
||||
|
||||
|
@ -2651,7 +2652,7 @@ func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
assert.Equal(t, body, w.Body.String())
|
||||
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 {
|
||||
|
|
20
gin_test.go
20
gin_test.go
|
@ -73,7 +73,7 @@ func TestLoadHTMLGlobDebugMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func TestLoadHTMLGlobTestMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func TestLoadHTMLGlobReleaseMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func TestLoadHTMLGlobUsingTLS(t *testing.T) {
|
|||
},
|
||||
}
|
||||
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 {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/raw")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ func TestLoadHTMLFilesTestMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ func TestLoadHTMLFilesDebugMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ func TestLoadHTMLFilesReleaseMode(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ func TestLoadHTMLFilesUsingTLS(t *testing.T) {
|
|||
},
|
||||
}
|
||||
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 {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
|
|||
)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))
|
||||
res, err := http.Get(ts.URL + "/raw")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -411,7 +412,7 @@ func exampleFromPath(path string) (string, Params) {
|
|||
}
|
||||
if start >= 0 {
|
||||
if c == '/' {
|
||||
value := fmt.Sprint(rand.Intn(100000))
|
||||
value := strconv.Itoa(rand.Intn(100000))
|
||||
params = append(params, Param{
|
||||
Key: path[start:i],
|
||||
Value: value,
|
||||
|
@ -425,7 +426,7 @@ func exampleFromPath(path string) (string, Params) {
|
|||
}
|
||||
}
|
||||
if start >= 0 {
|
||||
value := fmt.Sprint(rand.Intn(100000))
|
||||
value := strconv.Itoa(rand.Intn(100000))
|
||||
params = append(params, Param{
|
||||
Key: path[start:],
|
||||
Value: value,
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package gin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -33,7 +32,7 @@ func TestPanicClean(t *testing.T) {
|
|||
},
|
||||
header{
|
||||
Key: "Authorization",
|
||||
Value: fmt.Sprintf("Bearer %s", password),
|
||||
Value: "Bearer " + password,
|
||||
},
|
||||
header{
|
||||
Key: "Content-Type",
|
||||
|
|
|
@ -560,7 +560,7 @@ func TestRouterNotFoundWithRemoveExtraSlash(t *testing.T) {
|
|||
w := PerformRequest(router, "GET", tr.route)
|
||||
assert.Equal(t, tr.code, w.Code)
|
||||
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)
|
||||
assert.Equal(t, tr.code, w.Code)
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue