Skip to content

Commit 0538880

Browse files
committed
Fix lint findings from first real golangci-lint run
errcheck: wrap deferred Close calls; staticcheck: De Morgan simplifications, tagged switch, Fprintf over WriteString(Sprintf), drop redundant nil check; remove unused newConfirmModal and renderSparkline.
1 parent 49439f8 commit 0538880

8 files changed

Lines changed: 11 additions & 77 deletions

File tree

audit/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Append(e Entry) {
6161
if err != nil {
6262
return
6363
}
64-
defer f.Close()
64+
defer func() { _ = f.Close() }()
6565
data, err := json.Marshal(e)
6666
if err != nil {
6767
return

tools/archive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func extractFromTarGz(archive []byte, binName string) ([]byte, error) {
3030
if err != nil {
3131
return nil, fmt.Errorf("gzip: %w", err)
3232
}
33-
defer gz.Close()
33+
defer func() { _ = gz.Close() }()
3434
tr := tar.NewReader(gz)
3535
for {
3636
h, err := tr.Next()

tools/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func k9sReleaser(goos, goarch string) (Releaser, error) {
6666
if !ok {
6767
return Releaser{}, fmt.Errorf("k9s: unsupported OS %s", goos)
6868
}
69-
if !(goarch == "amd64" || goarch == "arm64") {
69+
if goarch != "amd64" && goarch != "arm64" {
7070
return Releaser{}, fmt.Errorf("k9s: unsupported arch %s", goarch)
7171
}
7272
ext := "tar.gz"

tui/app.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,8 @@ func (m model) headerView() string {
15671567
// LINODE_TOKEN with no named account). Falls back to the account
15681568
// name otherwise.
15691569
label := ""
1570-
switch acct := m.cfg.DefaultAccount; {
1571-
case acct == "__cli__" || acct == "":
1570+
switch acct := m.cfg.DefaultAccount; acct {
1571+
case "__cli__", "":
15721572
if m.username != "" {
15731573
label = m.username
15741574
}
@@ -1726,7 +1726,7 @@ func (m model) dispatch(input string) (tea.Model, tea.Cmd) {
17261726
b.WriteString(line + "\n")
17271727
}
17281728
}
1729-
b.WriteString(fmt.Sprintf("\nactive (global): %s\n", m.cfg.ActiveTheme))
1729+
fmt.Fprintf(&b, "\nactive (global): %s\n", m.cfg.ActiveTheme)
17301730
if len(m.cfg.Accounts) > 0 {
17311731
b.WriteString("\nper-account overrides:\n")
17321732
names := make([]string, 0, len(m.cfg.Accounts))
@@ -1744,9 +1744,9 @@ func (m model) dispatch(input string) (tea.Model, tea.Cmd) {
17441744
marker = " (active)"
17451745
}
17461746
if override == "" {
1747-
b.WriteString(fmt.Sprintf(" %s%s: (inherits global)\n", n, marker))
1747+
fmt.Fprintf(&b, " %s%s: (inherits global)\n", n, marker)
17481748
} else {
1749-
b.WriteString(fmt.Sprintf(" %s%s: %s\n", n, marker, override))
1749+
fmt.Fprintf(&b, " %s%s: %s\n", n, marker, override)
17501750
}
17511751
}
17521752
}

tui/confirm.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ type confirmModal struct {
2121
destructive bool
2222
}
2323

24-
func newConfirmModal(prompt string, onYes tea.Cmd) *confirmModal {
25-
return newConfirmModalWithTheme(prompt, onYes, theme.Theme{})
26-
}
27-
2824
func newConfirmModalWithTheme(prompt string, onYes tea.Cmd, th theme.Theme) *confirmModal {
2925
m := &confirmModal{
3026
onYes: onYes,

tui/create_linode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (m *createLinode) Update(msg tea.Msg) tea.Cmd {
195195
}
196196

197197
func (m *createLinode) maybeBuildForm() tea.Cmd {
198-
if !(m.gotReg && m.gotTyp && m.gotImg && m.gotSSH) {
198+
if !m.gotReg || !m.gotTyp || !m.gotImg || !m.gotSSH {
199199
return nil
200200
}
201201
regionOpts := make([]huh.Option[string], 0, len(m.regions))

tui/create_lke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (m *createLKE) Update(msg tea.Msg) tea.Cmd {
139139
}
140140

141141
func (m *createLKE) maybeBuildForm() tea.Cmd {
142-
if !(m.gotReg && m.gotTyp && m.gotVer) {
142+
if !m.gotReg || !m.gotTyp || !m.gotVer {
143143
return nil
144144
}
145145
regionOpts := make([]huh.Option[string], 0, len(m.regions))

tui/views/instance_detail.go

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func (m *instanceDetail) renderBackups() string {
489489
return " (no backup data — check `backups:read_only` scope)\n"
490490
}
491491
var b strings.Builder
492-
if bks.Automatic != nil && len(bks.Automatic) > 0 {
492+
if len(bks.Automatic) > 0 {
493493
b.WriteString(" Automatic Backups\n " + strings.Repeat("─", 40) + "\n")
494494
for _, bk := range bks.Automatic {
495495
created := ""
@@ -809,68 +809,6 @@ func bucketValues(values []float64, width int) []float64 {
809809
return out
810810
}
811811

812-
// renderSparkline turns a series of values into a single line of unicode
813-
// block characters. Width controls how many cells to render — values are
814-
// bucketed if there are more samples than cells. Baseline is 0 so the
815-
// height of each bar corresponds to the absolute value (not min-max scale).
816-
func renderSparkline(values []float64, width int) string {
817-
if len(values) == 0 || width <= 0 {
818-
return ""
819-
}
820-
// Bucket to width cells. Each cell is the mean of its bucket.
821-
buckets := make([]float64, width)
822-
if len(values) <= width {
823-
// Stretch: pad the left with zeros so the recent samples land on
824-
// the right edge (most readable).
825-
offset := width - len(values)
826-
for i, v := range values {
827-
buckets[offset+i] = v
828-
}
829-
} else {
830-
samplesPerCell := float64(len(values)) / float64(width)
831-
for cell := 0; cell < width; cell++ {
832-
lo := int(float64(cell) * samplesPerCell)
833-
hi := int(float64(cell+1) * samplesPerCell)
834-
if hi > len(values) {
835-
hi = len(values)
836-
}
837-
if lo >= hi {
838-
buckets[cell] = values[lo]
839-
continue
840-
}
841-
var sum float64
842-
for _, v := range values[lo:hi] {
843-
sum += v
844-
}
845-
buckets[cell] = sum / float64(hi-lo)
846-
}
847-
}
848-
var maxV float64
849-
for _, v := range buckets {
850-
if v > maxV {
851-
maxV = v
852-
}
853-
}
854-
if maxV == 0 {
855-
// All zeros — render a flat baseline.
856-
return strings.Repeat("▁", width)
857-
}
858-
// 8-level unicode block ramp.
859-
levels := []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
860-
var b strings.Builder
861-
for _, v := range buckets {
862-
idx := int((v / maxV) * float64(len(levels)-1))
863-
if idx < 0 {
864-
idx = 0
865-
}
866-
if idx >= len(levels) {
867-
idx = len(levels) - 1
868-
}
869-
b.WriteRune(levels[idx])
870-
}
871-
return b.String()
872-
}
873-
874812
func stats(values []float64) (minV, maxV, cur, avg float64) {
875813
if len(values) == 0 {
876814
return 0, 0, 0, 0

0 commit comments

Comments
 (0)