Skip to content

Refactor (packages/app/src/components/status-popover-indicator.ts): Function with many returns - #85

Open
wrakab wants to merge 2 commits into
CMU-17313Q:mainfrom
wrakab:refactor-status-popover-indicator
Open

wrakab wants to merge 2 commits into
CMU-17313Q:mainfrom
wrakab:refactor-status-popover-indicator

Conversation

@wrakab

@wrakab wrakab commented Sep 5, 2026

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue:
#10
Full path to the refactored file:
packages/app/src/components/status-popover-indicator.ts
What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)

  • Small helpers for the status popover in the UI
  • Two of them check MCP/LSP service states
  • The third picks the CSS class for the coloured status dot
  • Only used by status-popover.tsx
    What is the scope of your refactoring within that file?
    (Name specific functions/blocks/regions touched.)
  • Only serverStatusDotClass (line 18)
  • The other two exported functions were left alone

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)

  • Function with many returns (count = 6): serverStatusDotClass, line 18
  • BEFORE: 6 returns. AFTER: Qlty reports nothing for the file

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?

  • The order of the six if-returns is what decides which status wins
  • To add or change a state you had to read the whole chain to work out precedence

What changes did you make to resolve the issue?

  • Replaced the if/return chain with an ordered array of [condition, class] pairs
  • One return that takes the first matching pair with the neutral class as fallbackk
  • Kept the rules in the same order as the original branche... so behaviour is identical

How do your changes improve maintainability? Did you consider alternatives?

  • Adding or reordering a status is now a list edit instead of rewriting control flow
  • Precedence is visible as list order
  • Considered a switch but the conditions are not on a single value
  • Considered an object lookup but the conditions overlap and depend on order

3. Validation

How did you validate that the change is correct?

  • 5 existing tests cover all six original branches: 9 pass / 0 fail
  • packages/app suite: 640 pass / 9 fail, identical to main, so those are pre-existing
  • bun lint: 698 warnings / 2 errors, identical to main, errors are in packages/console
  • Coverage: packages/app 91.1%, this file 17/17 lines
  • qlty smells on the file reports nothing after the change

Attach a screenshot of the test coverage showing the lines were executed by the tests.

Attach a screenshot showing the tests that cover the change passing during CI

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.ts> showing fewer reported issues after the changes.
Screenshot 2026-09-05 at 7 51 36 PM
Screenshot 2026-09-05 at 7 51 48 PM
Screenshot 2026-09-05 at 8 05 55 PM

Screenshot 2026-09-05 at 9 10 48 PM

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.

1 participant