Skip to content

Commit d483ba0

Browse files
committed
Fix issues found by linters
Signed-off-by: Chris Koch <[email protected]>
1 parent fd995d2 commit d483ba0

12 files changed

+61
-45
lines changed

cp/cmp/cmp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/u-root/uio/uio"
1919
)
2020

21-
// isEqualFile compare two files by checksum
21+
// isEqualFile compare two files by checksum.
2222
func isEqualFile(fpath1, fpath2 string) error {
2323
file1, err := os.Open(fpath1)
2424
if err != nil {
@@ -56,7 +56,7 @@ func stat(o cp.Options, path string) (os.FileInfo, error) {
5656
return os.Stat(path)
5757
}
5858

59-
// IsEqualTree compare the content in the file trees in src and dst paths
59+
// IsEqualTree compare the content in the file trees in src and dst paths.
6060
func IsEqualTree(o cp.Options, src, dst string) error {
6161
srcInfo, err := stat(o, src)
6262
if err != nil {

cp/cp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestCopySimple(t *testing.T) {
9999
t.Errorf("Test %q failed. Want: %q, Got: %q", tt.name, tt.wantErr, err)
100100
}
101101
})
102-
//After every test with NoFollowSymlink we have to delete the created symlink
102+
// After every test with NoFollowSymlink we have to delete the created symlink.
103103
if strings.Contains(tt.dstfile, "symlink") {
104104
os.Remove(tt.dstfile)
105105
}
@@ -109,7 +109,7 @@ func TestCopySimple(t *testing.T) {
109109
t.Errorf("%q failed. Want: %q, Got: %q", tt.name, tt.wantErr, err)
110110
}
111111
})
112-
//After every test with NoFollowSymlink we have to delete the created symlink
112+
// After every test with NoFollowSymlink we have to delete the created symlink.
113113
if strings.Contains(tt.dstfile, "symlink") {
114114
os.Remove(tt.dstfile)
115115
}
@@ -119,7 +119,7 @@ func TestCopySimple(t *testing.T) {
119119
t.Errorf("Test %q failed. Want: %q, Got: %q", tt.name, tt.wantErr, err)
120120
}
121121
})
122-
//After every test with NoFollowSymlink we have to delete the created symlink
122+
// After every test with NoFollowSymlink we have to delete the created symlink.
123123
if strings.Contains(tt.dstfile, "symlink") {
124124
os.Remove(tt.dstfile)
125125
}
@@ -129,7 +129,7 @@ func TestCopySimple(t *testing.T) {
129129
t.Errorf("Test %q failed. Want: %q, Got: %q", tt.name, tt.wantErr, err)
130130
}
131131
})
132-
//After every test with NoFollowSymlink we have to delete the created symlink
132+
// After every test with NoFollowSymlink we have to delete the created symlink.
133133
if strings.Contains(tt.dstfile, "symlink") {
134134
os.Remove(tt.dstfile)
135135
}

rand/random.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type contextReader interface {
4343
// ctxReader takes a contextReader and turns it into a ContextReader.
4444
type ctxReader struct {
4545
contextReader
46-
ctx context.Context
46+
ctx context.Context //nolint:containedctx
4747
}
4848

4949
func (cr ctxReader) Read(b []byte) (int, error) {

rand/random_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (r *getrandomReader) ReadContext(ctx context.Context, b []byte) (int, error
4949
// initialized.
5050
n, err := unix.Getrandom(b, unix.GRND_NONBLOCK)
5151
if err == nil {
52-
return n, err
52+
return n, nil
5353
}
5454
select {
5555
case <-ctx.Done():

rand/random_urandom.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r *urandomReader) ReadContext(ctx context.Context, b []byte) (int, error)
4545
for {
4646
n, err := unix.Read(r.fd, b)
4747
if err == nil {
48-
return n, err
48+
return n, nil
4949
}
5050
select {
5151
case <-ctx.Done():

uio/archivereader_test.go

+37-26
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func randomString(l int) string {
6767
rand.Seed(time.Now().UnixNano())
6868
r := make([]byte, l)
6969
for i := 0; i < l; i++ {
70-
r[i] = byte(choices[rand.Intn(len(choices))])
70+
r[i] = choices[rand.Intn(len(choices))]
7171
}
7272
return string(r)
7373
}
@@ -114,31 +114,27 @@ type archiveReaderLZ4Case struct {
114114
func TestArchiveReaderLZ4(t *testing.T) {
115115
for _, tt := range []archiveReaderLZ4Case{
116116
{
117-
name: "non-legacy regular",
118-
setup: func(w io.Writer) *lz4.Writer {
119-
return lz4.NewWriter(w)
120-
},
117+
name: "non-legacy regular",
118+
setup: lz4.NewWriter,
121119
dataStr: randomString(1024),
122120
},
123121
{
124-
name: "non-legacy larger data",
125-
setup: func(w io.Writer) *lz4.Writer {
126-
return lz4.NewWriter(w)
127-
},
122+
name: "non-legacy larger data",
123+
setup: lz4.NewWriter,
128124
dataStr: randomString(5 * 1024),
129125
},
130126
{
131-
name: "non-legacy short data", // Likley not realistic for most cases in the real world.
132-
setup: func(w io.Writer) *lz4.Writer {
133-
return lz4.NewWriter(w)
134-
},
127+
name: "non-legacy short data", // Likley not realistic for most cases in the real world.
128+
setup: lz4.NewWriter,
135129
dataStr: randomString(100), // Smaller than pre-read size, 1024 bytes.
136130
},
137131
{
138132
name: "legacy regular",
139133
setup: func(w io.Writer) *lz4.Writer {
140134
lz4w := lz4.NewWriter(w)
141-
lz4w.Apply(lz4.LegacyOption(true))
135+
if err := lz4w.Apply(lz4.LegacyOption(true)); err != nil {
136+
t.Fatal(err)
137+
}
142138
return lz4w
143139
},
144140
dataStr: randomString(1024),
@@ -147,7 +143,9 @@ func TestArchiveReaderLZ4(t *testing.T) {
147143
name: "legacy larger data",
148144
setup: func(w io.Writer) *lz4.Writer {
149145
lz4w := lz4.NewWriter(w)
150-
lz4w.Apply(lz4.LegacyOption(true))
146+
if err := lz4w.Apply(lz4.LegacyOption(true)); err != nil {
147+
t.Fatal(err)
148+
}
151149
return lz4w
152150
},
153151
dataStr: randomString(5 * 1024),
@@ -156,7 +154,9 @@ func TestArchiveReaderLZ4(t *testing.T) {
156154
name: "legacy small data",
157155
setup: func(w io.Writer) *lz4.Writer {
158156
lz4w := lz4.NewWriter(w)
159-
lz4w.Apply(lz4.LegacyOption(true))
157+
if err := lz4w.Apply(lz4.LegacyOption(true)); err != nil {
158+
t.Fatal(err)
159+
}
160160
return lz4w
161161
},
162162
dataStr: randomString(100), // Smaller than pre-read size, 1024 bytes..
@@ -165,7 +165,9 @@ func TestArchiveReaderLZ4(t *testing.T) {
165165
name: "legacy small data",
166166
setup: func(w io.Writer) *lz4.Writer {
167167
lz4w := lz4.NewWriter(w)
168-
lz4w.Apply(lz4.LegacyOption(true))
168+
if err := lz4w.Apply(lz4.LegacyOption(true)); err != nil {
169+
t.Fatal(err)
170+
}
169171
return lz4w
170172
},
171173
dataStr: randomString(100), // Smaller than pre-read size, 1024 bytes..
@@ -174,7 +176,9 @@ func TestArchiveReaderLZ4(t *testing.T) {
174176
name: "regular larger data with fast compression",
175177
setup: func(w io.Writer) *lz4.Writer {
176178
lz4w := lz4.NewWriter(w)
177-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Fast))
179+
if err := lz4w.Apply(lz4.CompressionLevelOption(lz4.Fast)); err != nil {
180+
t.Fatal(err)
181+
}
178182
return lz4w
179183
},
180184
dataStr: randomString(5 * 1024),
@@ -183,8 +187,9 @@ func TestArchiveReaderLZ4(t *testing.T) {
183187
name: "legacy larger data with fast compression",
184188
setup: func(w io.Writer) *lz4.Writer {
185189
lz4w := lz4.NewWriter(w)
186-
lz4w.Apply(lz4.LegacyOption(true))
187-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Fast))
190+
if err := lz4w.Apply(lz4.LegacyOption(true), lz4.CompressionLevelOption(lz4.Fast)); err != nil {
191+
t.Fatal(err)
192+
}
188193
return lz4w
189194
},
190195
dataStr: randomString(5 * 1024),
@@ -202,7 +207,9 @@ func TestArchiveReaderLZ4SlowCompressed(t *testing.T) {
202207
name: "regular larger data with medium compression",
203208
setup: func(w io.Writer) *lz4.Writer {
204209
lz4w := lz4.NewWriter(w)
205-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Level5))
210+
if err := lz4w.Apply(lz4.CompressionLevelOption(lz4.Level5)); err != nil {
211+
t.Fatal(err)
212+
}
206213
return lz4w
207214
},
208215
dataStr: randomString(5 * 1024),
@@ -211,7 +218,9 @@ func TestArchiveReaderLZ4SlowCompressed(t *testing.T) {
211218
name: "regular larger data with slow compression",
212219
setup: func(w io.Writer) *lz4.Writer {
213220
lz4w := lz4.NewWriter(w)
214-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Level9))
221+
if err := lz4w.Apply(lz4.CompressionLevelOption(lz4.Level9)); err != nil {
222+
t.Fatal(err)
223+
}
215224
return lz4w
216225
},
217226
dataStr: randomString(5 * 1024),
@@ -220,8 +229,9 @@ func TestArchiveReaderLZ4SlowCompressed(t *testing.T) {
220229
name: "legacy larger data with medium compression",
221230
setup: func(w io.Writer) *lz4.Writer {
222231
lz4w := lz4.NewWriter(w)
223-
lz4w.Apply(lz4.LegacyOption(true))
224-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Level5))
232+
if err := lz4w.Apply(lz4.LegacyOption(true), lz4.CompressionLevelOption(lz4.Level5)); err != nil {
233+
t.Fatal(err)
234+
}
225235
return lz4w
226236
},
227237
dataStr: randomString(5 * 1024),
@@ -230,8 +240,9 @@ func TestArchiveReaderLZ4SlowCompressed(t *testing.T) {
230240
name: "legacy larger data with slow compression",
231241
setup: func(w io.Writer) *lz4.Writer {
232242
lz4w := lz4.NewWriter(w)
233-
lz4w.Apply(lz4.LegacyOption(true))
234-
lz4w.Apply(lz4.CompressionLevelOption(lz4.Level9))
243+
if err := lz4w.Apply(lz4.LegacyOption(true), lz4.CompressionLevelOption(lz4.Level9)); err != nil {
244+
t.Fatal(err)
245+
}
235246
return lz4w
236247
},
237248
dataStr: randomString(5 * 1024),

uio/buffer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (l *Lexer) Read8() uint8 {
224224
if v == nil {
225225
return 0
226226
}
227-
return uint8(v[0])
227+
return v[0]
228228
}
229229

230230
// Read16 reads a 16-bit value from the Buffer.
@@ -319,7 +319,7 @@ func (l *Lexer) WriteData(data interface{}) {
319319
//
320320
// If an error occurred, Error() will return a non-nil error.
321321
func (l *Lexer) Write8(v uint8) {
322-
l.append(1)[0] = byte(v)
322+
l.append(1)[0] = v
323323
}
324324

325325
// Write16 writes a 16-bit value to the Buffer.

uio/null.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var blackHolePool = sync.Pool{
4040

4141
func (devNull) ReadFrom(r io.Reader) (n int64, err error) {
4242
bufp := blackHolePool.Get().(*[]byte)
43-
readSize := 0
43+
var readSize int
4444
for {
4545
readSize, err = r.Read(*bufp)
4646
n += int64(readSize)

uio/progress.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type ProgressReadCloser struct {
2626
func (rc *ProgressReadCloser) Read(p []byte) (n int, err error) {
2727
defer func() {
2828
numSymbols := (rc.counter%rc.Interval + n) / rc.Interval
29-
rc.W.Write([]byte(strings.Repeat(rc.Symbol, numSymbols)))
29+
_, _ = rc.W.Write([]byte(strings.Repeat(rc.Symbol, numSymbols)))
3030
rc.counter += n
3131
rc.written = (rc.written || numSymbols > 0)
3232
if err == io.EOF && rc.written {
33-
rc.W.Write([]byte("\n"))
33+
_, _ = rc.W.Write([]byte("\n"))
3434
}
3535
}()
3636
return rc.RC.Read(p)

uio/progress_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ func TestProgressReadCloser(t *testing.T) {
2222

2323
// Read one byte at a time.
2424
output := make([]byte, 1)
25-
prc.Read(output)
26-
prc.Read(output)
27-
prc.Read(output)
25+
_, _ = prc.Read(output)
26+
_, _ = prc.Read(output)
27+
_, _ = prc.Read(output)
2828
if len(stdout.Bytes()) != 0 {
2929
t.Errorf("found %q, but expected no bytes to be written", stdout)
3030
}
31-
prc.Read(output)
31+
_, _ = prc.Read(output)
3232
if stdout.String() != "#" {
3333
t.Errorf("found %q, expected %q to be written", stdout.String(), "#")
3434
}
3535

3636
// Read 9 bytes all at once.
3737
output = make([]byte, 9)
38-
prc.Read(output)
38+
_, _ = prc.Read(output)
3939
if stdout.String() != "###" {
4040
t.Errorf("found %q, expected %q to be written", stdout.String(), "###")
4141
}

uio/uiotest/uiotest.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func NowLog() string {
2121

2222
// TestLineWriter is an io.Writer that logs full lines of serial to tb.
2323
func TestLineWriter(tb testing.TB, prefix string) io.WriteCloser {
24+
tb.Helper()
2425
if len(prefix) > 0 {
2526
return uio.FullLineWriter(&testLinePrefixWriter{tb: tb, prefix: prefix})
2627
}

ulog/log_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2023 the u-root Authors. All rights reserved
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package ulog
26

37
import (

0 commit comments

Comments
 (0)