review-duplication

作者: google-gemini

在程式碼審查期間使用此技能,主動檢查程式碼庫中是否存在重複功能、重新發明輪子或未重複使用現有…的情況。

npx skills add https://github.com/google-gemini/gemini-cli --skill review-duplication

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."

來自 google-gemini 的更多技能

greeter
google-gemini
一個友善的問候技能
official
code-reviewer
google-gemini
針對本地變更與遠端拉取請求的自動化程式碼審查,提供涵蓋正確性、可維護性及安全性的結構化分析。支援本地檔案系統變更(包含暫存與未暫存)及遠端 PR(依編號或網址),並自動透過 GitHub CLI 進行檢出。從七個面向分析程式碼:正確性、可維護性、可讀性、效率、安全性、邊界情況處理及測試覆蓋率。可執行選用的前置驗證套件(例如 npm run preflight)以提前發現問題。
official
review-duplication
google-gemini
在程式碼審查期間使用此技能,主動檢查程式碼庫中是否存在重複功能、重複造輪子或未能重複使用現有…
official
reconciliation
google-gemini
將已載入的費用與預先解析的發票資料庫進行比對,標記出金額不符、遺漏發票及商家不匹配等差異…
official
agent-tui
google-gemini
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…
official
async-pr-review
google-gemini
當使用者想要開始非同步的 PR 審查、對 PR 執行背景檢查,或查看先前開始的非同步 PR 狀態時,觸發此技能…
official
ci
google-gemini
專為 Gemini CLI 設計的高效能、快速失敗的專業技能
official
critique
google-gemini
專長於審計和修復儲存庫腳本及 GitHub Actions 工作流程,以確保技術穩健性與安全性。
official