Skip to content

Commit 02c1144

Browse files
authored
ci(lint): enable perfsprint linter (#4090)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent f875d87 commit 02c1144

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- nakedret
1717
- nilerr
1818
- nolintlint
19+
- perfsprint
1920
- revive
2021
- testifylint
2122
- wastedassign
@@ -34,6 +35,13 @@ linters-settings:
3435
- G112
3536
- G201
3637
- G203
38+
perfsprint:
39+
err-error: true
40+
errorf: true
41+
fiximports: true
42+
int-conversion: true
43+
sprintf1: true
44+
strconcat: true
3745
testifylint:
3846
enable-all: true
3947

binding/form_mapping_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package binding
66

77
import (
88
"encoding/hex"
9-
"fmt"
9+
"errors"
1010
"mime/multipart"
1111
"reflect"
1212
"strconv"
@@ -494,7 +494,7 @@ type customUnmarshalParamType struct {
494494
func (f *customUnmarshalParamType) UnmarshalParam(param string) error {
495495
parts := strings.Split(param, ":")
496496
if len(parts) != 3 {
497-
return fmt.Errorf("invalid format")
497+
return errors.New("invalid format")
498498
}
499499
f.Protocol = parts[0]
500500
f.Path = parts[1]
@@ -556,7 +556,7 @@ func (p *customPath) UnmarshalParam(param string) error {
556556
elems := strings.Split(param, "/")
557557
n := len(elems)
558558
if n < 2 {
559-
return fmt.Errorf("invalid format")
559+
return errors.New("invalid format")
560560
}
561561

562562
*p = elems
@@ -600,7 +600,7 @@ func (o *objectID) UnmarshalParam(param string) error {
600600
func convertTo(s string) (objectID, error) {
601601
var nilObjectID objectID
602602
if len(s) != 24 {
603-
return nilObjectID, fmt.Errorf("invalid format")
603+
return nilObjectID, errors.New("invalid format")
604604
}
605605

606606
var oid [12]byte

context_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"net/url"
1919
"os"
2020
"reflect"
21+
"strconv"
2122
"strings"
2223
"sync"
2324
"testing"
@@ -2633,7 +2634,7 @@ func TestContextRenderDataFromReader(t *testing.T) {
26332634
assert.Equal(t, http.StatusOK, w.Code)
26342635
assert.Equal(t, body, w.Body.String())
26352636
assert.Equal(t, contentType, w.Header().Get("Content-Type"))
2636-
assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length"))
2637+
assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))
26372638
assert.Equal(t, extraHeaders["Content-Disposition"], w.Header().Get("Content-Disposition"))
26382639
}
26392640

@@ -2651,7 +2652,7 @@ func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {
26512652
assert.Equal(t, http.StatusOK, w.Code)
26522653
assert.Equal(t, body, w.Body.String())
26532654
assert.Equal(t, contentType, w.Header().Get("Content-Type"))
2654-
assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length"))
2655+
assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))
26552656
}
26562657

26572658
type TestResponseRecorder struct {

gin_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestLoadHTMLGlobDebugMode(t *testing.T) {
7373
)
7474
defer ts.Close()
7575

76-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
76+
res, err := http.Get(ts.URL + "/test")
7777
if err != nil {
7878
t.Error(err)
7979
}
@@ -131,7 +131,7 @@ func TestLoadHTMLGlobTestMode(t *testing.T) {
131131
)
132132
defer ts.Close()
133133

134-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
134+
res, err := http.Get(ts.URL + "/test")
135135
if err != nil {
136136
t.Error(err)
137137
}
@@ -151,7 +151,7 @@ func TestLoadHTMLGlobReleaseMode(t *testing.T) {
151151
)
152152
defer ts.Close()
153153

154-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
154+
res, err := http.Get(ts.URL + "/test")
155155
if err != nil {
156156
t.Error(err)
157157
}
@@ -178,7 +178,7 @@ func TestLoadHTMLGlobUsingTLS(t *testing.T) {
178178
},
179179
}
180180
client := &http.Client{Transport: tr}
181-
res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))
181+
res, err := client.Get(ts.URL + "/test")
182182
if err != nil {
183183
t.Error(err)
184184
}
@@ -198,7 +198,7 @@ func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
198198
)
199199
defer ts.Close()
200200

201-
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))
201+
res, err := http.Get(ts.URL + "/raw")
202202
if err != nil {
203203
t.Error(err)
204204
}
@@ -229,7 +229,7 @@ func TestLoadHTMLFilesTestMode(t *testing.T) {
229229
)
230230
defer ts.Close()
231231

232-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
232+
res, err := http.Get(ts.URL + "/test")
233233
if err != nil {
234234
t.Error(err)
235235
}
@@ -249,7 +249,7 @@ func TestLoadHTMLFilesDebugMode(t *testing.T) {
249249
)
250250
defer ts.Close()
251251

252-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
252+
res, err := http.Get(ts.URL + "/test")
253253
if err != nil {
254254
t.Error(err)
255255
}
@@ -269,7 +269,7 @@ func TestLoadHTMLFilesReleaseMode(t *testing.T) {
269269
)
270270
defer ts.Close()
271271

272-
res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))
272+
res, err := http.Get(ts.URL + "/test")
273273
if err != nil {
274274
t.Error(err)
275275
}
@@ -296,7 +296,7 @@ func TestLoadHTMLFilesUsingTLS(t *testing.T) {
296296
},
297297
}
298298
client := &http.Client{Transport: tr}
299-
res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))
299+
res, err := client.Get(ts.URL + "/test")
300300
if err != nil {
301301
t.Error(err)
302302
}
@@ -316,7 +316,7 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
316316
)
317317
defer ts.Close()
318318

319-
res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))
319+
res, err := http.Get(ts.URL + "/raw")
320320
if err != nil {
321321
t.Error(err)
322322
}

githubapi_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"net/http/httptest"
1212
"os"
13+
"strconv"
1314
"strings"
1415
"testing"
1516

@@ -411,7 +412,7 @@ func exampleFromPath(path string) (string, Params) {
411412
}
412413
if start >= 0 {
413414
if c == '/' {
414-
value := fmt.Sprint(rand.Intn(100000))
415+
value := strconv.Itoa(rand.Intn(100000))
415416
params = append(params, Param{
416417
Key: path[start:i],
417418
Value: value,
@@ -425,7 +426,7 @@ func exampleFromPath(path string) (string, Params) {
425426
}
426427
}
427428
if start >= 0 {
428-
value := fmt.Sprint(rand.Intn(100000))
429+
value := strconv.Itoa(rand.Intn(100000))
429430
params = append(params, Param{
430431
Key: path[start:],
431432
Value: value,

recovery_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package gin
66

77
import (
8-
"fmt"
98
"net"
109
"net/http"
1110
"os"
@@ -33,7 +32,7 @@ func TestPanicClean(t *testing.T) {
3332
},
3433
header{
3534
Key: "Authorization",
36-
Value: fmt.Sprintf("Bearer %s", password),
35+
Value: "Bearer " + password,
3736
},
3837
header{
3938
Key: "Content-Type",

routes_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func TestRouterNotFoundWithRemoveExtraSlash(t *testing.T) {
560560
w := PerformRequest(router, "GET", tr.route)
561561
assert.Equal(t, tr.code, w.Code)
562562
if w.Code != http.StatusNotFound {
563-
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))
563+
assert.Equal(t, tr.location, w.Header().Get("Location"))
564564
}
565565
}
566566
}
@@ -590,7 +590,7 @@ func TestRouterNotFound(t *testing.T) {
590590
w := PerformRequest(router, http.MethodGet, tr.route)
591591
assert.Equal(t, tr.code, w.Code)
592592
if w.Code != http.StatusNotFound {
593-
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))
593+
assert.Equal(t, tr.location, w.Header().Get("Location"))
594594
}
595595
}
596596

0 commit comments

Comments
 (0)