Skip to content

Commit 77dbb50

Browse files
committed
Upgrade to golangci-lint v2, massive linter clean-up
1 parent d23222e commit 77dbb50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+656
-262
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ jobs:
1717
name: Lint
1818
runs-on: ubuntu-24.04
1919
steps:
20-
- uses: actions/checkout@v4
21-
- uses: actions/setup-go@v5
20+
- uses: actions/checkout@v6
21+
- uses: actions/setup-go@v6
2222
with:
2323
go-version-file: 'go.mod'
2424
- name: "Install libpam"
2525
run: |
2626
sudo apt-get update
2727
sudo apt-get install -y libpam-dev
28-
- uses: golangci/golangci-lint-action@v6
28+
- uses: golangci/golangci-lint-action@v9
2929
with:
30-
version: v1.60
31-
args: "--timeout=30m"
30+
version: v2.11
3231
buildsh:
3332
name: "Verify build.sh"
3433
runs-on: ubuntu-latest
3534
steps:
36-
- uses: actions/checkout@v4
37-
- uses: actions/setup-go@v5
35+
- uses: actions/checkout@v6
36+
- uses: actions/setup-go@v6
3837
with:
3938
go-version-file: 'go.mod'
4039
- name: "Install libpam"
@@ -50,8 +49,8 @@ jobs:
5049
name: "Build and test"
5150
runs-on: ubuntu-latest
5251
steps:
53-
- uses: actions/checkout@v4
54-
- uses: actions/setup-go@v5
52+
- uses: actions/checkout@v6
53+
- uses: actions/setup-go@v6
5554
with:
5655
go-version-file: 'go.mod'
5756
- name: "Install libpam"
@@ -65,11 +64,3 @@ jobs:
6564
run: |
6665
cd tests/
6766
./run.sh
68-
- uses: codecov/codecov-action@v2
69-
with:
70-
files: ./coverage.out
71-
flags: unit
72-
- uses: codecov/codecov-action@v2
73-
with:
74-
files: ./tests/coverage.out
75-
flags: integration

.golangci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
version: "2"
12
linters:
23
enable:
3-
- gosimple
44
- errcheck
55
- staticcheck
66
- ineffassign
7-
- typecheck
87
- govet
98
- unused
10-
- goimports
119
- prealloc
1210
- unconvert
1311
- misspell
1412
- whitespace
1513
- nakedret
1614
- dogsled
1715
- copyloopvar
16+
- sqlclosecheck
17+
- testifylint
18+
- rowserrcheck
19+
- recvcheck
20+
settings:
21+
errcheck:
22+
disable-default-exclusions: false
23+
formatters:
24+
enable:
25+
- goimports

config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ func reinitLogging() {
114114
return
115115
}
116116

117-
out.Close()
117+
if err := out.Close(); err != nil {
118+
log.Println("Can't close logger:", err)
119+
}
118120

119121
log.DefaultLogger.Out = newOut
120122
}

framework/cfgparser/imports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (ctx *parseContext) expandSingleValueMacro(arg string) (string, error) {
169169
value = ctx.macros[macroName][0]
170170
}
171171

172-
arg = strings.Replace(arg, "$("+macroName+")", value, -1)
172+
arg = strings.ReplaceAll(arg, "$("+macroName+")", value)
173173
}
174174

175175
return arg, nil

framework/cfgparser/parse_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"reflect"
2424
"strings"
2525
"testing"
26+
27+
"github.com/stretchr/testify/require"
2628
)
2729

2830
var cases = []struct {
@@ -579,8 +581,8 @@ func printTree(t *testing.T, root Node, indent int) {
579581
}
580582

581583
func TestRead(t *testing.T) {
582-
os.Setenv("TESTING_VARIABLE", "ABCDEF")
583-
os.Setenv("TESTING_VARIABLE2", "ABC2 DEF2")
584+
require.NoError(t, os.Setenv("TESTING_VARIABLE", "ABCDEF"))
585+
require.NoError(t, os.Setenv("TESTING_VARIABLE2", "ABC2 DEF2"))
584586

585587
for _, case_ := range cases {
586588
t.Run(case_.name, func(t *testing.T) {

framework/dns/dnssec_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/foxcpp/maddy/framework/log"
1313
"github.com/miekg/dns"
14+
"github.com/stretchr/testify/require"
1415
)
1516

1617
type TestSrvAction int
@@ -55,8 +56,8 @@ func (s *IPAddrTestServer) Run() {
5556
go s.udpServ.ActivateAndServe() //nolint:errcheck
5657
}
5758

58-
func (s *IPAddrTestServer) Close() {
59-
s.udpServ.PacketConn.Close()
59+
func (s *IPAddrTestServer) Close() error {
60+
return s.udpServ.PacketConn.Close()
6061
}
6162

6263
func (s *IPAddrTestServer) Addr() *net.UDPAddr {
@@ -141,7 +142,9 @@ func TestExtResolver_AuthLookupIPAddr(t *testing.T) {
141142
s.aAD = aAD
142143
s.aaaaAD = aaaaAD
143144
s.Run()
144-
defer s.Close()
145+
defer func() {
146+
require.NoError(t, s.Close())
147+
}()
145148
res := ExtResolver{
146149
cl: new(dns.Client),
147150
Cfg: &dns.ClientConfig{

framework/resource/netresource/fd.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111

1212
func ListenFD(fd uint) (net.Listener, error) {
1313
file := os.NewFile(uintptr(fd), strconv.FormatUint(uint64(fd), 10))
14-
defer file.Close()
14+
defer func() {
15+
if err := file.Close(); err != nil {
16+
panic(err)
17+
}
18+
}()
1519
return net.FileListener(file)
1620
}
1721

@@ -42,6 +46,10 @@ func ListenFDName(name string) (net.Listener, error) {
4246
}
4347

4448
file := os.NewFile(3+fd, name)
45-
defer file.Close()
49+
defer func() {
50+
if err := file.Close(); err != nil {
51+
panic(err)
52+
}
53+
}()
4654
return net.FileListener(file)
4755
}

framework/resource/singleton.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ func (s *Singleton[T]) CloseUnused(isUsed func(key string) bool) error {
5050
if isUsed(key) {
5151
continue
5252
}
53+
if err := res.Close(); err != nil {
54+
s.log.Error("resource close failed", err, "key", key)
55+
}
5356
s.log.DebugMsg("resource released", "key", key)
54-
res.Close()
5557
delete(s.resources, key)
5658
}
5759

@@ -63,8 +65,10 @@ func (s *Singleton[T]) Close() error {
6365
defer s.lock.Unlock()
6466

6567
for key, res := range s.resources {
68+
if err := res.Close(); err != nil {
69+
s.log.Error("resource close failed", err, "key", key)
70+
}
6671
s.log.DebugMsg("resource released", "key", key)
67-
res.Close()
6872
delete(s.resources, key)
6973
}
7074

internal/auth/dovecot_sasl/dovecot_sasl.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func (a *Auth) getConn() (*dovecotsasl.Client, error) {
7777
}
7878

7979
func (a *Auth) returnConn(cl *dovecotsasl.Client) {
80-
cl.Close()
80+
if err := cl.Close(); err != nil {
81+
a.log.Error("connection close failed", err)
82+
}
8183
}
8284

8385
func (a *Auth) Configure(inlineArgs []string, cfg *config.Map) error {
@@ -113,7 +115,11 @@ func (a *Auth) Configure(inlineArgs []string, cfg *config.Map) error {
113115
return fmt.Errorf("%s: unable to contact server: %v", modName, err)
114116
}
115117

116-
defer cl.Close()
118+
defer func() {
119+
if err := cl.Close(); err != nil {
120+
a.log.Error("connection close failed", err)
121+
}
122+
}()
117123
a.mechanisms = make(map[string]dovecotsasl.Mechanism, len(cl.ConnInfo().Mechs))
118124
for name, mech := range cl.ConnInfo().Mechs {
119125
if mech.Private {

internal/auth/ldap/ldap.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func (a *Auth) getConn() (*ldap.Conn, error) {
181181
a.conn = conn
182182
}
183183
if a.conn.IsClosing() {
184-
a.conn.Close()
184+
if err := a.conn.Close(); err != nil {
185+
a.log.Error("Connection close failed", err)
186+
}
185187
conn, err := a.newConn()
186188
if err != nil {
187189
a.connLock.Unlock()
@@ -196,11 +198,15 @@ func (a *Auth) returnConn(conn *ldap.Conn) {
196198
defer a.connLock.Unlock()
197199
if err := a.readBind(conn); err != nil {
198200
a.log.Error("failed to rebind for reading", err)
199-
conn.Close()
201+
if err := a.conn.Close(); err != nil {
202+
a.log.Error("Connection close failed", err)
203+
}
200204
a.conn = nil
201205
}
202206
if a.conn != conn {
203-
a.conn.Close()
207+
if err := a.conn.Close(); err != nil {
208+
a.log.Error("Connection close failed", err)
209+
}
204210
}
205211
a.conn = conn
206212
}
@@ -285,8 +291,7 @@ func (a *Auth) Start() error {
285291
func (a *Auth) Stop() error {
286292
a.connLock.Lock()
287293
defer a.connLock.Unlock()
288-
a.conn.Close()
289-
return nil
294+
return a.conn.Close()
290295
}
291296

292297
func init() {

0 commit comments

Comments
 (0)