Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linting #851

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: GolangCI-Lint Action
uses: actions-contrib/golangci-lint@v0.1.0
uses: actions-contrib/golangci-lint@v1
with:
golangci_lint_version: v1.28.3
2 changes: 1 addition & 1 deletion allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestAllocationURI(t *testing.T) {

n := testing.AllocsPerRun(100, func() {
u := AcquireURI()
u.Parse(nil, uri)
u.Parse(nil, uri) //nolint:errcheck
ReleaseURI(u)
})

Expand Down
4 changes: 2 additions & 2 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ func testCopyTo(t *testing.T, a *Args) {
var b Args
a.CopyTo(&b)

if !reflect.DeepEqual(*a, b) { //nolint:govet
t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint:govet
if !reflect.DeepEqual(*a, b) { //nolint
t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint
}

b.VisitAll(func(k, v []byte) {
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ func doRequestFollowRedirectsBuffer(req *Request, dst []byte, url string, c clie
oldBody := bodyBuf.B
bodyBuf.B = dst

statusCode, body, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c)
statusCode, _, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c)

body = bodyBuf.B
bodyBuf.B = oldBody
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestClientInvalidURI(t *testing.T) {
atomic.AddInt64(&requests, 1)
},
}
go s.Serve(ln)
go s.Serve(ln) //nolint:errcheck
c := &Client{
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
Expand Down Expand Up @@ -113,10 +113,10 @@ func TestClientGetWithBody(t *testing.T) {
s := &Server{
Handler: func(ctx *RequestCtx) {
body := ctx.Request.Body()
ctx.Write(body)
ctx.Write(body) //nolint:errcheck
},
}
go s.Serve(ln)
go s.Serve(ln) //nolint:errcheck
c := &Client{
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
Expand Down
2 changes: 1 addition & 1 deletion fasthttpadaptor/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value i

func TestContentType(t *testing.T) {
nethttpH := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<!doctype html><html>"))
w.Write([]byte("<!doctype html><html>")) //nolint:errcheck
}
fasthttpH := NewFastHTTPHandler(http.HandlerFunc(nethttpH))

Expand Down
22 changes: 11 additions & 11 deletions fasthttputil/inmemory_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ func TestInmemoryListener(t *testing.T) {
go func(n int) {
conn, err := ln.Dial()
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
defer conn.Close()
req := fmt.Sprintf("request_%d", n)
nn, err := conn.Write([]byte(req))
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
if nn != len(req) {
t.Fatalf("unexpected number of bytes written: %d. Expecting %d", nn, len(req))
t.Errorf("unexpected number of bytes written: %d. Expecting %d", nn, len(req))
}
buf := make([]byte, 30)
nn, err = conn.Read(buf)
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
buf = buf[:nn]
resp := fmt.Sprintf("response_%d", n)
if nn != len(resp) {
t.Fatalf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp))
t.Errorf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp))
}
if string(buf) != resp {
t.Fatalf("unexpected response %q. Expecting %q", buf, resp)
t.Errorf("unexpected response %q. Expecting %q", buf, resp)
}
ch <- struct{}{}
}(i)
Expand All @@ -61,19 +61,19 @@ func TestInmemoryListener(t *testing.T) {
buf := make([]byte, 30)
n, err := conn.Read(buf)
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
buf = buf[:n]
if !bytes.HasPrefix(buf, []byte("request_")) {
t.Fatalf("unexpected request prefix %q. Expecting %q", buf, "request_")
t.Errorf("unexpected request prefix %q. Expecting %q", buf, "request_")
}
resp := fmt.Sprintf("response_%s", buf[len("request_"):])
n, err = conn.Write([]byte(resp))
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
if n != len(resp) {
t.Fatalf("unexpected number of bytes written: %d. Expecting %d", n, len(resp))
t.Errorf("unexpected number of bytes written: %d. Expecting %d", n, len(resp))
}
}
}()
Expand Down Expand Up @@ -129,7 +129,7 @@ func testInmemoryListenerHTTP(t *testing.T, f func(t *testing.T, client *http.Cl

go func() {
if err := server.Serve(ln); err != nil && err != http.ErrServerClosed {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion fasthttputil/inmemory_listener_timing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func benchmarkExt(b *testing.B, h fasthttp.RequestHandler, bc *benchConfig) {
serverLn = tls.NewListener(serverLn, serverTLSConfig)
}
if err := fasthttp.Serve(serverLn, h); err != nil {
b.Fatalf("unexpected error in server: %s", err)
b.Errorf("unexpected error in server: %s", err)
}
close(serverStopCh)
}()
Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func swapResponseBody(a, b *Response) {

// URI returns request URI
func (req *Request) URI() *URI {
req.parseURI()
req.parseURI() //nolint:errcheck
return &req.uri
}

Expand Down
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestFragmentInURIRequest(t *testing.T) {
req.SetRequestURI("https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#events")

var b bytes.Buffer
req.WriteTo(&b)
req.WriteTo(&b) //nolint:errcheck
got := b.String()
expected := "GET /ee/user/project/integrations/webhooks.html HTTP/1.1\r\nHost: docs.gitlab.com\r\n\r\n"

Expand Down
2 changes: 1 addition & 1 deletion reuseport/reuseport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func testNewListener(t *testing.T, network, addr string, serversCount, requestsC
ch := make(chan struct{})
go func() {
if resp, err = ioutil.ReadAll(c); err != nil {
t.Fatalf("%d. unexpected error when reading response: %s", i, err)
t.Errorf("%d. unexpected error when reading response: %s", i, err)
}
close(ch)
}()
Expand Down
10 changes: 8 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,10 @@ func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
if s.tlsConfig == nil {
return errNoCertOrKeyProvided
}
s.tlsConfig.BuildNameToCertificate()

// BuildNameToCertificate has been deprecated since 1.14.
// But since we also support older versions we'll keep this here.
s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck

return s.Serve(
tls.NewListener(ln, s.tlsConfig),
Expand All @@ -1596,7 +1599,10 @@ func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error
if s.tlsConfig == nil {
return errNoCertOrKeyProvided
}
s.tlsConfig.BuildNameToCertificate()

// BuildNameToCertificate has been deprecated since 1.14.
// But since we also support older versions we'll keep this here.
s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck

return s.Serve(
tls.NewListener(ln, s.tlsConfig),
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) {

s := &Server{
Handler: func(ctx *RequestCtx) {
io.WriteString(ctx, "test")
io.WriteString(ctx, "test") //nolint:errcheck
ctx.HijackSetNoResponse(true)
},
}
Expand All @@ -2319,7 +2319,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) {
strings.NewReader(rw.w.String()),
)
resp := AcquireResponse()
resp.Read(bf)
resp.Read(bf) //nolint:errcheck
if got := string(resp.Body()); got != "test" {
t.Errorf(`expected "test", got %q`, got)
}
Expand Down
14 changes: 7 additions & 7 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func testURIAcquireRelease(t *testing.T) {
host := fmt.Sprintf("host.%d.com", i*23)
path := fmt.Sprintf("/foo/%d/bar", i*17)
queryArgs := "?foo=bar&baz=aass"
u.Parse([]byte(host), []byte(path+queryArgs))
u.Parse([]byte(host), []byte(path+queryArgs)) //nolint:errcheck
if string(u.Host()) != host {
t.Fatalf("unexpected host %q. Expecting %q", u.Host(), host)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestURIUpdate(t *testing.T) {

func testURIUpdate(t *testing.T, base, update, result string) {
var u URI
u.Parse(nil, []byte(base))
u.Parse(nil, []byte(base)) //nolint:errcheck
u.Update(update)
s := u.String()
if s != result {
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestURIPathNormalize(t *testing.T) {
}

func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string) {
u.Parse(nil, []byte(requestURI))
u.Parse(nil, []byte(requestURI)) //nolint:errcheck
if string(u.Path()) != expectedPath {
t.Fatalf("Unexpected path %q. Expected %q. requestURI=%q", u.Path(), expectedPath, requestURI)
}
Expand All @@ -201,7 +201,7 @@ func TestURINoNormalization(t *testing.T) {

var u URI
irregularPath := "/aaa%2Fbbb%2F%2E.%2Fxxx"
u.Parse(nil, []byte(irregularPath))
u.Parse(nil, []byte(irregularPath)) //nolint:errcheck
u.DisablePathNormalizing = true
if string(u.RequestURI()) != irregularPath {
t.Fatalf("Unexpected path %q. Expected %q.", u.Path(), irregularPath)
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestURIFullURI(t *testing.T) {

// test with empty args and non-empty query string
var u URI
u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq"))
u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq")) //nolint:errcheck
uri := u.FullURI()
expectedURI := "http://google.com/foo?bar=baz&baraz#qqqq"
if string(uri) != expectedURI {
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestURIParseNilHost(t *testing.T) {

func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI, expectedHash string) {
var u URI
u.Parse(nil, []byte(uri))
u.Parse(nil, []byte(uri)) //nolint:errcheck
if string(u.Scheme()) != expectedScheme {
t.Fatalf("Unexpected scheme %q. Expecting %q for uri %q", u.Scheme(), expectedScheme, uri)
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestURIParse(t *testing.T) {

func testURIParse(t *testing.T, u *URI, host, uri,
expectedURI, expectedHost, expectedPath, expectedPathOriginal, expectedArgs, expectedHash string) {
u.Parse([]byte(host), []byte(uri))
u.Parse([]byte(host), []byte(uri)) //nolint:errcheck

if !bytes.Equal(u.FullURI(), []byte(expectedURI)) {
t.Fatalf("Unexpected uri %q. Expected %q. host=%q, uri=%q", u.FullURI(), expectedURI, host, uri)
Expand Down
4 changes: 2 additions & 2 deletions uri_timing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func BenchmarkURIFullURI(b *testing.B) {

b.RunParallel(func(pb *testing.PB) {
var u URI
u.Parse(host, requestURI)
u.Parse(host, requestURI) //nolint:errcheck
for pb.Next() {
uri := u.FullURI()
if len(uri) != uriLen {
Expand All @@ -43,7 +43,7 @@ func benchmarkURIParse(b *testing.B, host, uri string) {
b.RunParallel(func(pb *testing.PB) {
var u URI
for pb.Next() {
u.Parse(strHost, strURI)
u.Parse(strHost, strURI) //nolint:errcheck
}
})
}