Skip to content

Commit 7676fcb

Browse files
committed
chore: lint and test fixes
1 parent ef964bc commit 7676fcb

17 files changed

Lines changed: 97 additions & 78 deletions

.golangci.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ linters:
1212
- ineffassign
1313
- misspell
1414
# gosec disabled - false positives for CLI tools that shell out to git
15+
settings:
16+
errcheck:
17+
check-type-assertions: true
18+
check-blank: true
19+
govet:
20+
enable:
21+
- shadow
1522
exclusions:
1623
rules:
1724
# Test files can have unchecked errors - tests use t.Fatal patterns
@@ -24,14 +31,6 @@ formatters:
2431
- gofmt
2532
- goimports
2633

27-
linters-settings:
28-
errcheck:
29-
check-type-assertions: true
30-
check-blank: true
31-
govet:
32-
enable:
33-
- shadow
34-
3534
issues:
3635
max-issues-per-linter: 0
3736
max-same-issues: 0

cmd/abort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func runAbort(cmd *cobra.Command, args []string) error {
4444
}
4545

4646
// Clean up state (ignore error - best effort cleanup)
47-
_ = state.Remove(g.GetGitDir())
47+
_ = state.Remove(g.GetGitDir()) //nolint:errcheck // best effort cleanup
4848

4949
fmt.Printf("Cascade aborted. Original HEAD was %s\n", st.OriginalHead)
5050
return nil

cmd/adopt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func runAdopt(cmd *cobra.Command, args []string) error {
5656
}
5757

5858
// Check if already tracked
59-
if _, err := cfg.GetParent(branchName); err == nil {
59+
if _, getParentErr := cfg.GetParent(branchName); getParentErr == nil {
6060
return fmt.Errorf("branch %q is already tracked", branchName)
6161
}
6262

@@ -73,7 +73,7 @@ func runAdopt(cmd *cobra.Command, args []string) error {
7373
}
7474

7575
if parent != trunk {
76-
if _, err := cfg.GetParent(parent); err != nil {
76+
if _, parentErr := cfg.GetParent(parent); parentErr != nil {
7777
return fmt.Errorf("parent %q is not tracked", parent)
7878
}
7979
}

cmd/cascade.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ func runCascade(cmd *cobra.Command, args []string) error {
8888
}
8989

9090
func doCascade(g *git.Git, cfg *config.Config, branches []*tree.Node, dryRun bool) error {
91-
originalBranch, _ := g.CurrentBranch()
92-
originalHead, _ := g.GetTip(originalBranch)
91+
originalBranch, err := g.CurrentBranch()
92+
if err != nil {
93+
return err
94+
}
95+
originalHead, err := g.GetTip(originalBranch)
96+
if err != nil {
97+
return err
98+
}
9399

94100
for i, b := range branches {
95101
parent, err := cfg.GetParent(b.Name)
@@ -132,7 +138,7 @@ func doCascade(g *git.Git, cfg *config.Config, branches []*tree.Node, dryRun boo
132138
Pending: remaining,
133139
OriginalHead: originalHead,
134140
}
135-
_ = state.Save(g.GetGitDir(), st) // Best effort - user can recover manually
141+
_ = state.Save(g.GetGitDir(), st) //nolint:errcheck // best effort - user can recover manually
136142

137143
fmt.Printf("\nCONFLICT: Resolve conflicts and run 'gh stack continue', or 'gh stack abort' to cancel.\n")
138144
fmt.Printf("Remaining branches: %v\n", remaining)
@@ -144,7 +150,7 @@ func doCascade(g *git.Git, cfg *config.Config, branches []*tree.Node, dryRun boo
144150

145151
// Return to original branch
146152
if !dryRun {
147-
_ = g.Checkout(originalBranch) // Best effort - cascade succeeded
153+
_ = g.Checkout(originalBranch) //nolint:errcheck // best effort - cascade succeeded
148154
}
149155

150156
return nil

cmd/continue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func runContinue(cmd *cobra.Command, args []string) error {
4040
// Complete the in-progress rebase
4141
if g.IsRebaseInProgress() {
4242
fmt.Println("Continuing rebase...")
43-
if err := g.RebaseContinue(); err != nil {
43+
if rebaseErr := g.RebaseContinue(); rebaseErr != nil {
4444
return fmt.Errorf("rebase --continue failed; resolve conflicts first")
4545
}
4646
}
@@ -49,7 +49,7 @@ func runContinue(cmd *cobra.Command, args []string) error {
4949

5050
// Continue with remaining branches
5151
if len(st.Pending) == 0 {
52-
_ = state.Remove(g.GetGitDir()) // Cleanup
52+
_ = state.Remove(g.GetGitDir()) //nolint:errcheck // cleanup
5353
fmt.Println("Cascade complete!")
5454
return nil
5555
}
@@ -73,7 +73,7 @@ func runContinue(cmd *cobra.Command, args []string) error {
7373
}
7474

7575
// Remove state file before continuing (will be recreated if conflict)
76-
_ = state.Remove(g.GetGitDir())
76+
_ = state.Remove(g.GetGitDir()) //nolint:errcheck // cleanup
7777

7878
return doCascade(g, cfg, branches, false)
7979
}

cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func runCreate(cmd *cobra.Command, args []string) error {
5757
}
5858

5959
if currentBranch != trunk {
60-
if _, err := cfg.GetParent(currentBranch); err != nil {
60+
if _, parentErr := cfg.GetParent(currentBranch); parentErr != nil {
6161
return fmt.Errorf("current branch %q is not tracked; use 'gh stack adopt' first", currentBranch)
6262
}
6363
}

cmd/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func runLog(cmd *cobra.Command, args []string) error {
4646
}
4747

4848
g := git.New(cwd)
49-
currentBranch, _ := g.CurrentBranch()
49+
currentBranch, _ := g.CurrentBranch() //nolint:errcheck // empty string is fine for display
5050

5151
if logPorcelainFlag {
5252
printPorcelain(root, currentBranch)

cmd/orphan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ func runOrphan(cmd *cobra.Command, args []string) error {
7070
if orphanForceFlag {
7171
descendants := tree.GetDescendants(node)
7272
for _, desc := range descendants {
73-
_ = cfg.RemoveParent(desc.Name) // Best effort cleanup
74-
_ = cfg.RemovePR(desc.Name)
73+
_ = cfg.RemoveParent(desc.Name) //nolint:errcheck // best effort cleanup
74+
_ = cfg.RemovePR(desc.Name) //nolint:errcheck // best effort cleanup
7575
fmt.Printf("Orphaned %q\n", desc.Name)
7676
}
7777
}
7878

7979
// Orphan the branch
80-
_ = cfg.RemoveParent(branchName) // Best effort cleanup
81-
_ = cfg.RemovePR(branchName)
80+
_ = cfg.RemoveParent(branchName) //nolint:errcheck // best effort cleanup
81+
_ = cfg.RemovePR(branchName) //nolint:errcheck // best effort cleanup
8282
fmt.Printf("Orphaned %q\n", branchName)
8383

8484
return nil

cmd/pr.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ func runPR(cmd *cobra.Command, args []string) error {
6767
}
6868

6969
// Check if PR already exists
70-
existingPR, _ := cfg.GetPR(branch)
70+
existingPR, _ := cfg.GetPR(branch) //nolint:errcheck // 0 is fine if no PR
7171
if existingPR > 0 {
7272
// Update existing PR's base if needed
7373
fmt.Printf("PR #%d already exists, updating base to %q\n", existingPR, base)
74-
if err := gh.UpdatePRBase(existingPR, base); err != nil {
75-
return fmt.Errorf("failed to update PR base: %w", err)
74+
if updateErr := gh.UpdatePRBase(existingPR, base); updateErr != nil {
75+
return fmt.Errorf("failed to update PR base: %w", updateErr)
7676
}
7777

7878
// Update stack comment
79-
root, err := tree.Build(cfg)
80-
if err != nil {
81-
return fmt.Errorf("build tree: %w", err)
79+
root, buildErr := tree.Build(cfg)
80+
if buildErr != nil {
81+
return fmt.Errorf("build tree: %w", buildErr)
8282
}
8383
comment := github.GenerateStackComment(root, branch, trunk)
8484
if comment != "" {
85-
if err := gh.CreateOrUpdateStackComment(existingPR, comment); err != nil {
86-
fmt.Printf("Warning: failed to update stack comment: %v\n", err)
85+
if commentErr := gh.CreateOrUpdateStackComment(existingPR, comment); commentErr != nil {
86+
fmt.Printf("Warning: failed to update stack comment: %v\n", commentErr)
8787
}
8888
}
8989
return nil
@@ -109,14 +109,14 @@ func runPR(cmd *cobra.Command, args []string) error {
109109
}
110110

111111
// Store PR number
112-
if err := cfg.SetPR(branch, prNumber); err != nil {
113-
return err
112+
if setPRErr := cfg.SetPR(branch, prNumber); setPRErr != nil {
113+
return setPRErr
114114
}
115115

116116
// Post stack navigation comment
117-
root, err := tree.Build(cfg)
118-
if err != nil {
119-
return fmt.Errorf("build tree: %w", err)
117+
root, buildErr := tree.Build(cfg)
118+
if buildErr != nil {
119+
return fmt.Errorf("build tree: %w", buildErr)
120120
}
121121

122122
comment := github.GenerateStackComment(root, branch, trunk)

cmd/push.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ func runPush(cmd *cobra.Command, args []string) error {
5858

5959
// Get downstack (ancestors from current to trunk, reversed)
6060
ancestors := tree.GetAncestors(node)
61-
trunk, _ := cfg.GetTrunk()
61+
trunk, err := cfg.GetTrunk()
62+
if err != nil {
63+
return err
64+
}
6265

6366
// Build list: current + ancestors (excluding trunk)
6467
var branches []*tree.Node
@@ -76,7 +79,7 @@ func runPush(cmd *cobra.Command, args []string) error {
7679

7780
// Update PR bases and push
7881
for _, b := range branches {
79-
parent, _ := cfg.GetParent(b.Name)
82+
parent, _ := cfg.GetParent(b.Name) //nolint:errcheck // empty string is fine
8083

8184
// Update PR base if needed
8285
if b.PR > 0 {

0 commit comments

Comments
 (0)