Skip to content

Commit 934f04e

Browse files
authored
Refactor golangci-lint config and remove redundant nolints (valyala#1486)
* Refactor golangci-lint config - Use golangci-lint-action for GitHub workflow. - Add additional golangci-lint run options. - Remove unused nolint directives. * Revert exclude-use-default option
1 parent f84e234 commit 934f04e

File tree

15 files changed

+37
-64
lines changed

15 files changed

+37
-64
lines changed

Diff for: .github/workflows/lint.yml

+4-31
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,10 @@ jobs:
1212
- uses: actions/setup-go@v3
1313
with:
1414
go-version: 1.20.x
15-
16-
- name: Get Go cache paths
17-
id: go-env
18-
run: |
19-
echo "::set-output name=cache::$(go env GOCACHE)"
20-
echo "::set-output name=modcache::$(go env GOMODCACHE)"
21-
- name: Set up Go cache
22-
uses: actions/cache@v3
23-
with:
24-
key: golangci-lint-${{ runner.os }}-go-${{ hashFiles('go.mod') }}
25-
restore-keys: golangci-lint-${{ runner.os }}-go-
26-
path: |
27-
${{ steps.go-env.outputs.cache }}
28-
${{ steps.go-env.outputs.modcache }}
29-
30-
- name: Install golangci-lint
31-
run: go install github.com/golangci/golangci-lint/cmd/[email protected]
32-
33-
- name: Get golangci-lint cache path
34-
id: golangci-lint-cache-status
35-
run: |
36-
echo "::set-output name=dir::$(golangci-lint cache status | head -1 | sed 's/^Dir: //')"
37-
38-
- name: Set up golangci-lint cache
39-
uses: actions/cache@v3
40-
with:
41-
key: golangci-lint-${{ runner.os }}-golangci-lint-${{ hashFiles('go.mod') }}
42-
restore-keys: golangci-lint-${{ runner.os }}-golangci-lint-
43-
path: ${{ steps.golangci-lint-cache-status.outputs.dir }}
44-
4515
- run: go version
4616
- run: diff -u <(echo -n) <(gofmt -d .)
4717
- name: Run golangci-lint
48-
run: golangci-lint run
18+
uses: golangci/golangci-lint-action@v3
19+
with:
20+
version: v1.51.1
21+
args: --enable=nolintlint --enable=gochecknoinits --verbose

Diff for: args.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var argsPool = &sync.Pool{
4444
//
4545
// Args instance MUST NOT be used from concurrently running goroutines.
4646
type Args struct {
47-
noCopy noCopy //nolint:unused,structcheck
47+
noCopy noCopy
4848

4949
args []argsKV
5050
buf []byte

Diff for: args_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ func testCopyTo(t *testing.T, a *Args) {
336336
var b Args
337337
a.CopyTo(&b)
338338

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

343343
b.VisitAll(func(k, _ []byte) {

Diff for: client.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ var defaultClient Client
179179
//
180180
// The fields of a Client should not be changed while it is in use.
181181
type Client struct {
182-
noCopy noCopy //nolint:unused,structcheck
182+
noCopy noCopy
183183

184184
// Client name. Used in User-Agent request header.
185185
//
@@ -642,7 +642,7 @@ const (
642642
//
643643
// It is safe calling HostClient methods from concurrently running goroutines.
644644
type HostClient struct {
645-
noCopy noCopy //nolint:unused,structcheck
645+
noCopy noCopy
646646

647647
// Comma-separated list of upstream HTTP server host addresses,
648648
// which are passed to Dial in a round-robin manner.
@@ -2165,7 +2165,7 @@ func (q *wantConnQueue) clearFront() (cleaned bool) {
21652165
// It is safe calling PipelineClient methods from concurrently running
21662166
// goroutines.
21672167
type PipelineClient struct {
2168-
noCopy noCopy //nolint:unused,structcheck
2168+
noCopy noCopy
21692169

21702170
// Address of the host to connect to.
21712171
Addr string
@@ -2279,7 +2279,7 @@ type PipelineClient struct {
22792279
}
22802280

22812281
type pipelineConnClient struct {
2282-
noCopy noCopy //nolint:unused,structcheck
2282+
noCopy noCopy
22832283

22842284
Addr string
22852285
Name string

Diff for: cookie.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var cookiePool = &sync.Pool{
6565
//
6666
// Cookie instance MUST NOT be used from concurrently running goroutines.
6767
type Cookie struct {
68-
noCopy noCopy //nolint:unused,structcheck
68+
noCopy noCopy
6969

7070
key []byte
7171
value []byte

Diff for: fasthttpadaptor/adaptor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestNewFastHTTPHandler(t *testing.T) {
102102
req.Header.SetMethod(expectedMethod)
103103
req.SetRequestURI(expectedRequestURI)
104104
req.Header.SetHost(expectedHost)
105-
req.BodyWriter().Write([]byte(expectedBody)) // nolint:errcheck
105+
req.BodyWriter().Write([]byte(expectedBody)) //nolint:errcheck
106106
for k, v := range expectedHeader {
107107
req.Header.Set(k, v)
108108
}

Diff for: fasthttputil/inmemory_listener.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (ln *InmemoryListener) DialWithLocalAddr(local net.Addr) (net.Conn, error)
121121
// Wait until the connection has been accepted.
122122
<-accepted
123123
} else {
124-
sConn.Close() //nolint:errcheck
125-
cConn.Close() //nolint:errcheck
124+
_ = sConn.Close()
125+
_ = cConn.Close()
126126
cConn = nil
127127
}
128128
ln.lock.Unlock()

Diff for: fs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func NewPathPrefixStripper(prefixSize int) PathRewriteFunc {
223223
//
224224
// It is prohibited copying FS values. Create new values instead.
225225
type FS struct {
226-
noCopy noCopy //nolint:unused,structcheck
226+
noCopy noCopy
227227

228228
// Path to the root directory to serve files from.
229229
Root string

Diff for: header.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// ResponseHeader instance MUST NOT be used from concurrently running
2525
// goroutines.
2626
type ResponseHeader struct {
27-
noCopy noCopy //nolint:unused,structcheck
27+
noCopy noCopy
2828

2929
disableNormalizing bool
3030
noHTTP11 bool
@@ -59,7 +59,7 @@ type ResponseHeader struct {
5959
// RequestHeader instance MUST NOT be used from concurrently running
6060
// goroutines.
6161
type RequestHeader struct {
62-
noCopy noCopy //nolint:unused,structcheck
62+
noCopy noCopy
6363

6464
disableNormalizing bool
6565
noHTTP11 bool

Diff for: http.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func SetBodySizePoolLimit(reqBodyLimit, respBodyLimit int) {
3737
//
3838
// Request instance MUST NOT be used from concurrently running goroutines.
3939
type Request struct {
40-
noCopy noCopy //nolint:unused,structcheck
40+
noCopy noCopy
4141

4242
// Request header
4343
//
@@ -81,7 +81,7 @@ type Request struct {
8181
//
8282
// Response instance MUST NOT be used from concurrently running goroutines.
8383
type Response struct {
84-
noCopy noCopy //nolint:unused,structcheck
84+
noCopy noCopy
8585

8686
// Response header
8787
//

Diff for: http_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1370,10 +1370,10 @@ func TestResponseGzipStream(t *testing.T) {
13701370
fmt.Fprintf(w, "foo")
13711371
w.Flush()
13721372
time.Sleep(time.Millisecond)
1373-
w.Write([]byte("barbaz")) //nolint:errcheck
1374-
w.Flush() //nolint:errcheck
1373+
_, _ = w.Write([]byte("barbaz"))
1374+
_ = w.Flush()
13751375
time.Sleep(time.Millisecond)
1376-
fmt.Fprintf(w, "1234") //nolint:errcheck
1376+
_, _ = fmt.Fprintf(w, "1234")
13771377
if err := w.Flush(); err != nil {
13781378
t.Fatalf("unexpected error: %v", err)
13791379
}
@@ -1392,11 +1392,11 @@ func TestResponseDeflateStream(t *testing.T) {
13921392
t.Fatalf("IsBodyStream must return false")
13931393
}
13941394
r.SetBodyStreamWriter(func(w *bufio.Writer) {
1395-
w.Write([]byte("foo")) //nolint:errcheck
1396-
w.Flush() //nolint:errcheck
1397-
fmt.Fprintf(w, "barbaz") //nolint:errcheck
1398-
w.Flush() //nolint:errcheck
1399-
w.Write([]byte("1234")) //nolint:errcheck
1395+
_, _ = w.Write([]byte("foo"))
1396+
_ = w.Flush()
1397+
_, _ = fmt.Fprintf(w, "barbaz")
1398+
_ = w.Flush()
1399+
_, _ = w.Write([]byte("1234"))
14001400
if err := w.Flush(); err != nil {
14011401
t.Fatalf("unexpected error: %v", err)
14021402
}

Diff for: lbclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type BalancingClient interface {
2525
//
2626
// It is safe calling LBClient methods from concurrently running goroutines.
2727
type LBClient struct {
28-
noCopy noCopy //nolint:unused,structcheck
28+
noCopy noCopy
2929

3030
// Clients must contain non-zero clients list.
3131
// Incoming requests are balanced among these clients.

Diff for: nocopy.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package fasthttp
55
//
66
// See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details.
77
// and also: https://stackoverflow.com/questions/52494458/nocopy-minimal-example
8-
type noCopy struct{} //nolint:unused
8+
type noCopy struct{}
99

10-
func (*noCopy) Lock() {} //nolint:unused
11-
func (*noCopy) Unlock() {} //nolint:unused
10+
func (*noCopy) Lock() {}
11+
func (*noCopy) Unlock() {}

Diff for: server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type ServeHandler func(c net.Conn) error
148148
//
149149
// It is safe to call Server methods from concurrently running goroutines.
150150
type Server struct {
151-
noCopy noCopy //nolint:unused,structcheck
151+
noCopy noCopy
152152

153153
// Handler for processing incoming requests.
154154
//
@@ -577,7 +577,7 @@ func CompressHandlerBrotliLevel(h RequestHandler, brotliLevel, otherLevel int) R
577577
// running goroutines. The only exception is TimeoutError*, which may be called
578578
// while other goroutines accessing RequestCtx.
579579
type RequestCtx struct {
580-
noCopy noCopy //nolint:unused,structcheck
580+
noCopy noCopy
581581

582582
// Incoming request.
583583
//
@@ -1950,12 +1950,12 @@ func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.
19501950

19511951
if tc, ok := c.(*net.TCPConn); ok && s.TCPKeepalive {
19521952
if err := tc.SetKeepAlive(s.TCPKeepalive); err != nil {
1953-
tc.Close() //nolint:errcheck
1953+
_ = tc.Close()
19541954
return nil, err
19551955
}
19561956
if s.TCPKeepalivePeriod > 0 {
19571957
if err := tc.SetKeepAlivePeriod(s.TCPKeepalivePeriod); err != nil {
1958-
tc.Close() //nolint:errcheck
1958+
_ = tc.Close()
19591959
return nil, err
19601960
}
19611961
}

Diff for: uri.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var uriPool = &sync.Pool{
4040
//
4141
// URI instance MUST NOT be used from concurrently running goroutines.
4242
type URI struct {
43-
noCopy noCopy //nolint:unused,structcheck
43+
noCopy noCopy
4444

4545
pathOriginal []byte
4646
scheme []byte

0 commit comments

Comments
 (0)