Skip to content

[refactor] 清除 SonarCloud code smells(批次)#27

Open
YJack0000 wants to merge 1 commit into
mainfrom
fix/sonar-code-smells-bulk
Open

[refactor] 清除 SonarCloud code smells(批次)#27
YJack0000 wants to merge 1 commit into
mainfrom
fix/sonar-code-smells-bulk

Conversation

@YJack0000

Copy link
Copy Markdown
Contributor

批次修掉 SonarCloud 清單上的 43 筆問題。分三類處理:直接修已是 scaffolding 不動用排除處理

直接修正的原始碼問題(28 筆)

Readonly props(React, S6759)

  • layout.tsxlogo.tsx(×2)、page-header.tsxbook-badge.tsxsubscriptions/page.tsxtransactions/page.tsxreconciliation/new-reconciliation-dialog.tsx

巢狀三元 → 獨立敘述

  • contracts/page.tsx:進度條顏色 + 未收/溢收/已收齊標籤抽成 barColor / remainingLabel(同時解掉 L40 認知複雜度 16→<15)
  • tools-hr.ts:薪資項目 isTaxable 改 if/else

認知複雜度 → 抽 helper

  • handler.tstools/call 抽成 handleToolCall(19→<15)
  • tools-hr.tsparseSalaryItems(16→<15)
  • tools-transactions.tsnormalizeBulkTxnItem + fillIncomeExpense/fillAdvance/fillTransfer(36→<15)、applyTxnRelationPatch + applyTxnAmountPatch(29→<15)

其他

  • use-mobile.tswindowglobalThis
  • activity/page.tsx:移除 negated condition
  • table-skeleton.tsx:改用穩定 key(不用 array index)
  • row-dialog.tsxhitInteractive 移到 module scope
  • combobox.tsxrole="option"tabIndex={-1} 使其 focusable
  • queries.ts.sort() 改用 localeCompareBug 類)
  • tools.ts:改用 export…from re-export ToolContext
  • onboarding/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 警告為既存、非本清單項目)
  • 所有 refactor 皆為等價抽取,行為不變

- 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).
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@YJack0000 YJack0000 requested a review from yui0303 July 8, 2026 17:40

@yui0303 yui0303 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Sonar cleanup batch. Changes are mechanical refactors / accessibility cleanup, .infisical.json contains workspace config rather than secrets, and SonarCloud is green.

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.

2 participants