Skip to content

P1B: Refactor (packages/opencode/src/cli/cmd/run/footer.ts:122): Function with many returns (count = 8): eventPatch - #105

Open
halhajricmu wants to merge 1 commit into
CMU-17313Q:mainfrom
halhajricmu:refactor/footer-eventpatch-many-returns
Open

halhajricmu wants to merge 1 commit into
CMU-17313Q:mainfrom
halhajricmu:refactor/footer-eventpatch-many-returns

Conversation

@halhajricmu

@halhajricmu halhajricmu commented Sep 6, 2026

Copy link
Copy Markdown
  1. Issue
    Link to the associated GitHub issue: Closes P1B: Refactor (packages/opencode/src/cli/cmd/run/footer.ts:122): Function with many returns (count = 8): eventPatch #99
    Full path to the refactored file: packages/opencode/src/cli/cmd/run/footer.ts
    What do you think this file does? Implements RunFooter, the mutable footer UI for opencode run interactive mode — it owns the append-only scrollback stream and the reactive footer state (prompt, status, permission/question views) and turns incoming FooterEvents into state patches.

What is the scope of your refactoring within that file?
Only the module-level function eventPatch(next: FooterEvent): FooterPatch | undefined (previously lines 122–165). No other function touched.

Which Qlty-reported issue did you address? The "Function with many returns (count = 8): eventPatch" smell at footer.ts:122.

  1. Refactoring
    How did the specific issue you chose impact the codebase's maintainability? The 8 separate return points made the function hard to scan and easy to break when adding a case.

What changes did you make to resolve the issue? Replaced the if/return chain with one switch (next.type) that assigns to a single patch local and returns once at the end. TypeScript still narrows each case, so every branch produces the exact same value as before; unhandled types fall through to the initial undefined. How do your changes improve maintainability? Did you consider alternatives? One exit point and a case per event type makes the event→patch mapping readable at a glance. Alternative considered: a lookup object keyed by type, but the per-case payloads differ and rely on union narrowing, so a switch stays clearer with no casts.

  1. Validation
    How did you validate that the change is correct? Behaviour is identical by construction (same 7 cases → same patches). Added packages/opencode/test/cli/run/footer.event-patch.test.ts with one assertion per handled event type plus the undefined fallback; bun test passes locally and in CI. Re-ran qlty smells --no-snippets on the file and the eventPatch "many returns" finding is gone.

Coverage, local test run, and qlty smells (before / after):

Screenshot 2026-09-06 at 7 19 46 PM Screenshot 2026-09-06 at 7 20 06 PM Screenshot 2026-09-06 at 7 24 42 PM Screenshot 2026-09-06 at 7 24 53 PM Screenshot 2026-09-06 at 7 28 41 PM

Tests passing during CI (GitHub Actions):
image

@halhajricmu halhajricmu changed the title Refactor (packages/opencode/src/cli/cmd/run/footer.ts): Collapse eventPatch's many returns into a single-return switch P1B: Refactor (packages/opencode/src/cli/cmd/run/footer.ts:122): Function with many returns (count = 8): eventPatch Sep 6, 2026
@halhajricmu
halhajricmu force-pushed the refactor/footer-eventpatch-many-returns branch from d8f820d to de6c7ec Compare September 6, 2026 17:17
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.

P1B: Refactor (packages/opencode/src/cli/cmd/run/footer.ts:122): Function with many returns (count = 8): eventPatch

1 participant