ci(lint): enable perfsprint linter (#4090)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Matthieu MOREL · committed by GitHub · parent f875d87 · Browse files · 7 files·+31 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Diff stats
7 files+31 added−22 removed
- other:+31 added−22 removed
Provenance
- Commit
02c1144- Tree
98a26b9- Author
Matthieu MOREL <matthieu.morel35@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
f875d87
7 files changed+31 added−22 removed
modified:binding/form_mapping_test.go+4 added-4 removed
4 unmodified lines5 package binding6 7 import (8 "encoding/hex"9- "fmt"9+ "errors"10 "mime/multipart"11 "reflect"12 "strconv"13 "strings"479 unmodified lines493 494 func (f *customUnmarshalParamType) UnmarshalParam(param string) error {495 parts := strings.Split(param, ":")496 if len(parts) != 3 {497- return fmt.Errorf("invalid format")497+ return errors.New("invalid format")498 }499 f.Protocol = parts[0]500 f.Path = parts[1]501 f.Name = parts[2]53 unmodified lines555 func (p *customPath) UnmarshalParam(param string) error {556 elems := strings.Split(param, "/")557 n := len(elems)558 if n < 2 {559- return fmt.Errorf("invalid format")559+ return errors.New("invalid format")560 }561 562 *p = elems563 return nil35 unmodified lines599 600 func convertTo(s string) (objectID, error) {601 var nilObjectID objectID602 if len(s) != 24 {603- return nilObjectID, fmt.Errorf("invalid format")603+ return nilObjectID, errors.New("invalid format")604 }605 606 var oid [12]byte607 _, err := hex.Decode(oid[:], []byte(s))30 unmodified linesmodified:.golangci.yml+8 added
14 unmodified lines15161718192021222310 unmodified lines34353637383940414243444546474823 unmodified lines14 unmodified lines - misspell - nakedret - nilerr - nolintlint - perfsprint - revive - testifylint - wastedassign
10 unmodified lines - G111 - G112 - G201 - G203 perfsprint: err-error: true errorf: true fiximports: true int-conversion: true sprintf1: true strconcat: true testifylint: enable-all: true
issues:23 unmodified linesmodified:context_test.go+3 added-2 removed
16 unmodified lines17 "net/http/httptest"18 "net/url"19 "os"20 "reflect"21+ "strconv"22 "strings"23 "sync"24 "testing"25 "time"2607 unmodified lines2633 2634 assert.Equal(t, http.StatusOK, w.Code)2635 assert.Equal(t, body, w.Body.String())2636 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"))2638 assert.Equal(t, extraHeaders["Content-Disposition"], w.Header().Get("Content-Disposition"))2639 }2640 2641 func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {9 unmodified lines2651 2652 assert.Equal(t, http.StatusOK, w.Code)2653 assert.Equal(t, body, w.Body.String())2654 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"))2656 }2657 2658 type TestResponseRecorder struct {2659 *httptest.ResponseRecorder425 unmodified linesmodified:gin_test.go+10 added-10 removed
71 unmodified lines72 },73 )74 defer ts.Close()75 76- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))76+ res, err := http.Get(ts.URL + "/test")77 if err != nil {78 t.Error(err)79 }80 49 unmodified lines130 },131 )132 defer ts.Close()133 134- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))134+ res, err := http.Get(ts.URL + "/test")135 if err != nil {136 t.Error(err)137 }138 11 unmodified lines150 },151 )152 defer ts.Close()153 154- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))154+ res, err := http.Get(ts.URL + "/test")155 if err != nil {156 t.Error(err)157 }158 18 unmodified lines177 InsecureSkipVerify: true,178 },179 }180 client := &http.Client{Transport: tr}181- res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))181+ res, err := client.Get(ts.URL + "/test")182 if err != nil {183 t.Error(err)184 }185 11 unmodified lines197 },198 )199 defer ts.Close()200 201- res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))201+ res, err := http.Get(ts.URL + "/raw")202 if err != nil {203 t.Error(err)204 }205 22 unmodified lines228 },229 )230 defer ts.Close()231 232- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))232+ res, err := http.Get(ts.URL + "/test")233 if err != nil {234 t.Error(err)235 }236 11 unmodified lines248 },249 )250 defer ts.Close()251 252- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))252+ res, err := http.Get(ts.URL + "/test")253 if err != nil {254 t.Error(err)255 }256 11 unmodified lines268 },269 )270 defer ts.Close()271 272- res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))272+ res, err := http.Get(ts.URL + "/test")273 if err != nil {274 t.Error(err)275 }276 18 unmodified lines295 InsecureSkipVerify: true,296 },297 }298 client := &http.Client{Transport: tr}299- res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))299+ res, err := client.Get(ts.URL + "/test")300 if err != nil {301 t.Error(err)302 }303 11 unmodified lines315 },316 )317 defer ts.Close()318 319- res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))319+ res, err := http.Get(ts.URL + "/raw")320 if err != nil {321 t.Error(err)322 }323 445 unmodified linesmodified:githubapi_test.go+3 added-2 removed
8 unmodified lines9 "math/rand"10 "net/http"11 "net/http/httptest"12 "os"13+ "strconv"14 "strings"15 "testing"16 17 "github.com/stretchr/testify/assert"393 unmodified lines411 start = i + 1412 }413 if start >= 0 {414 if c == '/' {414- value := fmt.Sprint(rand.Intn(100000))415+ value := strconv.Itoa(rand.Intn(100000))416 params = append(params, Param{417 Key: path[start:i],418 Value: value,419 })5 unmodified lines425 output.WriteRune(c)426 }427 }428 if start >= 0 {428- value := fmt.Sprint(rand.Intn(100000))429+ value := strconv.Itoa(rand.Intn(100000))430 params = append(params, Param{431 Key: path[start:],432 Value: value,433 })43 unmodified linesmodified:recovery_test.go+1 added-2 removed
3 unmodified lines4 5 package gin6 7 import (8- "fmt"8 "net"9 "net/http"10 "os"11 "strings"19 unmodified lines31 Value: "www.google.com",32 },33 header{34 Key: "Authorization",36- Value: fmt.Sprintf("Bearer %s", password),35+ Value: "Bearer " + password,36 },37 header{38 Key: "Content-Type",39 Value: "application/json",208 unmodified linesmodified:routes_test.go+2 added-2 removed
558 unmodified lines559 for _, tr := range testRoutes {560 w := PerformRequest(router, "GET", tr.route)561 assert.Equal(t, tr.code, w.Code)562 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"))564 }565 }566 }567 21 unmodified lines589 for _, tr := range testRoutes {590 w := PerformRequest(router, http.MethodGet, tr.route)591 assert.Equal(t, tr.code, w.Code)592 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"))594 }595 }596 597 // Test custom not found handler194 unmodified lines