Skip to content

Commit 1a1a673

Browse files
fix(linter): golangci-lint v1.61.0 compatibility (#334)
1 parent 18eb8a4 commit 1a1a673

7 files changed

Lines changed: 57 additions & 14 deletions

File tree

internal/clierrors/command_failed.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ type CommandFailedError struct {
88

99
var _ ClientError = CommandFailedError{}
1010

11-
func min(a, b int) int {
12-
if a < b {
13-
return a
14-
}
15-
return b
16-
}
17-
1811
func (err CommandFailedError) ErrorCode() int {
1912
return min(err.FailedCount, 99)
2013
}

internal/commands/storage/import.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package storage
33
import (
44
"fmt"
55
"io"
6+
"math"
67
"net/url"
78
"os"
89
"path/filepath"
@@ -249,12 +250,16 @@ func (s *importCommand) ExecuteWithoutArguments(exec commands.Executor) (output.
249250
})
250251
} else {
251252
// we have no knowledge of the remote file size, report bytes uploaded
253+
transferred := fmt.Sprintf("%sB", "-1")
254+
if statusUpdate.bytesTransferred <= math.MaxUint32 {
255+
transferred = ui.AbbrevNumBinaryPrefix(uint(statusUpdate.bytesTransferred)) //nolint:gosec // disable G115: false positive because value is checked
256+
}
252257
exec.PushProgressUpdate(messages.Update{
253258
Key: msg,
254259
ProgressMessage: fmt.Sprintf(
255260
"- %sed %sB (%sBps)",
256261
transferType,
257-
ui.AbbrevNumBinaryPrefix(uint(statusUpdate.bytesTransferred)),
262+
transferred,
258263
ui.AbbrevNumBinaryPrefix(uint(bps)),
259264
),
260265
})

internal/format/stringslice.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ func toIfaceSlice(val interface{}) ([]interface{}, bool) {
4949
}
5050

5151
func maxStringLen(strings []string) int {
52-
max := 0
52+
maxLen := 0
5353
for _, str := range strings {
54-
if strLen := len(str); strLen > max {
55-
max = strLen
54+
if strLen := len(str); strLen > maxLen {
55+
maxLen = strLen
5656
}
5757
}
58-
return max
58+
return maxLen
5959
}
6060

6161
func stringSliceString(values []interface{}, andOrOr string, singleLine bool) string {

internal/ui/list_layout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *ListLayout) appendSection(title, note string, sectionBody []string) {
106106
if s.style.NoteSeparator {
107107
s.appendLine()
108108
}
109-
s.l.AppendItem(DefaultNoteColours.Sprintf(note))
109+
s.l.AppendItem(DefaultNoteColours.Sprint(note))
110110
}
111111
if s.style.MarginBottom {
112112
s.appendLine()

internal/ui/numeric.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func AbbrevNumBinaryPrefix(raw uint) string {
8282

8383
// FormatBytes returns a string with the given number interpreted as bytes and abbreviated with binary formatting (eg 1024 = 1KiB)
8484
func FormatBytes(n int) string {
85+
if n < 0 || n > math.MaxUint32 {
86+
return fmt.Sprintf("%sB", "-1")
87+
}
88+
8589
return fmt.Sprintf("%sB", AbbrevNumBinaryPrefix(uint(n)))
8690
}
8791

internal/ui/ui.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ func FormatRange(start, end string) string {
5050

5151
// ConcatStrings like join but handles well the empty strings
5252
func ConcatStrings(strs ...string) string {
53-
ret := fmt.Sprintf(strs[0])
53+
if len(strs) == 0 {
54+
return ""
55+
}
56+
57+
ret := strs[0]
5458

5559
if len(strs) <= 1 {
5660
return ret

internal/ui/ui_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ui
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestConcatStringsSingleString(t *testing.T) {
10+
result := ConcatStrings("hello")
11+
expected := "hello"
12+
assert.Equal(t, expected, result)
13+
}
14+
15+
func TestConcatStringsMultipleStrings(t *testing.T) {
16+
result := ConcatStrings("hello", "world", "foo", "bar")
17+
expected := "hello/world/foo/bar"
18+
assert.Equal(t, expected, result)
19+
}
20+
21+
func TestConcatStringsWithEmptyStrings(t *testing.T) {
22+
result := ConcatStrings("hello", "", "world", "", "foo", "bar")
23+
expected := "hello/world/foo/bar"
24+
assert.Equal(t, expected, result)
25+
}
26+
27+
func TestConcatStringsAllEmptyStrings(t *testing.T) {
28+
result := ConcatStrings("", "", "")
29+
expected := ""
30+
assert.Equal(t, expected, result)
31+
}
32+
33+
func TestConcatStringsEmptyInput(t *testing.T) {
34+
result := ConcatStrings()
35+
expected := ""
36+
assert.Equal(t, expected, result)
37+
}

0 commit comments

Comments
 (0)