1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:15:07 +00:00

refactor: fix modernize lint issues (#539)

This commit is contained in:
Oleksandr Redko
2026-03-05 14:46:12 +02:00
committed by GitHub
parent fc006e32be
commit 603df79a01
7 changed files with 17 additions and 48 deletions

View File

@@ -261,10 +261,10 @@ func scutilProxyEnabled(out, key string) bool {
func scutilProxyValue(out, key string) string {
prefix := key + " :"
for _, line := range strings.Split(out, "\n") {
for line := range strings.Lines(out) {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, prefix) {
return strings.TrimSpace(strings.TrimPrefix(line, prefix))
if after, ok := strings.CutPrefix(line, prefix); ok {
return strings.TrimSpace(after)
}
}
return ""

View File

@@ -261,7 +261,7 @@ func renderCPUCard(cpu CPUStatus, thermal ThermalStatus) cardData {
sort.Slice(cores, func(i, j int) bool { return cores[i].val > cores[j].val })
maxCores := min(len(cores), 3)
for i := 0; i < maxCores; i++ {
for i := range maxCores {
c := cores[i]
lines = append(lines, fmt.Sprintf("Core%-2d %s %5.1f%%", c.idx+1, progressBar(c.val), c.val))
}
@@ -403,10 +403,7 @@ func formatDiskLine(label string, d DiskStatus) string {
}
func ioBar(rate float64) string {
filled := min(int(rate/10.0), 5)
if filled < 0 {
filled = 0
}
filled := max(min(int(rate/10.0), 5), 0)
bar := strings.Repeat("▮", filled) + strings.Repeat("▯", 5-filled)
if rate > 80 {
return dangerStyle.Render(bar)
@@ -451,10 +448,7 @@ func buildCards(m MetricsSnapshot, width int) []cardData {
}
func miniBar(percent float64) string {
filled := min(int(percent/20), 5)
if filled < 0 {
filled = 0
}
filled := max(min(int(percent/20), 5), 0)
return colorizePercent(percent, strings.Repeat("▮", filled)+strings.Repeat("▯", 5-filled))
}
@@ -478,13 +472,7 @@ func renderNetworkCard(netStats []NetworkStatus, history NetworkHistory, proxy P
// Layout: "Down " (7) + graph + " " (2) + rate (approx 10-12)
// Safe margin: 22 chars.
// We target 16 chars to match progressBar implementation for visual consistency.
graphWidth := cardWidth - 22
if graphWidth < 5 {
graphWidth = 5
}
if graphWidth > 16 {
graphWidth = 16 // Match progressBar fixed width
}
graphWidth := min(max(cardWidth-22, 5), 16)
// sparkline graphs
rxSparkline := sparkline(history.RxHistory, totalRx, graphWidth)
@@ -536,10 +524,7 @@ func sparkline(history []float64, current float64, width int) string {
var builder strings.Builder
for _, v := range data {
level := int((v / maxVal) * float64(len(blocks)-1))
if level < 0 {
level = 0
}
level := max(int((v/maxVal)*float64(len(blocks)-1)), 0)
if level >= len(blocks) {
level = len(blocks) - 1
}
@@ -639,10 +624,7 @@ func renderCard(data cardData, width int, height int) string {
}
titleText := data.icon + " " + data.title
lineLen := width - lipgloss.Width(titleText) - 2
if lineLen < 0 {
lineLen = 0
}
lineLen := max(width-lipgloss.Width(titleText)-2, 0)
header := titleStyle.Render(titleText)
if lineLen > 0 {

View File

@@ -951,7 +951,7 @@ func TestRenderHeaderWrapsOnNarrowWidth(t *testing.T) {
}
header, _ := renderHeader(m, "", 0, 38, true)
for _, line := range strings.Split(header, "\n") {
for line := range strings.Lines(header) {
if lipgloss.Width(stripANSI(line)) > 38 {
t.Fatalf("renderHeader() line exceeds width: %q", line)
}
@@ -1021,7 +1021,7 @@ func TestRenderCardWrapsOnNarrowWidth(t *testing.T) {
}
rendered := renderCard(card, 26, 0)
for _, line := range strings.Split(rendered, "\n") {
for line := range strings.Lines(rendered) {
if lipgloss.Width(stripANSI(line)) > 26 {
t.Fatalf("renderCard() line exceeds width: %q", line)
}