Skip to content

Commit 764c2f5

Browse files
rubysclaude
andcommitted
Fix all remaining lint errors for clean golangci-lint v2 run
Fix errcheck and staticcheck issues across process, server, utils, and auth packages. Verified with golangci-lint v2.11.3: 0 issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dddb4d2 commit 764c2f5

9 files changed

Lines changed: 28 additions & 29 deletions

File tree

internal/auth/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func TestHtpasswdAutoReload(t *testing.T) {
505505
if err != nil {
506506
t.Fatalf("Failed to create temp file: %v", err)
507507
}
508-
defer os.Remove(tmpfile.Name())
508+
defer func() { _ = os.Remove(tmpfile.Name()) }()
509509

510510
// Write initial htpasswd content with user1:password1
511511
// Using bcrypt hash (generated with: htpasswd -nbB user1 password1)

internal/process/process_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ func TestCleanupPidFile(t *testing.T) {
906906
if _, err := os.Stat(pidFile); !os.IsNotExist(err) {
907907
t.Error("PID file should be removed after cleanup")
908908
// Clean up if test failed
909-
os.Remove(pidFile)
909+
_ = os.Remove(pidFile)
910910
}
911911

912912
// Test cleanup of non-existent file (should not error)
@@ -1063,7 +1063,7 @@ func TestLoggingComponents(t *testing.T) {
10631063
if strings.Contains(filename, "{{app}}") {
10641064
filename = strings.ReplaceAll(filename, "{{app}}", tt.source)
10651065
}
1066-
os.Remove(filename)
1066+
_ = os.Remove(filename)
10671067
}
10681068
})
10691069
}

internal/process/webapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func cleanupPidFile(pidfilePath string) error {
433433
if err != nil {
434434
slog.Warn("Invalid PID in file", "file", pidfilePath, "pid", pidStr)
435435
// Remove invalid PID file
436-
os.Remove(pidfilePath)
436+
_ = os.Remove(pidfilePath)
437437
return nil
438438
}
439439

internal/server/handler_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ func TestMaintenanceModeWithStaticFiles(t *testing.T) {
894894
if err != nil {
895895
t.Fatalf("Failed to create temp dir: %v", err)
896896
}
897-
defer os.RemoveAll(tempDir)
897+
defer func() { _ = os.RemoveAll(tempDir) }()
898898

899899
// Create a static HTML file
900900
staticHTML := `<!DOCTYPE html>
@@ -1028,7 +1028,7 @@ func TestAssetServingIntegration(t *testing.T) {
10281028
if err != nil {
10291029
t.Fatalf("Failed to create temp dir: %v", err)
10301030
}
1031-
defer os.RemoveAll(tempDir)
1031+
defer func() { _ = os.RemoveAll(tempDir) }()
10321032

10331033
// Create assets directory and test files
10341034
assetsDir := filepath.Join(tempDir, "assets")
@@ -1139,11 +1139,12 @@ func TestAssetServingIntegration(t *testing.T) {
11391139
}
11401140

11411141
// Verify actual content matches expected
1142-
if assetTest.expectedExt == ".js" {
1142+
switch assetTest.expectedExt {
1143+
case ".js":
11431144
if !strings.Contains(body, "Live scores controller loaded") {
11441145
t.Errorf("JS file content not found in response for %s", assetTest.path)
11451146
}
1146-
} else if assetTest.expectedExt == ".css" {
1147+
case ".css":
11471148
if !strings.Contains(body, ".live-scores") {
11481149
t.Errorf("CSS content not found in response for %s", assetTest.path)
11491150
}
@@ -1161,7 +1162,7 @@ func TestAssetServingIntegrationErrorCases(t *testing.T) {
11611162
if err != nil {
11621163
t.Fatalf("Failed to create temp dir: %v", err)
11631164
}
1164-
defer os.RemoveAll(tempDir)
1165+
defer func() { _ = os.RemoveAll(tempDir) }()
11651166

11661167
cfg := &config.Config{
11671168
LocationConfigMutex: sync.RWMutex{},
@@ -1197,7 +1198,7 @@ func TestAssetServingRootPathVariations(t *testing.T) {
11971198
if err != nil {
11981199
t.Fatalf("Failed to create temp dir: %v", err)
11991200
}
1200-
defer os.RemoveAll(tempDir)
1201+
defer func() { _ = os.RemoveAll(tempDir) }()
12011202

12021203
// Create test asset
12031204
assetsDir := filepath.Join(tempDir, "assets")
@@ -1452,8 +1453,7 @@ func TestHandler_HandleRewritesFlyReplay(t *testing.T) {
14521453
t.Run(tt.name, func(t *testing.T) {
14531454
// Set up environment
14541455
if tt.flyAppName != "" {
1455-
os.Setenv("FLY_APP_NAME", tt.flyAppName)
1456-
defer os.Unsetenv("FLY_APP_NAME")
1456+
t.Setenv("FLY_APP_NAME", tt.flyAppName)
14571457
}
14581458

14591459
// Create handler with test configuration
@@ -1544,8 +1544,7 @@ func TestHandler_HandleRewritesFlyReplayWithMethods(t *testing.T) {
15441544
}
15451545

15461546
func TestHandler_HandleRewritesFlyReplayLargeRequest(t *testing.T) {
1547-
os.Setenv("FLY_APP_NAME", "testapp")
1548-
defer os.Unsetenv("FLY_APP_NAME")
1547+
t.Setenv("FLY_APP_NAME", "testapp")
15491548

15501549
cfg := &config.Config{}
15511550
cfg.Server.Listen = "3000"

internal/server/proxy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func TestWebSocketProxy_SuccessfulUpgrade(t *testing.T) {
353353
if err != nil {
354354
t.Fatalf("WebSocket connection failed: %v", err)
355355
}
356-
defer conn.Close()
356+
defer func() { _ = conn.Close() }()
357357

358358
// Test echo
359359
testMessage := "hello websocket"
@@ -384,7 +384,7 @@ func TestWebSocketProxy_StripPath(t *testing.T) {
384384
t.Errorf("Backend upgrade failed: %v", err)
385385
return
386386
}
387-
conn.Close()
387+
_ = conn.Close()
388388
}))
389389
defer backend.Close()
390390

@@ -418,7 +418,7 @@ func TestWebSocketProxy_StripPath(t *testing.T) {
418418
if err != nil {
419419
t.Fatalf("WebSocket connection failed: %v", err)
420420
}
421-
conn.Close()
421+
_ = conn.Close()
422422

423423
// Verify the backend received the stripped path
424424
if receivedPath != "/cable" {
@@ -493,7 +493,7 @@ func TestWebSocketProxy_ProtocolNegotiation(t *testing.T) {
493493
t.Errorf("Backend upgrade failed: %v", err)
494494
return
495495
}
496-
defer conn.Close()
496+
defer func() { _ = conn.Close() }()
497497

498498
// Send welcome message (like Action Cable does)
499499
_ = conn.WriteMessage(websocket.TextMessage, []byte(`{"type":"welcome"}`))
@@ -538,7 +538,7 @@ func TestWebSocketProxy_ProtocolNegotiation(t *testing.T) {
538538
if err != nil {
539539
t.Fatalf("WebSocket connection failed: %v", err)
540540
}
541-
defer conn.Close()
541+
defer func() { _ = conn.Close() }()
542542

543543
// Verify the selected protocol is returned to client
544544
if resp.Header.Get("Sec-WebSocket-Protocol") != selectedProtocol {

internal/server/static_config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestServerTryFilesWithFileResolution(t *testing.T) {
1919
if err != nil {
2020
t.Fatalf("Failed to create temp dir: %v", err)
2121
}
22-
defer os.RemoveAll(tempDir)
22+
defer func() { _ = os.RemoveAll(tempDir) }()
2323

2424
// Create test files
2525
studiosDir := filepath.Join(tempDir, "studios")
@@ -120,7 +120,7 @@ func TestServerAllowedExtensions(t *testing.T) {
120120
if err != nil {
121121
t.Fatalf("Failed to create temp dir: %v", err)
122122
}
123-
defer os.RemoveAll(tempDir)
123+
defer func() { _ = os.RemoveAll(tempDir) }()
124124

125125
// Create test files with different extensions
126126
testFiles := map[string]string{
@@ -216,7 +216,7 @@ func TestServerCacheControl(t *testing.T) {
216216
if err != nil {
217217
t.Fatalf("Failed to create temp dir: %v", err)
218218
}
219-
defer os.RemoveAll(tempDir)
219+
defer func() { _ = os.RemoveAll(tempDir) }()
220220

221221
// Create directory structure
222222
assetsDir := filepath.Join(tempDir, "assets")
@@ -319,7 +319,7 @@ func TestServerTryFilesWithAllowedExtensions(t *testing.T) {
319319
if err != nil {
320320
t.Fatalf("Failed to create temp dir: %v", err)
321321
}
322-
defer os.RemoveAll(tempDir)
322+
defer func() { _ = os.RemoveAll(tempDir) }()
323323

324324
// Create test files with different extensions
325325
contentDir := filepath.Join(tempDir, "content")
@@ -394,7 +394,7 @@ func TestServerTryFilesDisabled(t *testing.T) {
394394
if err != nil {
395395
t.Fatalf("Failed to create temp dir: %v", err)
396396
}
397-
defer os.RemoveAll(tempDir)
397+
defer func() { _ = os.RemoveAll(tempDir) }()
398398

399399
// Create test file
400400
htmlFile := filepath.Join(tempDir, "page.html")
@@ -440,7 +440,7 @@ func TestServerTryFilesWithTenantPaths(t *testing.T) {
440440
if err != nil {
441441
t.Fatalf("Failed to create temp dir: %v", err)
442442
}
443-
defer os.RemoveAll(tempDir)
443+
defer func() { _ = os.RemoveAll(tempDir) }()
444444

445445
// Create studios/millbrae.html
446446
studiosDir := filepath.Join(tempDir, "studios")
@@ -493,7 +493,7 @@ func TestDirectoryRedirect(t *testing.T) {
493493
if err != nil {
494494
t.Fatalf("Failed to create temp dir: %v", err)
495495
}
496-
defer os.RemoveAll(tempDir)
496+
defer func() { _ = os.RemoveAll(tempDir) }()
497497

498498
// Create studios/laval/index.html
499499
lavalDir := filepath.Join(tempDir, "studios", "laval")

internal/server/webapp_proxy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestHandleProxyNoRetry(t *testing.T) {
6363
if ok {
6464
conn, _, _ := hj.Hijack()
6565
if conn != nil {
66-
conn.Close()
66+
_ = conn.Close()
6767
}
6868
}
6969
}))

internal/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func WritePIDFile(pidFile string) error {
7272

7373
// RemovePIDFile removes the PID file
7474
func RemovePIDFile(pidFile string) {
75-
os.Remove(pidFile)
75+
_ = os.Remove(pidFile)
7676
}
7777

7878
// SendReloadSignal sends a HUP signal to the running navigator process

internal/utils/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestExtractTenantName(t *testing.T) {
5757
func TestWritePIDFile(t *testing.T) {
5858
// Test with temporary file
5959
tmpFile := "/tmp/test-navigator.pid"
60-
defer os.Remove(tmpFile)
60+
defer func() { _ = os.Remove(tmpFile) }()
6161

6262
err := WritePIDFile(tmpFile)
6363
if err != nil {

0 commit comments

Comments
 (0)