Community程式設計與開發github.com

alfathafp/portofolio-web-design

進行多軸向程式碼審查。在合併任何變更前使用。在審查自己、其他代理或人類編寫的程式碼時使用。當需要跨多個維度評估程式碼品質再合併至主分支時使用。當被要求審查 diff 或 pull request(即使是內聯貼上的 diff)時使用。

portofolio-web-design 是什麼?

這項技能提供了一個結構化的多維度程式碼審查流程,專為在合併前確保程式碼品質而設計。它支援 Claude Code、Cursor 等 AI 代理平台,也適用於人類開發者。審查涵蓋五大軸向:正確性、可讀性、架構、安全性與效能,並提供明確的審查標準,強調持續改進而非追求完美。技能還包含變更規模建議、結構化發現分類(如 Critical、Nit)、審查步驟、多模型協作模式、以及處理意見分歧的層級架構。透過這些指引,技能幫助團隊維持程式碼健康度、減少技術債,並加速審查流程。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/code-review-and-quality

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

程式碼審查與品質

概述

多維度程式碼審查,附帶品質關卡。每個變更在合併前都必須經過審查 — 沒有例外。審查涵蓋五大軸向:正確性、可讀性、架構、安全性與效能。

核准標準: 當一個變更確實能改善整體程式碼健康度時,即使不完美,也應予核准。完美的程式碼不存在 — 目標是持續改進。不要因為變更不是您理想中的寫法而阻擋它。如果它能改善程式碼庫並遵循專案慣例,就予以核准。

使用時機

  • 合併任何 PR 或變更之前
  • 完成功能實作之後
  • 當需要評估其他代理或模型產生的程式碼時
  • 重構現有程式碼時
  • 任何錯誤修正之後(同時審查修正與回歸測試)

五大軸向審查

每次審查都會依據這些維度評估程式碼:

1. 正確性

程式碼是否如其所述般運作?

  • 是否符合規格或任務需求?
  • 是否處理了邊界情況(null、空值、邊界值)?
  • 是否處理了錯誤路徑(不僅是快樂路徑)?
  • 是否通過所有測試?測試是否真的測試了正確的東西?
  • 是否存在差一錯誤、競爭條件或狀態不一致?

2. 可讀性與簡潔性

另一位工程師(或代理)能否在無需作者解釋的情況下理解這段程式碼?

  • 命名是否具描述性並與專案慣例一致?(沒有無上下文的 temp、data、result)
  • 控制流程是否直接明瞭(避免巢狀三元運算子、深層回呼)?
  • 程式碼組織是否合乎邏輯(相關程式碼分組、清晰的模組邊界)?
  • 是否有應簡化的「取巧」技巧?
  • 能否用更少的行數完成?(原本 100 行就能解決,卻寫了 1000 行就是失敗)
  • 抽象化是否值得其複雜度?(在第三次使用案例之前不要急著泛化)
  • 註解是否能幫助澄清非顯而易見的意圖?(但不要為顯而易見的程式碼加註解)
  • 是否存在無效程式碼:無作用變數(_unused)、向後相容墊片或 // removed 註解?
  • 是否將新的條件判斷硬塞進無關的流程中? 這是設計壞味道,不是小問題 — 應將邏輯推送到自己的輔助函式、狀態或策略中,而不是纏繞現有路徑。
  • 是否反覆出現對相同形狀的條件判斷? 這表示缺少模型或調度器。「暫時」的分支通常是永久的技術債。

3. 架構

此變更是否符合系統的設計?

  • 是否遵循現有模式或引入新模式?如果是新的,是否有正當理由?
  • 是否維護了清晰的模組邊界?
  • 是否存在應共用的重複程式碼?
  • 依賴關係是否流向正確的方向(無循環依賴)?
  • 抽象層級是否恰當(不過度設計,也未過度耦合)?
  • 此重構是否真的降低了複雜度,還是只是重新定位了複雜度? 計算讀者需要記住多少概念才能理解變更。如果一個「更乾淨」的版本並未減少概念數,那就不是更乾淨 — 優先選擇能讓整個分支、模式或層次消失的重構,勝過重新集中相同邏輯的重構。優先選擇刪除抽象化,而非改進它。
  • 功能特定邏輯是否洩漏到共用或通用模組中? 將邏輯保留在其所屬層級,重複使用現有的規範輔助函式,而非近似重複,並且不要讓架構漂移常態化。
  • 型別邊界是否明確? 質疑隨意的 any/unknown/可選/型別轉換,以及掩蓋不明確不變量的隱形後備方案 — 明確化邊界通常能簡化周圍的控制流程。

4. 安全性

關於詳細的安全指導,請參閱 security-and-hardening。此變更是否引入了弱點?

  • 使用者輸入是否經過驗證與清理?
  • 機密是否未遺留在程式碼、日誌和版本控制中?
  • 需要時是否檢查了身分驗證/授權?
  • SQL 查詢是否使用了參數化(無字串串接)?
  • 輸出是否經過編碼以防止 XSS?
  • 依賴項是否來自受信任的來源且無已知弱點?
  • 來自外部來源(API、日誌、使用者內容、設定檔)的資料是否被視為不受信任?
  • 外部資料流是否在系統邊界進行驗證,然後再用於邏輯或呈現?

5. 效能

關於詳細的效能分析和最佳化,請參閱 performance-optimization。此變更是否引入了效能問題?

  • 是否存在 N+1 查詢模式?
  • 是否存在無界迴圈或無限制的資料擷取?
  • 是否存在應為非同步的同步操作?
  • UI 元件中是否存在不必要的重新渲染?
  • 列表端點是否缺少分頁?
  • 熱路徑中是否建立了大型物件?

結構性補救措施

標記結構性問題時,請提出具體的動作 — 而不僅僅是問題本身。只說「這很複雜」的審查讓作者無所適從。請使用具名的重構方式:

  • 用型別模型或明確的調度器取代一連串的條件判斷
  • 將重複的分支合併成一個更清晰的流程
  • 將協調邏輯與業務邏輯分離,讓兩者各自獨立可讀
  • 將功能特定邏輯移出共用模組,放入擁有該概念的套件中
  • 重複使用規範的輔助函式,而非自製近似重複
  • 明確化型別邊界,使得後續分支消失
  • 刪除一個僅傳遞的包裝器,它增加了間接性卻未釐清 API
  • 提取輔助函式,或將大檔案拆分成專注的模組

優先選擇能移除活動部分的補救措施,勝過將相同複雜度分散各處的方案。

變更規模

小而專注的變更更容易審查、更快合併、也更安全部署。目標規模如下:

~100 行變更   → 良好。可一次審查完成。
~300 行變更   → 可接受,前提是單一邏輯變更。
~1000 行變更  → 太大。請拆分。

注意檔案大小,而不僅僅是 diff 大小。 一個小 diff 仍可能將檔案推過健康邊界 — 單一檔案約 1000 總行數(與上述 ~1000 變更行數門檻不同)是常見的檢查訊號,而非硬性上限。當變更顯著增大已很大的檔案時,請在添加更多內容之前,先詢問是否應提取輔助函式、子元件或模組。先分解,再添加。

何謂「一個變更」: 一個自包含的修改,處理一件事,包含相關測試,並在提交後保持系統功能正常。一個功能的一部分 — 而非整個功能。

變更過大時的拆分策略:

策略方式使用時機
堆疊提交一個小變更,基於它開始下一個順序相依性
按檔案分組為需要不同審查者的群組分開變更跨領域關注點
水平先建立共用程式碼/樁,然後再實作消費者分層架構
垂直將功能拆解成較小的全端切片功能開發

何時可接受大變更: 完整的檔案刪除以及自動化重構,此時審查者只需驗證意圖,而非每一行程式碼。

將重構與功能開發分開。 同時重構現有程式碼並新增行為的變更,實際上是兩個變更 — 請分別提交。小規模清理(如變數重新命名)可由審查者決定是否包含。

變更描述

每個變更都需要一個在版本控制歷史中能獨立存在的描述。

第一行: 簡短、祈使句、獨立。使用「Delete the FizzBuzz RPC」而非「Deleting the FizzBuzz RPC」。必須具有足夠資訊,使搜尋歷史的人無需閱讀 diff 就能理解變更。

內文: 變更了什麼以及原因。包含程式碼本身無法看到的背景、決策和推理。連結相關的錯誤編號、基準測試結果或設計文件。承認方法上的缺點(如果存在)。

反模式:「Fix bug」、「Fix build」、「Add patch」、「Moving code from A to B」、「Phase 1」、「Add convenience functions」。

審查流程

步驟 1:了解背景

在查看程式碼之前,先了解意圖:

- 此變更嘗試達成什麼?
- 它實作了哪個規格或任務?
- 預期的行為變更是什麼?

步驟 2:先審查測試

測試揭示意圖和涵蓋範圍:

- 是否為變更編寫了測試?
- 它們測試的是行為(而非實作細節)嗎?
- 是否涵蓋了邊界情況?
- 測試名稱是否具描述性?
- 如果程式碼改變,測試是否會捕獲回歸?

透過實驗而非閱讀來回答最後一個問題。反轉變更新增的一個條件(移除否定、將 && 換成 ||),執行測試套件,然後從拷貝恢復檔案。維持綠燈的突變是一個發現:命名缺失的測試案例。關於專案範圍的突變分數,請參閱 constraint-driven-development。

步驟 3:審查實作

使用五大軸向來檢視程式碼:

對於每個變更的檔案:
1. 正確性:這段程式碼是否執行了測試所說的功能?
2. 可讀性:我能在無需幫助的情況下理解它嗎?
3. 架構:它是否符合系統設計?
4. 安全性:是否有任何弱點?
5. 效能:是否有任何瓶頸?

步驟 4:分類發現

為每個評論標記嚴重程度,以便作者知道哪些是必須的,哪些是可選的:

前綴意義作者行動
(無前綴)必要的變更合併前必須處理
Critical:阻擋合併安全弱點、資料遺失、功能中斷
Nit:次要、可選作者可忽略 — 格式化、風格偏好
Optional: / Consider:建議值得考慮但非必要
FYI僅供參考無需行動 — 提供未來參考的背景資訊

這可防止作者將所有回饋視為強制性的,並浪費時間處理可選建議。

先說最重要的。 按影響力排序發現:先處理正確性和安全性,然後是結構性回歸和遺漏的簡化,最後才是其他事項。不要將真正的問題埋沒在程式碼風格小問題之下 — 少數幾個高信心的評論勝過一長串清單。如果你有一個結構性問題和十個程式碼風格小問題,結構性問題 就是 審查的重點。

步驟 5:驗證驗證

檢查作者的驗證說明:

- 運行了哪些測試?
- 建置是否通過?
- 是否手動測試了變更?
- UI 變更是否有螢幕截圖?
- 是否有前後比較?

多模型審查模式

針對不同的審查視角使用不同的模型:

模型 A 編寫程式碼
    │
    ▼
模型 B 審查正確性與架構
    │
    ▼
模型 A 處理回饋
    │
    ▼
人類做出最終決定

這能捕捉單一模型可能遺漏的問題 — 不同模型有不同的盲點。

給審查代理的範例提示:

審查此程式碼變更的正確性、安全性以及是否符合
我們的專案慣例。規格說明 [X]。變更應 [Y]。
將任何問題標記為 Critical、Required、Optional 或 Nit。

無效程式碼衛生

在任何重構或實作變更後,檢查孤立的程式碼:

  1. 識別現在無法到達或未使用的程式碼
  2. 明確列出它們
  3. 在刪除前先詢問:「我應該移除這些現在未使用的元素嗎:[清單]?」

不要留下無效程式碼 — 它會混淆未來的讀者和代理。但也不要無聲無息地刪除你不確定的東西。如有疑問,請先詢問。

發現的無效程式碼:
- src/utils/date.ts 中的 formatLegacyDate() — 已被 formatDate() 取代
- src/components/ 中的 OldTaskCard 元件 — 已被 TaskCard 取代
- src/config.ts 中的 LEGACY_API_URL 常數 — 已無任何參考
→ 可以安全移除這些嗎?

審查速度

緩慢的審查會阻礙整個團隊。切換情境來審查的成本低於強加給他人的等待成本。

  • 在一個工作日內回應 — 這是上限,而非目標
  • 理想節奏: 收到審查請求後不久即回應,除非正處於深度專注編碼中。一個典型的變更應在一天內完成多輪審查
  • 優先快速回應,勝過快速最終核准。即使需要多輪審查,快速回饋也能減少挫折感
  • 大型變更: 要求作者拆分,而非審查一個巨大的變更集

處理意見分歧

解決審查爭議時,依此層級處理:

  1. 技術事實和資料優先於意見和偏好
  2. 風格指南是風格問題的絕對權威
  3. 軟體設計必須基於工程原則評估,而非個人偏好
  4. 程式碼庫一致性可接受,前提是不降低整體健康度

不要接受「我之後再清理。」 經驗顯示,延遲的清理很少真的發生。要求提交前清理,除非是真正的緊急情況。如果周圍的問題無法在此變更中解決,則要求提交一個 bug 並指定自己負責。

審查中的誠實

審查程式碼時 — 無論是您自己、其他代理或人類編寫的:

  • 不要橡皮圖章。 沒有審查證據的「LGTM」對任何人都沒幫助。
  • 不要軟化真正的問題。 當一個錯誤會影響生產環境時,說「這可能是個小問題」是不誠實的。
  • 盡可能量化問題。「這個 N+1 查詢將在列表中的每個項目增加約 50ms」優於「這可能會很慢」。
  • 對有明顯問題的方法提出異議。 阿諛奉承是審查中的失敗模式。如果實作有問題,直接說出來並提出替代方案。
  • 優雅地接受否決。 如果作者擁有完整的背景並不同意,請尊重他們的判斷。評論程式碼,而非人 — 將針對個人的批評重新聚焦在程式碼本身。

依賴項紀律

程式碼審查的一部分是依賴項審查:

…

[因翻譯而截斷]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能