Skip to content

Commit c94b6a1

Browse files
authored
fix: lint issues, modernize codebase (#922)
1 parent a543547 commit c94b6a1

File tree

14 files changed

+119
-110
lines changed

14 files changed

+119
-110
lines changed

.golangci.yml

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,56 @@
1+
version: "2"
12
run:
2-
go: "1.20"
3-
timeout: 5m
3+
go: "1.24"
44
linters:
55
enable:
6+
- depguard
7+
- forbidigo
8+
- misspell
9+
- revive
10+
- tagliatelle
11+
- testifylint
612
- thelper
7-
- gofumpt
813
- tparallel
914
- unconvert
15+
- usetesting
1016
- unparam
1117
- wastedassign
12-
- revive
13-
- forbidigo
14-
- tagliatelle
15-
- misspell
16-
- depguard
17-
- testifylint
18-
linters-settings:
19-
forbidigo:
20-
forbid:
21-
- 'ioutil\.*'
22-
tagliatelle:
23-
case:
24-
use-field-name: false
18+
settings:
19+
depguard:
2520
rules:
26-
yaml: snake
27-
json: snake
28-
depguard:
29-
rules:
30-
main:
31-
deny:
32-
- pkg: "github.com/pkg/errors"
33-
desc: "use stdlib instead"
34-
testifylint:
35-
disable:
36-
- encoded-compare
21+
main:
22+
deny:
23+
- pkg: github.com/pkg/errors
24+
desc: use stdlib instead
25+
forbidigo:
26+
forbid:
27+
- pattern: ioutil\.*
28+
tagliatelle:
29+
case:
30+
rules:
31+
json: snake
32+
yaml: snake
33+
use-field-name: false
34+
testifylint:
35+
disable:
36+
- encoded-compare
37+
exclusions:
38+
generated: lax
39+
presets:
40+
- comments
41+
- common-false-positives
42+
- legacy
43+
- std-error-handling
44+
paths:
45+
- third_party$
46+
- builtin$
47+
- examples$
48+
formatters:
49+
enable:
50+
- gofumpt
51+
exclusions:
52+
generated: lax
53+
paths:
54+
- third_party$
55+
- builtin$
56+
- examples$

arch/arch.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"io"
1212
"os"
13+
"slices"
1314
"strconv"
1415
"strings"
1516
"time"
@@ -107,12 +108,7 @@ func mapValidChar(r rune) rune {
107108

108109
// isOneOf checks whether a rune is one of the runes in rr
109110
func isOneOf(r rune, rr ...rune) bool {
110-
for _, char := range rr {
111-
if r == char {
112-
return true
113-
}
114-
}
115-
return false
111+
return slices.Contains(rr, r)
116112
}
117113

118114
// Package writes a new archlinux package to the given writer using the given info.

deb/deb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,15 @@ func createControl(instSize int64, md5sums []byte, info *nfpm.Info) (controlTarG
607607
mode: 0o755,
608608
},
609609
"rules": {
610-
fileName: info.Overridables.Deb.Scripts.Rules,
610+
fileName: info.Deb.Scripts.Rules,
611611
mode: 0o755,
612612
},
613613
"templates": {
614-
fileName: info.Overridables.Deb.Scripts.Templates,
614+
fileName: info.Deb.Scripts.Templates,
615615
mode: 0o644,
616616
},
617617
"config": {
618-
fileName: info.Overridables.Deb.Scripts.Config,
618+
fileName: info.Deb.Scripts.Config,
619619
mode: 0o755,
620620
},
621621
}

deprecation/deprecation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func Println(s string) {
2626
}
2727

2828
// Printf printfs the given string to the Noticer.
29-
func Printf(format string, a ...interface{}) {
29+
func Printf(format string, a ...any) {
3030
fmt.Fprintf(Noticer, format, a...)
3131
}

files/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (c *Content) IsDir() bool {
187187
}
188188

189189
// Sys to part of the os.FileInfo interface
190-
func (c *Content) Sys() interface{} {
190+
func (c *Content) Sys() any {
191191
return nil
192192
}
193193

files/files_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ contents:
282282
errs := make(chan error, 10)
283283
t.Cleanup(func() { close(errs) })
284284
var wg sync.WaitGroup
285-
for i := 0; i < 10; i++ {
285+
for range 10 {
286286
wg.Add(1)
287287
go func() {
288288
defer wg.Done()
@@ -298,7 +298,7 @@ contents:
298298
}
299299
wg.Wait()
300300

301-
for i := 0; i < 10; i++ {
301+
for range 10 {
302302
require.NoError(t, <-errs)
303303
}
304304
}

files/fs.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package files
22

3+
import "slices"
4+
35
func ownedByFilesystem(path string) bool {
46
p := ToNixPath(path)
5-
for _, pp := range append(fsPaths, logrotatePaths...) {
6-
if p == pp {
7-
return true
8-
}
9-
}
10-
return false
7+
return slices.Contains(append(fsPaths, logrotatePaths...), p)
118
}
129

1310
// yum install yum-utils

internal/glob/glob.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ func longestCommonPrefix(strs []string) string {
2929
}
3030

3131
func strlcp(a, b string) string {
32-
var min int
33-
if len(a) > len(b) {
34-
min = len(b)
35-
} else {
36-
min = len(a)
37-
}
38-
for i := 0; i < min; i++ {
32+
minlen := min(len(a), len(b))
33+
for i := range minlen {
3934
if a[i] != b[i] {
4035
return a[0:i]
4136
}
4237
}
43-
return a[0:min]
38+
return a[0:minlen]
4439
}
4540

4641
// ErrGlobNoMatch happens when no files matched the given glob.

internal/glob/glob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestLongestCommonPrefix(t *testing.T) {
2222

2323
empty := []string{}
2424
lcp2 := longestCommonPrefix(empty)
25-
require.Equal(t, "", lcp2)
25+
require.Empty(t, lcp2)
2626

2727
unique := []string{
2828
"every",
@@ -35,7 +35,7 @@ func TestLongestCommonPrefix(t *testing.T) {
3535
}
3636

3737
lcp3 := longestCommonPrefix(unique)
38-
require.Equal(t, "", lcp3)
38+
require.Empty(t, lcp3)
3939
}
4040

4141
func TestGlob(t *testing.T) {

internal/sign/pgp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func readSigningKey(keyFile, passphrase string) (*openpgp.Entity, error) {
254254
}
255255

256256
func isASCII(s []byte) bool {
257-
for i := 0; i < len(s); i++ {
257+
for i := range s {
258258
if s[i] > unicode.MaxASCII {
259259
return false
260260
}

0 commit comments

Comments
 (0)