選項
首頁首頁 Skill 其他 review-duplication

review-duplication

google-gemini/gemini-cli google-gemini/gemini-cli

在代碼審查過程中運用這項技能,主動檢視程式碼庫,以找出功能重複、重複發明輪子,或是未能重用現有專案的最佳實踐與共用函式庫的情況。

...展開全部
10
更新時間 2026-08-13

評論重複

概述

此技能提供一套結構化的工作流程,用於在程式碼審查期間調查程式碼庫,以識別重複的邏輯、重新發明的輔助函式,以及錯失重用既定模式的機會。透過執行此工作流程,可確保新程式碼能與現有的專案架構無縫整合。

工作流程:檢查重複代碼

在進行程式碼審查時,請於完成審查前執行以下步驟:

1. 提取核心邏輯

分析新程式碼,以識別其中引入的核心演算法、輔助函式、通用資料結構或使用者介面元件。請跳脫特定的業務邏輯,深入觀察其底層運作機制。

2. 推斷現有位置並追蹤依賴關係

思考若此類程式碼已存在於專案中,應位於何處。請提供從儲存庫根目錄開始的絕對路徑,以消除歧義。

  • 輔助函式: packages/core/src/utils/、packages/cli/src/utils/
  • UI 元件: packages/cli/src/ui/components/、packages/cli/src/ui/
  • 服務: packages/core/src/services/、packages/cli/src/services/
  • 設定: packages/core/src/config/、packages/cli/src/config/
  • 核心邏輯:若功能不屬於 React UI 專屬,請標示為packages/core/。

追蹤第三方依賴項:若拉取請求(PR)引入了新實用程式庫的匯入(例如lodash.merge、date-fns),請追蹤專案目前如何及在何處使用該實用程式庫。很可能已有現成的封裝程式或共用實用程式。

檢查套件檔案:在標記複雜演算法的自訂實作之前,請先檢查package.json,確認是否已安裝提供此功能的標準函式庫(如lodash或uuid)。

3. 調查程式碼庫(子代理委派)

將代碼庫調查這項繁重的工作委派給專門的子代理。這些子代理經過優化,能夠進行深度搜尋和語義映射,同時不會使您的會話歷史紀錄過於臃腫。

為確保審查全面,您必須為子代理制定高度具體的目標,並提供您在步驟 1 中發現的「線索」。

  • 程式碼庫調查員:將 `codebase_investigator` 作為您的主要研究員。在委派任務時,請制定一個目標,提出關於程式碼庫的具體調查問題,並明確包含以下搜尋向量:
    • 結構相似性:詢問現有程式碼是否使用相同的底層 API(例如:「是否有現有程式碼出於類似目的而使用Intl.DateTimeFormat或setTimeout?」)。
    • 命名規範:詢問是否存在具有類似命名模式的現有符號(例如:「是否有現有符號採用*Format*或*Debounce* 這樣的命名模式?」)。
    • 註解與文件:探詢拉取請求(PR)的註解或 JSDoc 中是否存在關鍵字,用以描述其他地方的類似行為。
    • 架構契合度:詢問此類邏輯目前集中於何處(例如:「集中式的日期格式化邏輯位於何處?」)。
    • 重構指引:至關重要的是,請子代理說明應如何重構新程式碼,以便運用其所發現的任何現有邏輯。
  • 通才型代理:使用通才型代理進行詳細且需多次迭代的比較。例如:「檢視 PR 中MyNewComponent的實作,並與packages/ui/src 中的所有元件進行語義比對。是否有現有的元件可以延伸使用或直接替代?」
  • 保留簡單搜尋的快速路徑:對於極其簡單且無歧義的檢查(例如:「package.json是否包含lodash?」),請直接執行搜尋以節省時間。對於任何開放式的「調查」,預設採用委派處理。

4. 評估最佳實務

檢查新程式碼是否符合專案既定的規範。

  • 錯誤處理:是否使用了專案的標準錯誤類別或記錄機制?
  • 狀態管理:是否繞過了既定的儲存區或上下文?
  • 樣式設定:是否硬編碼顏色或間距,而非使用主題變數? 若拉取請求引入了新模式,請將其與文件中記載的標準進行比對,並明確確認是否應改用現有的專案模式。

5. 提出建設性回饋

若發現 Pull Request 重複了現有功能或忽略了最佳實務:

  • 請提供清晰的審查評論。
  • 指明來源:明確提及應重複使用的絕對或專案相對檔案路徑,以及具體的符號(函式、元件、類別)。
  • 實作指引:提供簡短的程式碼片段或清晰的說明,展示如何整合現有程式碼以滿足任務需求。
  • 說明價值:簡要說明為何重用現有程式碼有益(例如:可維護性、一致性、內建邊緣案例處理)。

範例註解:

「看來這個 PR 引入了一個新的formatDate輔助函式。我們在src/utils/dateHelpers.ts 中已經有一個經過充分測試且穩健的formatDate函式。

您可以透過以下方式導入該函式來取代您的實作:

import{ formatDate }from '../utils/dateHelpers';// 然後在此處使用:
constdisplayDate =formatDate(userDate,'MMM Do, YYYY');

重複使用此函式可確保日期格式與應用程式的其餘部分保持一致,並能正確處理時區轉換。」

此儲存庫的更多內容同一儲存庫

此儲存庫的更多內容

effortgoogle-gemini/gemini-cli估算解決指定問題所需的實作工作量。2026-07-07106.2kqualitygoogle-gemini/gemini-cli評估 GitHub 問題是否為垃圾訊息、內容為空、需要更多資訊,或是可以繼續處理。2026-07-07 106.2k spec-generator google-gemini/gemini-cli 產生結構化的 Workable Spec JSON,以引導開發者工作人員。2026-07-07106.2kantigravity-supportgoogle-gemini/gemini-cli當使用者提出問題、尋求協助,或要求有關安裝、設定或遷移至 Antigravity CLI 的指示時,請使用此功能。 此技能提供源自官方 Antigravity CLI 文件中的最新詳細資訊、需求及指令。2026-06-09106.2kagent-tuigoogle-gemini/gemini-cli 主要代理程式:請勿直接使用此技能。 若需測試 TUI,請呼叫 `tui_tester` 子代理程式。透過程式化方式驅動終端使用者介面 (TUI) 應用程式,以進行測試、自動化及檢查。適用情境:自動化 CLI/TUI 互動、對終端應用程式進行回歸測試,或驗證互動行為。 此外,當使用者詢問「什麼是 agent-tui」、「agent-tui 做什麼」、「演示 agent-tui」、「向我展示 agent-tui」、「agent-tui 是如何運作的」,或希望親眼見證其實際運作時,亦可使用此功能。2026-05-18106.2ktui-testergoogle-gemini/gemini-cli 透過終端機自動化測試 Gemini CLI 行為與視覺輸出的專家指南。2026-05-18106.2k
在 GitHub 上查看

Review Duplication

Overview

This skill provides a structured workflow for investigating a codebase during a code review to identify duplicated logic, reinvented utilities, and missed opportunities to reuse established patterns. By executing this workflow, you ensure that new code integrates seamlessly with the existing project architecture.

Workflow: Investigating for Duplication

When reviewing code, perform the following steps before finalizing your review:

1. Extract Core Logic

Analyze the new code to identify the core algorithms, utility functions, generic data structures, or UI components being introduced. Look beyond the specific business logic to see the underlying mechanics.

2. Hypothesize Existing Locations & Trace Dependencies

Think about where this type of code would live if it already existed in the project. Provide absolute paths from the repo root to disambiguate.

  • Utilities: packages/core/src/utils/, packages/cli/src/utils/
  • UI Components: packages/cli/src/ui/components/, packages/cli/src/ui/
  • Services: packages/core/src/services/, packages/cli/src/services/
  • Configuration: packages/core/src/config/, packages/cli/src/config/
  • Core Logic: Call out packages/core/ if functionality does not appear React UI specific.

Trace Third-Party Dependencies: If the PR introduces a new import for a utility library (e.g., lodash.merge, date-fns), trace how and where the project currently uses that library. There is likely an existing wrapper or shared utility.

Check Package Files: Before flagging a custom implementation of a complex algorithm, check package.json to see if a standard library (like lodash or uuid) is already installed that provides this functionality.

3. Investigate the Codebase (Sub-Agent Delegation)

Delegate the heavy lifting of codebase investigation to specialized sub-agents. They are optimized to perform deep searches and semantic mapping without bloating your session history.

To ensure a comprehensive review, you MUST formulate highly specific objectives for the sub-agents, providing them with the "scents" you discovered in Step 1.

  • Codebase Investigator: Use the codebase_investigator as your primary researcher. When delegating, formulate an objective that asks specific, investigative questions about the codebase, explicitly including these search vectors:
    • Structural Similarity: Ask if existing code uses the same underlying APIs (e.g., "Does any existing code use Intl.DateTimeFormat or setTimeout for similar purposes?").
    • Naming Conventions: Ask if there are existing symbols with similar naming patterns (e.g., "Are there existing symbols with naming patterns like *Format* or *Debounce*?").
    • Comments & Documentation: Ask if keywords from the PR's comments or JSDoc exist in describing similar behavior elsewhere.
    • Architectural Fit: Ask where this type of logic is currently centralized (e.g., "Where is centralized date formatting logic located?").
    • Refactoring Guidance: Crucially, ask the sub-agent to explain how the new code could be refactored to use any existing logic it finds.
  • Generalist Agent: Use the generalist for detailed, turn-intensive comparisons. For example: "Review the implementation of MyNewComponent in the PR and compare it semantically against all components in packages/ui/src. Are there any existing components that could be extended or used instead?"
  • Retain Fast Path for Simple Searches: For extremely simple, unambiguous checks (e.g., "Does package.json include lodash?"), perform a direct search to save time. Default to delegation for any open-ended "investigations."

4. Evaluate Best Practices

Check if the new code aligns with the project's established conventions.

  • Error Handling: Does it use the project's standard error classes or logging mechanisms?
  • State Management: Does it bypass established stores or contexts?
  • Styling: Does it hardcode colors or spacing instead of using theme variables? If the PR introduces a new pattern, compare it against the documented standards and explicitly confirm if an existing project pattern should have been used instead.

5. Formulate Constructive Feedback

If you discover that the PR duplicates existing functionality or ignores a best practice:

  • Provide a clear review comment.
  • Identify the Source: Explicitly mention the absolute or project-relative file path and the specific symbol (function, component, class) that should be reused.
  • Implementation Guidance: Provide a brief code snippet or a clear explanation showing how to integrate the existing code to fulfill the task's requirements.
  • Explain the Value: Briefly explain why reusing the existing code is beneficial (e.g., maintainability, consistency, built-in edge case handling).

Example comment:

"It looks like this PR introduces a new formatDate utility. We already have a robust, tested formatDate function in src/utils/dateHelpers.ts.

You can replace your implementation by importing it like this:

import { formatDate } from '../utils/dateHelpers';// Then use it here:
const displayDate = formatDate(userDate, 'MMM Do, YYYY');

Reusing this ensures that the date formatting remains consistent with the rest of the application and handles timezone conversions correctly."

More from this repositorysame repository

More from this repository

effortgoogle-gemini/gemini-cli

Estimates the implementation effort required to address the given issue.

2026-07-07106.2k
qualitygoogle-gemini/gemini-cli

Evaluates whether a GitHub issue is spam, empty, needs more information, or is OK to proceed.

2026-07-07106.2k
spec-generatorgoogle-gemini/gemini-cli

Generates a structured Workable Spec JSON to guide a Developer Worker.

2026-07-07106.2k
antigravity-supportgoogle-gemini/gemini-cli

Use when the user asks questions, seeks help, or requests instructions related to installing, setting up, or migrating to Antigravity CLI. This skill provides the latest up to date details, requirements, and commands sourced from the official Antigravity CLI documentation.

2026-06-09106.2k
agent-tuigoogle-gemini/gemini-cli

Main Agents: Do NOT use this skill directly. If you need to test the TUI, invoke the `tui_tester` subagent. Drive terminal UI (TUI) applications programmatically for testing, automation, and inspection. Use when: automating CLI/TUI interactions, regression testing terminal apps, or verifying interactive behavior. Also use when: user asks "what is agent-tui", "what does agent-tui do", "demo agent-tui", "show me agent-tui", "how does agent-tui work", or wants to see it in action.

2026-05-18106.2k
tui-testergoogle-gemini/gemini-cli

Expert guidance for testing Gemini CLI behavior and visual output using terminal automation.

2026-05-18106.2k

所有檔案

1 個檔案

安裝 review-duplication

請下載並將技能檔案解壓縮至您的 .claude/skills/ 目錄中。

下載 ZIP

複製儲存庫並將技能檔案複製到您的專案中。

git clone https://github.com/google-gemini/gemini-cli/tree/main/.gemini/skills/review-duplication # Copy the skill folder to .claude/skills/ or .codex/skills/

複製 複製
快速設定: 將技能資料夾複製到 .claude/skills/,Claude 會自動偵測並使用該技能

相關技能

multica-creating-agents
更新時間 2026-08-12
tilemaps
更新時間 2026-08-04
v4-new-features
更新時間 2026-08-04
pixijs-application
更新時間 2026-08-04
OR