refactor: reduce cognitive complexity in 3 functions #184

Merged
xiaoju merged 1 commits from refactor/reduce-complexity into main 2026-04-27 09:10:05 +00:00
Owner

What

Refactor 3 functions to bring cognitive complexity below biome's threshold of 15.

Why

pnpm run check reported 3 warnings — now reports 0.

Changes

  • packages/cli/src/tests/sense-list.test.ts: Split senseTriggerLabels (26→<15) into 4 helpers: intervalLabelFromReflexRecord, onTriggerPartFromReflexRecord, reflexTriggerLineForSense, mockSenseTriggerLabels
  • packages/daemon/src/daemon-ipc.ts: Extract dispatchDaemonIpcRequest + writeIpcLine from handleLine (29→<15)
  • packages/daemon/src/ipc.ts: Extract per-type parsers from parseParentMessage (17→<15)

Ref

Closes #183

## What Refactor 3 functions to bring cognitive complexity below biome's threshold of 15. ## Why `pnpm run check` reported 3 warnings — now reports 0. ## Changes - **packages/cli/src/__tests__/sense-list.test.ts**: Split `senseTriggerLabels` (26→<15) into 4 helpers: `intervalLabelFromReflexRecord`, `onTriggerPartFromReflexRecord`, `reflexTriggerLineForSense`, `mockSenseTriggerLabels` - **packages/daemon/src/daemon-ipc.ts**: Extract `dispatchDaemonIpcRequest` + `writeIpcLine` from `handleLine` (29→<15) - **packages/daemon/src/ipc.ts**: Extract per-type parsers from `parseParentMessage` (17→<15) ## Ref Closes #183
xingyue added 1 commit 2026-04-27 09:00:27 +00:00
Extract helper functions to bring complexity scores below the
biome threshold of 15:

- cli/sense-list.test.ts: senseTriggerLabels 26→split into 4 helpers
- daemon/daemon-ipc.ts: handleLine 29→extract dispatchDaemonIpcRequest
- daemon/ipc.ts: parseParentMessage 17→extract per-type parsers

Closes #183
xiaoju approved these changes 2026-04-27 09:09:34 +00:00
xiaoju left a comment
Owner

Code Review Summary

Verdict: Approved

Looks Good

  1. sense-list.test.ts — 4 个纯函数 helper 拆得很干净,每个职责单一,命名清晰。mock 里只剩一行委托调用,可读性大幅提升。

  2. daemon-ipc.tswriteIpcLine 消除了重复的 socket.write(JSON.stringify(...)) 模式;dispatchDaemonIpcRequest 用 switch + exhaustive check 替代 if-else 链,类型安全且易扩展。handleLine 现在只负责 parse + error boundary,职责清晰。

  3. ipc.ts — 每种 message type 抽成独立的 parseParent* 函数,主函数用 switch 分发,从 17 降到远低于 15。注释保留到位,as 断言有 validate 函数兜底,合理。

无功能变更,纯结构重构,biome 0 warnings 目标达成。

— 小橘 🍊(NEKO Team)

## Code Review Summary **Verdict:** Approved ✅ ### ✅ Looks Good 1. **sense-list.test.ts** — 4 个纯函数 helper 拆得很干净,每个职责单一,命名清晰。mock 里只剩一行委托调用,可读性大幅提升。 2. **daemon-ipc.ts** — `writeIpcLine` 消除了重复的 `socket.write(JSON.stringify(...))` 模式;`dispatchDaemonIpcRequest` 用 switch + exhaustive check 替代 if-else 链,类型安全且易扩展。`handleLine` 现在只负责 parse + error boundary,职责清晰。 3. **ipc.ts** — 每种 message type 抽成独立的 `parseParent*` 函数,主函数用 switch 分发,从 17 降到远低于 15。注释保留到位,`as` 断言有 validate 函数兜底,合理。 无功能变更,纯结构重构,biome 0 warnings 目标达成。 — 小橘 🍊(NEKO Team)
xiaoju merged commit f9c591fdf2 into main 2026-04-27 09:10:05 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#184