From 26965eae854a109fc383dfc21ac51240b3bd9806 Mon Sep 17 00:00:00 2001 From: jcleira Date: Fri, 13 Feb 2026 11:58:26 +0100 Subject: [PATCH] Fix lint errors: errcheck, nilerr, and govet shadow * Objective Resolve all reported lint issues, including errcheck, nilerr, and govet shadow warnings. * Why Unchecked errors and shadowed variables can hide failures and lead to unreliable behavior in production and tests. * How Handle return values from errgroup.Wait() and semaphore.Acquire() instead of discarding them. Propagate errors returned by GetAllBranches during branch listing. Rename shadowed err variables in tests and ensure all error returns in test helpers are properly checked. --- pkg/branch/service.go | 14 ++++++++++---- pkg/config/config_test.go | 8 ++++++-- pkg/git/worktree_test.go | 36 ++++++++++++++++++++++++++---------- pkg/workspace/service.go | 8 ++++++-- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/pkg/branch/service.go b/pkg/branch/service.go index 65f0335..69b5f64 100644 --- a/pkg/branch/service.go +++ b/pkg/branch/service.go @@ -103,7 +103,7 @@ func (s *Service) List() (ListOutput, error) { g.Go(func() error { branches, err := git.GetAllBranches(repoPath) if err != nil { - return nil + return err } defaultBranch, err := git.GetDefaultBranch(repoPath) @@ -170,7 +170,9 @@ func (s *Service) List() (ListOutput, error) { }) } - _ = branchGroup.Wait() + if err := branchGroup.Wait(); err != nil { + return err + } mu.Lock() output.Repositories = append(output.Repositories, repoBranches) @@ -183,7 +185,9 @@ func (s *Service) List() (ListOutput, error) { }) } - _ = g.Wait() + if err := g.Wait(); err != nil { + return ListOutput{}, err + } return output, nil } @@ -260,7 +264,9 @@ func (s *Service) ExecuteCleanup(plan CleanupPlan, skipBranches []string) (Clean }) } - _ = g.Wait() + if err := g.Wait(); err != nil { + return CleanupResult{}, err + } return CleanupResult{ Deleted: deleted, Skipped: skipped, diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 28f54b4..3776a34 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -193,7 +193,9 @@ func TestConfigManager_IsInitialized(t *testing.T) { { name: "initialized when flag is set", setupFunc: func(cm *ConfigManager, tmpDir string) { - _ = cm.SetInitialized(true) + if err := cm.SetInitialized(true); err != nil { + panic(err) + } }, want: true, }, @@ -201,7 +203,9 @@ func TestConfigManager_IsInitialized(t *testing.T) { name: "initialized when repos dir has content", setupFunc: func(cm *ConfigManager, tmpDir string) { reposDir := cm.GetConfig().ReposDir - _ = os.MkdirAll(filepath.Join(reposDir, "some-repo"), 0o755) + if err := os.MkdirAll(filepath.Join(reposDir, "some-repo"), 0o755); err != nil { + panic(err) + } }, want: true, }, diff --git a/pkg/git/worktree_test.go b/pkg/git/worktree_test.go index 036c972..e45e7bc 100644 --- a/pkg/git/worktree_test.go +++ b/pkg/git/worktree_test.go @@ -22,11 +22,15 @@ func initGitRepo(t *testing.T, path string) { cmd = exec.Command("git", "config", "user.email", "test@test.com") cmd.Dir = path - _ = cmd.Run() + if err := cmd.Run(); err != nil { + t.Fatalf("failed to set git config email: %v", err) + } cmd = exec.Command("git", "config", "user.name", "Test User") cmd.Dir = path - _ = cmd.Run() + if err := cmd.Run(); err != nil { + t.Fatalf("failed to set git config name: %v", err) + } testFile := filepath.Join(path, "README.md") if err := os.WriteFile(testFile, []byte("# Test"), 0o644); err != nil { @@ -110,7 +114,7 @@ func TestCreateWorktree(t *testing.T) { t.Fatalf("CreateWorktree() error = %v", err) } - if _, err := os.Stat(worktreePath); os.IsNotExist(err) { + if _, statErr := os.Stat(worktreePath); os.IsNotExist(statErr) { t.Error("worktree directory was not created") } @@ -206,8 +210,8 @@ func TestListWorktrees(t *testing.T) { } worktreePath := filepath.Join(tmpDir, "worktree") - if err := CreateWorktree(mainRepoPath, worktreePath, "test-branch"); err != nil { - t.Fatalf("CreateWorktree() error = %v", err) + if createErr := CreateWorktree(mainRepoPath, worktreePath, "test-branch"); createErr != nil { + t.Fatalf("CreateWorktree() error = %v", createErr) } worktrees, err = ListWorktrees(mainRepoPath) @@ -247,7 +251,9 @@ func TestBranchExists(t *testing.T) { setupFunc: func(t *testing.T, repoPath string) { cmd := exec.Command("git", "branch", "feature-branch") cmd.Dir = repoPath - _ = cmd.Run() + if err := cmd.Run(); err != nil { + t.Fatalf("failed to create branch: %v", err) + } }, want: true, }, @@ -299,8 +305,14 @@ func TestIsBranchCheckedOut(t *testing.T) { t.Error("expected branch to be checked out") } - realWorktreePath, _ := filepath.EvalSymlinks(worktreePath) - realLocation, _ := filepath.EvalSymlinks(location) + realWorktreePath, err := filepath.EvalSymlinks(worktreePath) + if err != nil { + t.Fatalf("EvalSymlinks(worktreePath) error = %v", err) + } + realLocation, err := filepath.EvalSymlinks(location) + if err != nil { + t.Fatalf("EvalSymlinks(location) error = %v", err) + } if realLocation != realWorktreePath { t.Errorf("location = %s, want %s", realLocation, realWorktreePath) } @@ -332,11 +344,15 @@ func TestGetAllBranches(t *testing.T) { cmd := exec.Command("git", "branch", "branch1") cmd.Dir = repoPath - _ = cmd.Run() + if err := cmd.Run(); err != nil { + t.Fatalf("failed to create branch1: %v", err) + } cmd = exec.Command("git", "branch", "branch2") cmd.Dir = repoPath - _ = cmd.Run() + if err := cmd.Run(); err != nil { + t.Fatalf("failed to create branch2: %v", err) + } branches, err := GetAllBranches(repoPath) if err != nil { diff --git a/pkg/workspace/service.go b/pkg/workspace/service.go index 0482fd5..694e13c 100644 --- a/pkg/workspace/service.go +++ b/pkg/workspace/service.go @@ -70,7 +70,9 @@ func (s *Service) SyncMainRepos(repos []RepositorySpec) []SyncResult { }) } - _ = g.Wait() + if err := g.Wait(); err != nil { + return results + } return results } @@ -123,7 +125,9 @@ func (s *Service) Create(input CreateInput) (CreateOutput, error) { wg.Add(1) go func() { defer wg.Done() - _ = sem.Acquire(ctx, 1) + if err := sem.Acquire(ctx, 1); err != nil { + return + } defer sem.Release(1) targetPath := filepath.Join(workspacePath, repo.Name)