Skip to content

Commit e31bed9

Browse files
committed
build: Enable additional linters and fix issues
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 46837ec commit e31bed9

File tree

17 files changed

+153
-17
lines changed

17 files changed

+153
-17
lines changed

.golangci.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ linters:
2727
- goprintffuncname
2828
- gosmopolitan
2929
- govet
30+
- forcetypeassert
3031
- grouper
3132
- importas
3233
- ineffassign
@@ -47,6 +48,8 @@ linters:
4748
- tagalign
4849
- tagliatelle
4950
- testableexamples
51+
- thelper
52+
- tparallel
5053
- unconvert
5154
- unused
5255
- usestdlibvars
@@ -60,6 +63,13 @@ linters:
6063
- common-false-positives
6164
- legacy
6265
- std-error-handling
66+
67+
settings:
68+
revive:
69+
rules:
70+
- name: var-naming
71+
disabled: true
72+
6373
formatters:
6474
enable:
6575
- gci

embedfs/embed_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func TestOpen(t *testing.T) {
4444

4545
for _, tc := range tests {
4646
t.Run(tc.name, func(t *testing.T) {
47+
t.Parallel()
48+
4749
fs := New(&testdataDir)
4850

4951
var got []byte
@@ -115,6 +117,7 @@ func TestOpenFileFlags(t *testing.T) {
115117

116118
for _, tc := range tests {
117119
t.Run(tc.name, func(t *testing.T) {
120+
t.Parallel()
118121
fs := New(&testdataDir)
119122

120123
_, err := fs.OpenFile(tc.file, tc.flag, 0o700)
@@ -157,6 +160,7 @@ func TestStat(t *testing.T) {
157160

158161
for _, tc := range tests {
159162
t.Run(tc.name, func(t *testing.T) {
163+
t.Parallel()
160164
fs := New(&testdataDir)
161165

162166
fi, err := fs.Stat(tc.name)
@@ -213,6 +217,7 @@ func TestReadDir(t *testing.T) {
213217

214218
for _, tc := range tests {
215219
t.Run(tc.name, func(t *testing.T) {
220+
t.Parallel()
216221
fs := New(tc.fs)
217222

218223
fis, err := fs.ReadDir(tc.path)
@@ -296,6 +301,7 @@ func TestFileSeek(t *testing.T) {
296301

297302
for i, tc := range tests {
298303
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
304+
//nolint:tparallel
299305
_, err = f.Seek(tc.seekOff, tc.seekWhence)
300306
require.NoError(t, err)
301307

@@ -309,6 +315,8 @@ func TestFileSeek(t *testing.T) {
309315
}
310316

311317
func TestJoin(t *testing.T) {
318+
t.Parallel()
319+
312320
tests := []struct {
313321
name string
314322
path []string
@@ -338,6 +346,7 @@ func TestJoin(t *testing.T) {
338346

339347
for _, tc := range tests {
340348
t.Run(tc.name, func(t *testing.T) {
349+
t.Parallel()
341350
fs := New(&empty)
342351

343352
got := fs.Join(tc.path...)

helper/chroot/chroot.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chroot
22

33
import (
4+
"errors"
45
"io/fs"
56
"os"
67
"path/filepath"
@@ -126,7 +127,12 @@ func (fs *ChrootHelper) TempFile(dir, prefix string) (billy.File, error) {
126127
return nil, err
127128
}
128129

129-
f, err := fs.underlying.(billy.TempFile).TempFile(fullpath, prefix)
130+
tf, ok := fs.underlying.(billy.TempFile)
131+
if !ok {
132+
return nil, errors.New("underlying fs does not implement billy.TempFile")
133+
}
134+
135+
f, err := tf.TempFile(fullpath, prefix)
130136
if err != nil {
131137
return nil, err
132138
}
@@ -140,7 +146,11 @@ func (fs *ChrootHelper) ReadDir(path string) ([]fs.DirEntry, error) {
140146
return nil, err
141147
}
142148

143-
return fs.underlying.(billy.Dir).ReadDir(fullpath)
149+
d, ok := fs.underlying.(billy.Dir)
150+
if !ok {
151+
return nil, errors.New("underlying fs does not implement billy.Dir")
152+
}
153+
return d.ReadDir(fullpath)
144154
}
145155

146156
func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
@@ -149,7 +159,11 @@ func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
149159
return err
150160
}
151161

152-
return fs.underlying.(billy.Dir).MkdirAll(fullpath, perm)
162+
d, ok := fs.underlying.(billy.Dir)
163+
if !ok {
164+
return errors.New("underlying fs does not implement billy.Dir")
165+
}
166+
return d.MkdirAll(fullpath, perm)
153167
}
154168

155169
func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
@@ -158,7 +172,11 @@ func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
158172
return nil, err
159173
}
160174

161-
return fs.underlying.(billy.Symlink).Lstat(fullpath)
175+
sl, ok := fs.underlying.(billy.Symlink)
176+
if !ok {
177+
return nil, errors.New("underlying fs does not implement billy.Symlink")
178+
}
179+
return sl.Lstat(fullpath)
162180
}
163181

164182
func (fs *ChrootHelper) Symlink(target, link string) error {
@@ -175,7 +193,11 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
175193
return err
176194
}
177195

178-
return fs.underlying.(billy.Symlink).Symlink(target, link)
196+
sl, ok := fs.underlying.(billy.Symlink)
197+
if !ok {
198+
return errors.New("underlying fs does not implement billy.Symlink")
199+
}
200+
return sl.Symlink(target, link)
179201
}
180202

181203
func (fs *ChrootHelper) Readlink(link string) (string, error) {
@@ -184,7 +206,12 @@ func (fs *ChrootHelper) Readlink(link string) (string, error) {
184206
return "", err
185207
}
186208

187-
target, err := fs.underlying.(billy.Symlink).Readlink(fullpath)
209+
sl, ok := fs.underlying.(billy.Symlink)
210+
if !ok {
211+
return "", errors.New("underlying fs does not implement billy.Symlink")
212+
}
213+
214+
target, err := sl.Readlink(fullpath)
188215
if err != nil {
189216
return "", err
190217
}

helper/chroot/chroot_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func TestCapabilities(t *testing.T) {
353353
}
354354

355355
func testCapabilities(t *testing.T, basic billy.Basic) {
356+
t.Helper()
356357
baseCapabilities := billy.Capabilities(basic)
357358

358359
fs := New(basic, "/foo")

helper/iofs/iofs_test.go

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

1212
billyfs "github.com/go-git/go-billy/v6"
1313
"github.com/go-git/go-billy/v6/memfs"
14+
"github.com/stretchr/testify/require"
1415
)
1516

1617
type errorList interface {
@@ -30,7 +31,7 @@ func TestWithFSTest(t *testing.T) {
3031
}
3132
createdFiles := make([]string, 0, len(files))
3233
for filename, contents := range files {
33-
makeFile(memfs, t, filename, contents)
34+
makeFile(t, memfs, filename, contents)
3435
createdFiles = append(createdFiles, filename)
3536
}
3637

@@ -47,10 +48,11 @@ func TestWithFSTest(t *testing.T) {
4748
func TestDeletes(t *testing.T) {
4849
t.Parallel()
4950
memfs := memfs.New()
50-
iofs := New(memfs).(fs.ReadFileFS)
51+
iofs, ok := New(memfs).(fs.ReadFileFS)
52+
require.True(t, ok)
5153

52-
makeFile(memfs, t, "foo.txt", "hello, world")
53-
makeFile(memfs, t, "deleted", "nothing to see")
54+
makeFile(t, memfs, "foo.txt", "hello, world")
55+
makeFile(t, memfs, "deleted", "nothing to see")
5456

5557
if _, err := iofs.ReadFile("nonexistent"); err == nil {
5658
t.Errorf("expected error for nonexistent file")
@@ -73,7 +75,7 @@ func TestDeletes(t *testing.T) {
7375
}
7476
}
7577

76-
func makeFile(fs billyfs.Basic, t *testing.T, filename string, contents string) {
78+
func makeFile(t *testing.T, fs billyfs.Basic, filename string, contents string) {
7779
t.Helper()
7880
file, err := fs.Create(filename)
7981
if err != nil {

helper/mount/mount.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mount
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"io/fs"
@@ -184,19 +185,37 @@ func (h *Mount) getBasicAndPath(path string) (billy.Basic, string) {
184185
func (h *Mount) getDirAndPath(path string) (billy.Dir, string, error) {
185186
path = cleanPath(path)
186187
if !h.isMountpoint(path) {
187-
return h.underlying.(billy.Dir), path, nil
188+
d, ok := h.underlying.(billy.Dir)
189+
if !ok {
190+
return nil, "", errors.New("underlying fs does not implement billy.Dir")
191+
}
192+
return d, path, nil
188193
}
189194

190-
return h.source.(billy.Dir), h.mustRelToMountpoint(path), nil
195+
d, ok := h.source.(billy.Dir)
196+
if !ok {
197+
return nil, "", errors.New("source fs does not implement billy.Dir")
198+
}
199+
return d, h.mustRelToMountpoint(path), nil
191200
}
192201

193202
func (h *Mount) getSymlinkAndPath(path string) (billy.Symlink, string, error) {
194203
path = cleanPath(path)
195204
if !h.isMountpoint(path) {
196-
return h.underlying.(billy.Symlink), path, nil
205+
sl, ok := h.underlying.(billy.Symlink)
206+
if !ok {
207+
return nil, "", errors.New("underlying fs does not implement billy.Symlink")
208+
}
209+
210+
return sl, path, nil
211+
}
212+
213+
sl, ok := h.source.(billy.Symlink)
214+
if !ok {
215+
return nil, "", errors.New("source fs does not implement billy.Symlink")
197216
}
198217

199-
return h.source.(billy.Symlink), h.mustRelToMountpoint(path), nil
218+
return sl, h.mustRelToMountpoint(path), nil
200219
}
201220

202221
func (h *Mount) mustRelToMountpoint(path string) string {

helper/mount/mount_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func TestCapabilities(t *testing.T) {
377377
}
378378

379379
func testCapabilities(t *testing.T, a, b billy.Basic) {
380+
t.Helper()
380381
aCapabilities := billy.Capabilities(a)
381382
bCapabilities := billy.Capabilities(b)
382383

helper/polyfill/polyfill.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:forcetypeassert
12
package polyfill
23

34
import (

helper/polyfill/polyfill_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func TestCapabilities(t *testing.T) {
5757
}
5858

5959
func testCapabilities(t *testing.T, basic billy.Basic) {
60+
t.Helper()
6061
baseCapabilities := billy.Capabilities(basic)
6162

6263
fs := New(basic)

memfs/memory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ func (fs *Memory) Stat(filename string) (os.FileInfo, error) {
119119
// the name of the file should always the name of the stated file, so we
120120
// overwrite the Stat returned from the storage with it, since the
121121
// filename may belong to a link.
122-
fi.(*fileInfo).name = filepath.Base(filename)
122+
if ffi, ok := fi.(*fileInfo); ok {
123+
ffi.name = filepath.Base(filename)
124+
}
123125
return fi, nil
124126
}
125127

0 commit comments

Comments
 (0)