Skip to content

Commit

Permalink
Enable perfsprint linter; fix up lint issues (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Mar 2, 2024
1 parent bdd459a commit 7e1fb71
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 25 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ linters:
- noctx
- nonamedreturns
- paralleltest
- perfsprint
- testableexamples
- testpackage
- thelper
Expand Down
4 changes: 2 additions & 2 deletions bytesconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package fasthttp
import (
"bufio"
"bytes"
"fmt"
"html"
"net"
"net/url"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -118,7 +118,7 @@ func testAppendIPv4(t *testing.T, ipStr string, isValid bool) {
}

func testAppendUint(t *testing.T, n int) {
expectedS := fmt.Sprintf("%d", n)
expectedS := strconv.Itoa(n)
s := AppendUint(nil, n)
if string(s) != expectedS {
t.Fatalf("unexpected uint %q. Expecting %q. n=%d", s, expectedS, n)
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ type writeErrorConn struct {
}

func (w *writeErrorConn) Write(p []byte) (int, error) {
return 1, fmt.Errorf("error")
return 1, errors.New("error")
}

func (w *writeErrorConn) Close() error {
Expand Down Expand Up @@ -2286,7 +2286,7 @@ type readErrorConn struct {
}

func (r *readErrorConn) Read(p []byte) (int, error) {
return 0, fmt.Errorf("error")
return 0, errors.New("error")
}

func (r *readErrorConn) Write(p []byte) (int, error) {
Expand Down Expand Up @@ -2849,7 +2849,7 @@ func TestClientConfigureClientFailed(t *testing.T) {

c := &Client{
ConfigureClient: func(hc *HostClient) error {
return fmt.Errorf("failed to configure")
return errors.New("failed to configure")
},
}

Expand Down
3 changes: 2 additions & 1 deletion compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fasthttp

import (
"bytes"
"errors"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -225,7 +226,7 @@ func testConcurrent(concurrency int, f func() error) error {
return err
}
case <-time.After(time.Second):
return fmt.Errorf("timeout")
return errors.New("timeout")
}
}
return nil
Expand Down
18 changes: 9 additions & 9 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ func (h *ResponseHeader) tryRead(r *bufio.Reader, n int) error {
if err == bufio.ErrBufferFull {
if h.secureErrorLogMessage {
return &ErrSmallBuffer{
error: fmt.Errorf("error when reading response headers"),
error: errors.New("error when reading response headers"),
}
}
return &ErrSmallBuffer{
Expand Down Expand Up @@ -2170,7 +2170,7 @@ func (h *ResponseHeader) tryReadTrailer(r *bufio.Reader, n int) error {
if err == bufio.ErrBufferFull {
if h.secureErrorLogMessage {
return &ErrSmallBuffer{
error: fmt.Errorf("error when reading response trailer"),
error: errors.New("error when reading response trailer"),
}
}
return &ErrSmallBuffer{
Expand Down Expand Up @@ -2279,7 +2279,7 @@ func (h *RequestHeader) tryReadTrailer(r *bufio.Reader, n int) error {
if err == bufio.ErrBufferFull {
if h.secureErrorLogMessage {
return &ErrSmallBuffer{
error: fmt.Errorf("error when reading request trailer"),
error: errors.New("error when reading request trailer"),
}
}
return &ErrSmallBuffer{
Expand Down Expand Up @@ -2821,7 +2821,7 @@ func (h *ResponseHeader) parseFirstLine(buf []byte) (int, error) {
n := bytes.IndexByte(b, ' ')
if n < 0 {
if h.secureErrorLogMessage {
return 0, fmt.Errorf("cannot find whitespace in the first line of response")
return 0, errors.New("cannot find whitespace in the first line of response")
}
return 0, fmt.Errorf("cannot find whitespace in the first line of response %q", buf)
}
Expand All @@ -2838,7 +2838,7 @@ func (h *ResponseHeader) parseFirstLine(buf []byte) (int, error) {
}
if len(b) > n && b[n] != ' ' {
if h.secureErrorLogMessage {
return 0, fmt.Errorf("unexpected char at the end of status code")
return 0, errors.New("unexpected char at the end of status code")
}
return 0, fmt.Errorf("unexpected char at the end of status code. Response %q", buf)
}
Expand All @@ -2863,7 +2863,7 @@ func (h *RequestHeader) parseFirstLine(buf []byte) (int, error) {
n := bytes.IndexByte(b, ' ')
if n <= 0 {
if h.secureErrorLogMessage {
return 0, fmt.Errorf("cannot find http request method")
return 0, errors.New("cannot find http request method")
}
return 0, fmt.Errorf("cannot find http request method in %q", buf)
}
Expand All @@ -2876,7 +2876,7 @@ func (h *RequestHeader) parseFirstLine(buf []byte) (int, error) {
return 0, fmt.Errorf("cannot find whitespace in the first line of request %q", buf)
} else if n == 0 {
if h.secureErrorLogMessage {
return 0, fmt.Errorf("requestURI cannot be empty")
return 0, errors.New("requestURI cannot be empty")
}
return 0, fmt.Errorf("requestURI cannot be empty in %q", buf)
}
Expand Down Expand Up @@ -3067,7 +3067,7 @@ func (h *RequestHeader) parseHeaders(buf []byte) (int, error) {
}
if caseInsensitiveCompare(s.key, strContentLength) {
if contentLengthSeen {
return 0, fmt.Errorf("duplicate Content-Length header")
return 0, errors.New("duplicate Content-Length header")
}
contentLengthSeen = true

Expand Down Expand Up @@ -3100,7 +3100,7 @@ func (h *RequestHeader) parseHeaders(buf []byte) (int, error) {

if !isIdentity && !isChunked {
if h.secureErrorLogMessage {
return 0, fmt.Errorf("unsupported Transfer-Encoding")
return 0, errors.New("unsupported Transfer-Encoding")
}
return 0, fmt.Errorf("unsupported Transfer-Encoding: %q", s.value)
}
Expand Down
7 changes: 4 additions & 3 deletions header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net/http"
"reflect"
"strconv"
"strings"
"testing"
)
Expand Down Expand Up @@ -454,7 +455,7 @@ func TestResponseHeaderAdd(t *testing.T) {
m["bbb"] = struct{}{}
m["xxx"] = struct{}{}
for i := 0; i < 10; i++ {
v := fmt.Sprintf("%d", i)
v := strconv.Itoa(i)
h.Add("Foo-Bar", v)
m[v] = struct{}{}
}
Expand Down Expand Up @@ -507,7 +508,7 @@ func TestRequestHeaderAdd(t *testing.T) {
m["bbb"] = struct{}{}
m["xxx"] = struct{}{}
for i := 0; i < 10; i++ {
v := fmt.Sprintf("%d", i)
v := strconv.Itoa(i)
h.Add("Foo-Bar", v)
m[v] = struct{}{}
}
Expand Down Expand Up @@ -1294,7 +1295,7 @@ func TestResponseHeaderFirstByteReadEOF(t *testing.T) {

var h ResponseHeader

r := &errorReader{fmt.Errorf("non-eof error")}
r := &errorReader{errors.New("non-eof error")}
br := bufio.NewReader(r)
err := h.Read(br)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ func (req *Request) Write(w *bufio.Writer) error {
_, err = w.Write(body)
} else if len(body) > 0 {
if req.secureErrorLogMessage {
return fmt.Errorf("non-zero body for non-POST request")
return errors.New("non-zero body for non-POST request")
}
return fmt.Errorf("non-zero body for non-POST request. body=%q", body)
}
Expand Down Expand Up @@ -2379,7 +2379,7 @@ func readBodyChunked(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, erro
}
if !bytes.Equal(dst[len(dst)-strCRLFLen:], strCRLF) {
return dst, ErrBrokenChunk{
error: fmt.Errorf("cannot find crlf at the end of chunk"),
error: errors.New("cannot find crlf at the end of chunk"),
}
}
dst = dst[:len(dst)-strCRLFLen]
Expand Down
6 changes: 3 additions & 3 deletions stackless/func_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package stackless

import (
"fmt"
"errors"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestNewFuncMulti(t *testing.T) {
var err error
for i := 0; i < iterations; i++ {
if !f1(3) {
err = fmt.Errorf("f1 mustn't return false")
err = errors.New("f1 mustn't return false")
break
}
}
Expand All @@ -56,7 +56,7 @@ func TestNewFuncMulti(t *testing.T) {
var err error
for i := 0; i < iterations; i++ {
if !f2(5) {
err = fmt.Errorf("f2 mustn't return false")
err = errors.New("f2 mustn't return false")
break
}
}
Expand Down
3 changes: 2 additions & 1 deletion stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fasthttp

import (
"bufio"
"errors"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestStreamReaderClose(t *testing.T) {
w.Write(data) //nolint:errcheck
}
if err := w.Flush(); err == nil {
ch <- fmt.Errorf("expecting error on the second flush")
ch <- errors.New("expecting error on the second flush")
}
ch <- nil
})
Expand Down

0 comments on commit 7e1fb71

Please sign in to comment.