chore: add golangci-lint v2 config and fix linter warnings (#46)

- [x] Add golangci-lint v2 configuration with formatters section
- [x] Reorganize linters-settings under linters section
- [x] Replace if-else chains with switch statements for clarity
- [x] Wrap all ignored error returns with `_ = ` pattern
- [x] Add OSC 8 hyperlink helper function for clickable ports
- [x] Add blank line in table styling function
- [x] Remove unnecessary type assertion in test
This commit is contained in:
2026-02-13 18:46:27 +00:00
committed by GitHub
parent d3c5e5eb36
commit e50f73ec92
17 changed files with 65 additions and 47 deletions
+7 -1
View File
@@ -564,6 +564,11 @@ func (m model) buildTableRows() [][]string {
statusIcon, statusText := m.getStatusIconAndText(id, fwd)
localPortText := fmt.Sprintf("%d", fwd.LocalPort)
if fwd.Status == "Active" && !m.ui.isForwardDisabled(id) {
localPortText = hyperlink(fmt.Sprintf("http://127.0.0.1:%d", fwd.LocalPort), fmt.Sprintf("%d→", fwd.LocalPort))
}
rows = append(rows, []string{
truncate(fwd.Context, ColumnWidthContext),
truncate(fwd.Namespace, ColumnWidthNamespace),
@@ -571,7 +576,7 @@ func (m model) buildTableRows() [][]string {
truncate(fwd.Type, ColumnWidthType),
truncate(fwd.Resource, ColumnWidthResource),
fmt.Sprintf("%d", fwd.RemotePort),
fmt.Sprintf("%d", fwd.LocalPort),
localPortText,
statusIcon + " " + statusText,
})
}
@@ -642,6 +647,7 @@ func (m model) createTableStyleFunc(colors mainViewColors) func(row, col int) li
return baseStyle.Foreground(colors.errorColor)
}
}
}
return baseStyle
+1 -1
View File
@@ -368,7 +368,7 @@ func TestHTTPLogEntry(t *testing.T) {
func TestHTTPLogSubscriberType(t *testing.T) {
// Test that our mock matches the type
mock := NewMockHTTPLogSubscriber()
var subscriber HTTPLogSubscriber = mock.GetSubscriberFunc()
subscriber := mock.GetSubscriberFunc()
// Test subscription
callCount := 0
+4 -3
View File
@@ -856,11 +856,12 @@ func TestModel_Update_ViewModeRouting(t *testing.T) {
ui := NewBubbleTeaUI(nil, "1.0.0")
ui.mu.Lock()
ui.viewMode = tt.viewMode
if tt.viewMode == ViewModeAddWizard {
switch tt.viewMode {
case ViewModeAddWizard:
ui.addWizard = newAddWizardState()
} else if tt.viewMode == ViewModeBenchmark {
case ViewModeBenchmark:
ui.benchmarkState = newBenchmarkState("id", "alias", 8080)
} else if tt.viewMode == ViewModeHTTPLog {
case ViewModeHTTPLog:
ui.httpLogState = newHTTPLogState("id", "alias")
}
ui.mu.Unlock()
+7
View File
@@ -187,6 +187,13 @@ func (t *TableUI) Remove(id string) {
delete(t.forwards, id)
}
// hyperlink wraps text in an OSC 8 terminal hyperlink escape sequence.
// Clicking the text opens the URL in terminals that support it (Ghostty, iTerm2,
// Windows Terminal, Kitty, WezTerm, etc.). Unsupported terminals show plain text.
func hyperlink(url, text string) string {
return fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", url, text)
}
// truncate truncates a string to maxLen, adding "..." if needed
func truncate(s string, maxLen int) string {
if len(s) <= maxLen {
+4 -3
View File
@@ -661,12 +661,13 @@ func (m model) handleAddWizardEnter() (tea.Model, tea.Cmd) {
Alias: wizard.alias,
}
if wizard.selectedResourceType == ResourceTypePodPrefix {
switch wizard.selectedResourceType {
case ResourceTypePodPrefix:
fwd.Resource = "pod/" + wizard.resourceValue
} else if wizard.selectedResourceType == ResourceTypePodSelector {
case ResourceTypePodSelector:
fwd.Resource = wizard.resourceValue
fwd.Selector = wizard.selector
} else if wizard.selectedResourceType == ResourceTypeService {
case ResourceTypeService:
fwd.Resource = "service/" + wizard.resourceValue
}
+2 -2
View File
@@ -1304,10 +1304,10 @@ func decompressContent(content string, headers map[string]string) string {
if err != nil {
return content // Return original on error
}
defer reader.Close()
defer func() { _ = reader.Close() }()
case "deflate":
reader = flate.NewReader(bytes.NewReader(data))
defer reader.Close()
defer func() { _ = reader.Close() }()
default:
// br (brotli), compress, zstd - not in stdlib, return original
return content