Skip to content

chore(lint): clear pre-existing CI lint baseline - #18

Merged
benny123tw merged 2 commits into
mainfrom
chore/lint-baseline
Apr 26, 2026
Merged

chore(lint): clear pre-existing CI lint baseline#18
benny123tw merged 2 commits into
mainfrom
chore/lint-baseline

Conversation

@benny123tw

Copy link
Copy Markdown
Owner

Summary

Clears the 4 lint findings that were failing CI (and pre-dated PR #17) so the lint job goes green again.

Why these are appearing now

The CI workflow uses golangci-lint-action@v9 with version: latest and actions/setup-go@v6 with go-version: "stable". Both float, so newer rule versions of staticcheck/gosec started flagging code that was clean at the time it was written. Pinning latest is the upstream cause; this PR just clears the resulting backlog.

Changes

  • staticcheck QF1012 (internal/tui/confirm.go, internal/tui/model.go): replace sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&sb, ...). Pure mechanical, no behavior change. Includes some lines staticcheck didn't initially report — it has a per-file cap and re-rolls after each fix, so I converted all sb.WriteString(fmt.Sprintf(...)) instances in the touched files for consistency.
  • gosec G118 (internal/tui/model.go:884): startNextHook was silently overwriting m.hookCancelFunc when hooks completed normally, leaking the prior context.WithCancel cleanup. Call the previous cancel func first before assigning a new one — this fixes the (small) real leak and incidentally satisfies G118 without needing a //nolint.

Test plan

  • just fmt
  • just build
  • just test — all packages pass
  • just lint0 issues locally

🤖 Generated with Claude Code

- Replace `sb.WriteString(fmt.Sprintf(...))` with `fmt.Fprintf(&sb, ...)`
  in `confirm.go` and `model.go` (staticcheck QF1012).
- Cancel any previous hook context before starting a new one in
  `startNextHook`. The cancel func was being silently overwritten when
  hooks completed normally, leaking the prior context — calling it
  first also clears gosec G118.

These were flagged by newer golangci-lint releases; the workflow uses
`version: latest` so rule churn started failing CI on previously-passing
code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@benny123tw has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 52 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 18 minutes and 52 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cf0489fc-3e53-47cf-aa15-db68d67aa587

📥 Commits

Reviewing files that changed from the base of the PR and between a95eff8 and b62b749.

📒 Files selected for processing (2)
  • internal/tui/confirm.go
  • internal/tui/model.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/lint-baseline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Review

Clean, focused PR — all four lint findings are resolved correctly without nolint suppressions or scope creep.

QF1012 — fmt.Fprintf replacements

All eligible sb.WriteString(fmt.Sprintf(...)) call sites are converted. The residual sb.WriteString(SomeStyle.Render(fmt.Sprintf(...))) patterns in both files are correctly left alone — the outer Render() call makes them ineligible for QF1012, so nothing was missed.

The discarded (int, error) returns from fmt.Fprintf are fine here: strings.Builder implements io.Writer but its Write method never returns an error, so there is nothing to handle.

G118 — hookCancelFunc leak fix

The fix is correct. Calling the previous cancel before overwriting prevents the context from being leaked when hooks complete normally and startNextHook is re-entered at model.go:290. Calling an already-cancelled context.CancelFunc is a no-op, so the case where the user pressed Ctrl+C first (line 339) is safe.

One minor style note: the comment added here is three lines, which is longer than the project guideline ("one short line max" per CLAUDE.md). See the inline suggestion.

Test coverage

The G118 fix is a real behavioral change (the cancel func now runs on normal hook completion, not just on user cancellation). There are no new tests covering this path. Adding a test is not strictly necessary for a leak this small, but it would make the invariant explicit. Low priority for a lint-baseline PR.

Summary

All changes are mechanically correct and safe to merge. The only actionable item is the comment length nit inline.

Comment thread internal/tui/model.go Outdated
Comment on lines +883 to +885
// Tear down any previous hook's context before starting a new one — the
// cancel func is otherwise leaked when hooks complete normally and the
// field is overwritten on the next call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the project's style guideline (CLAUDE.md: "one short line max"), this three-line comment could be condensed. The why is still captured:

Suggested change
// Tear down any previous hook's context before starting a new one — the
// cancel func is otherwise leaked when hooks complete normally and the
// field is overwritten on the next call.
// Call previous cancel before overwriting — hooks completing normally don't cancel their own context.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Clears newly surfaced CI lint failures by refactoring string formatting in the TUI code and addressing a hook-context cancellation leak.

Changes:

  • Replaced sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&sb, ...) in internal/tui/model.go and internal/tui/confirm.go to satisfy staticcheck QF1012.
  • Ensured any previously stored hook cancel func is invoked before being overwritten in Model.startNextHook to address gosec G118.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/tui/model.go Uses fmt.Fprintf for builder output; cancels any prior hook context before creating a new one.
internal/tui/confirm.go Uses fmt.Fprintf for builder output in confirmation/success/error renderers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/tui/model.go Outdated
Comment on lines +883 to +888
// Tear down any previous hook's context before starting a new one — the
// cancel func is otherwise leaked when hooks complete normally and the
// field is overwritten on the next call.
if m.hookCancelFunc != nil {
m.hookCancelFunc()
}

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startNextHook cancels the previous hook context only when starting a subsequent hook. If the last hook in a phase completes and execution continues (or the program exits) without another startNextHook call, m.hookCancelFunc is never invoked and remains referenced. Consider calling the current cancel func (and setting m.hookCancelFunc = nil) when a hook completes / when leaving StateExecutingHooks, rather than only right before overwriting it here.

Copilot uses AI. Check for mistakes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes string building by replacing sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&sb, ...) across several TUI components to reduce allocations. Additionally, it fixes a potential context leak in the hook execution logic by ensuring that any existing hookCancelFunc is called before a new context is created. I have no feedback to provide.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@benny123tw
benny123tw merged commit 5ba71ea into main Apr 26, 2026
6 checks passed
@benny123tw
benny123tw deleted the chore/lint-baseline branch April 26, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants