[refactor] 清除 SonarCloud code smells(批次)#27
Open
YJack0000 wants to merge 1 commit into
Open
Conversation
- Mark component props as Readonly (layout/logo/page-header/book-badge/
subscriptions/transactions/reconciliation dialog)
- Extract nested ternaries into statements (contracts 收款進度、tools-hr 薪資項目)
- Reduce cognitive complexity by extracting helpers:
- handler.ts: split tools/call into handleToolCall (19→<15)
- tools-hr.ts: parseSalaryItems (16→<15)
- tools-transactions.ts: normalizeBulkTxnItem + fill* / applyTxnRelationPatch +
applyTxnAmountPatch (36→<15, 29→<15)
- prefer globalThis over window (use-mobile)
- avoid negated condition (activity)
- stable keys instead of array index (table-skeleton)
- move hitInteractive to module scope (row-dialog)
- option role focusable via tabIndex (combobox)
- localeCompare-based sort (queries, Bug)
- export…from re-export (tools.ts)
- simplify slug regex + safe FormData stringification (onboarding)
- exclude already-applied forward-only SQL migrations from Sonar (unfixable
literal duplication; editing applied migrations breaks drizzle hash tracking)
Untouched by design: src/components/ui/** (shadcn scaffolding, already in
sonar.exclusions).
|
yui0303
approved these changes
Jul 14, 2026
yui0303
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the Sonar cleanup batch. Changes are mechanical refactors / accessibility cleanup, .infisical.json contains workspace config rather than secrets, and SonarCloud is green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



批次修掉 SonarCloud 清單上的 43 筆問題。分三類處理:直接修、已是 scaffolding 不動、用排除處理。
直接修正的原始碼問題(28 筆)
Readonly props(React, S6759)
layout.tsx、logo.tsx(×2)、page-header.tsx、book-badge.tsx、subscriptions/page.tsx、transactions/page.tsx、reconciliation/new-reconciliation-dialog.tsx巢狀三元 → 獨立敘述
contracts/page.tsx:進度條顏色 + 未收/溢收/已收齊標籤抽成barColor/remainingLabel(同時解掉 L40 認知複雜度 16→<15)tools-hr.ts:薪資項目isTaxable改 if/else認知複雜度 → 抽 helper
handler.ts:tools/call抽成handleToolCall(19→<15)tools-hr.ts:parseSalaryItems(16→<15)tools-transactions.ts:normalizeBulkTxnItem+fillIncomeExpense/fillAdvance/fillTransfer(36→<15)、applyTxnRelationPatch+applyTxnAmountPatch(29→<15)其他
use-mobile.ts:window→globalThisactivity/page.tsx:移除 negated conditiontable-skeleton.tsx:改用穩定 key(不用 array index)row-dialog.tsx:hitInteractive移到 module scopecombobox.tsx:role="option"加tabIndex={-1}使其 focusablequeries.ts:.sort()改用localeCompare(Bug 類)tools.ts:改用export…fromre-exportToolContextonboarding/page.tsx:簡化 slug regex(去掉會 backtrack 的-+)+ 安全處理FormData.get()(避免[object Object])未改動:
src/components/ui/**(13 筆)breadcrumb / calendar / chart / sidebar 是 shadcn scaffolding,本來就在
sonar.exclusions內(也符合「保持 ui/ 原封不動、方便 CLI 更新」的慣例)。清單上這些應為排除生效前的殘留,下次掃描就會消失。用排除處理:
migrations/**(2 筆)0002/0003的「重複字面量」是 SQL DDL 的本質(org id、status 反覆出現)。這些是 已套用的 forward-only migration,改內容會破壞 drizzle 的 hash 追蹤,且 migration runner 沒有乾淨的「常數」機制。因此比照schema.ts的做法把migrations/**加入sonar.exclusions。若你偏好保留掃描覆蓋,改在 SonarCloud UI 標為 won't-fix 亦可。驗證
tsc --noEmit:我改動的檔案皆無錯(既有的recharts模組缺失錯誤與本 PR 無關,stash 後仍在)eslint:改動檔案無新增錯誤(new-reconciliation-dialog/use-mobile既有的set-state-in-effect警告為既存、非本清單項目)