Skip to main content

find-duplication

Find code duplication in the codebase. Supports two modes - scoped to current branch changes or a full codebase sweep. Use when the user asks to find duplicated code, copy-paste, repeated patterns, or wants to deduplicate before a PR.

소스 정보

저장소
openshift/lightspeed-agentic-operator
최근 소스 활동
2026년 5월 10일 16:04
감지된 SKILL.md 언어
영어
스타
15
포크
28

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
find-duplication
description
Find code duplication in the codebase. Supports two modes - scoped to current branch changes or a full codebase sweep. Use when the user asks to find duplicated code, copy-paste, repeated patterns, or wants to deduplicate before a PR.
disable-model-invocation
true
# Find Code Duplication Detect duplicated or near-duplicate Go code and suggest consolidation candidates. ## Rules - Report findings, do not refactor. Refactoring is a separate task. - Focus on production code (`controller/`, `api/`, `cmd/`, `cli/`). Skip test duplication unless explicitly asked. - Group findings by severity: exact duplicates first, then near-duplicates. - For each finding, state whether extraction is worth it or acceptable duplication. ## Step 1: Determine Scope Ask the user: - **Branch mode**: only files changed in the current branch vs main. - **Full mode**: scan the entire codebase. For branch mode: ```bash git diff --name-only upstream/main -- 'controller/' 'api/' 'cmd/' 'cli/' | grep '\.go$' | grep -v '_test\.go$' ``` For full mode, the target is `controller/ api/ cmd/ cli/`. ## Step 2: Run dupl Install and run dupl to find duplicate code blocks: ```bash go install github.com/mibk/dupl@latest dupl -threshold 15 <target> ``` `-threshold 15` means at least 15 tokens of duplication. Lower values = more noise. Review output and filter false positives: - Import blocks (common imports are not duplication) - Error constant declarations (repeated pattern is intentional) - Single-line patterns (logging, error wrapping) - Kubebuilder boilerplate (RBAC markers, webhook setup) ## Step 3: Semantic Duplication Search dupl only catches textual similarity. Also look for: 1. **Similar function signatures** — functions with near-identical parameter lists doing similar work across different packages. 2. **Repeated error handling** — same `if err != nil { return fmt.Errorf(...) }` pattern with slight variations. 3. **Copy-pasted reconciler logic** — similar reconciliation patterns across different controllers. 4. **Duplicated struct definitions** — similar structs in different packages (candidate for shared types). Search for patterns: ```bash # Find similar error wrapping rg "fmt\.Errorf.*%w.*err\)" controller/ api/ cmd/ cli/ -A 1 -B 1 # Find similar reconciler patterns rg "func.*Reconcile" controller/ -l # Find similar generation helpers rg "func Generate" controller/ -l ``` ## Step 4: Check for Repeated Utilities Look for utility functions that appear in multiple packages: ```bash # Find GetSecretContent-like patterns rg "func.*GetSecret" controller/ api/ cmd/ cli/ -l # Find generation helpers rg "func.*Generate.*Labels" controller/ api/ cmd/ cli/ -l # Find comparison helpers rg "func.*Equal\(" controller/ api/ cmd/ cli/ -l ``` These should live in a single shared place (e.g. a small helper file or package under `controller/`) rather than copy-pasted across packages. ## Step 5: Classify Findings For each duplicate found, classify: | Category | Action | |----------|--------| | **Extract** — identical logic in 3+ places | Recommend a shared helper (e.g. under `controller/` or a small `pkg/`) | | **Parameterize** — same structure, different values | Recommend a common function with parameters | | **Acceptable** — similar but serving different domains (app server vs lcore) | Note it, no action needed | | **Boilerplate** — kubebuilder/controller-runtime patterns | Skip, this is framework convention | | **Test-only** — repeated test setup/fixtures | Recommend shared test fixture (only if user asked) | ## Step 6: Report For each finding: 1. Files and line ranges involved 2. What is duplicated (brief description) 3. Token/line count 4. Classification (extract / parameterize / acceptable / boilerplate) 5. Suggested location for shared code (e.g. next to callers or a small internal helper package) Summary: total findings, how many actionable, estimated lines saved.
GitHub에서 보기