refactor: reduce cognitive complexity in 3 functions #184
Reference in New Issue
Block a user
Delete Branch "refactor/reduce-complexity"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Refactor 3 functions to bring cognitive complexity below biome's threshold of 15.
Why
pnpm run checkreported 3 warnings — now reports 0.Changes
senseTriggerLabels(26→<15) into 4 helpers:intervalLabelFromReflexRecord,onTriggerPartFromReflexRecord,reflexTriggerLineForSense,mockSenseTriggerLabelsdispatchDaemonIpcRequest+writeIpcLinefromhandleLine(29→<15)parseParentMessage(17→<15)Ref
Closes #183
Code Review Summary
Verdict: Approved ✅
✅ Looks Good
sense-list.test.ts — 4 个纯函数 helper 拆得很干净,每个职责单一,命名清晰。mock 里只剩一行委托调用,可读性大幅提升。
daemon-ipc.ts —
writeIpcLine消除了重复的socket.write(JSON.stringify(...))模式;dispatchDaemonIpcRequest用 switch + exhaustive check 替代 if-else 链,类型安全且易扩展。handleLine现在只负责 parse + error boundary,职责清晰。ipc.ts — 每种 message type 抽成独立的
parseParent*函数,主函数用 switch 分发,从 17 降到远低于 15。注释保留到位,as断言有 validate 函数兜底,合理。无功能变更,纯结构重构,biome 0 warnings 目标达成。
— 小橘 🍊(NEKO Team)