find-duplication
tarafından openshift
Kod tabanında kod tekrarını bulur. Mevcut dal değişiklikleriyle sınırlı veya tüm kod tabanı taraması olmak üzere iki modu destekler. Kullanıcı bulma talebinde bulunduğunda kullanılır…
npx skills add https://github.com/openshift/lightspeed-service --skill find-duplicationFind Code Duplication
Detect duplicated or near-duplicate code and suggest consolidation candidates.
Rules
- Report findings, do not refactor. Refactoring is a separate task.
- Focus on production code (
ols/). 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
ols/directory.
For branch mode:
git diff --name-only origin/main -- 'ols/' | grep '\.py$'
For full mode, the target is ols/.
Step 2: Run Pylint Duplicate Detection
uv run pylint --disable=all --enable=duplicate-code --min-similarity-lines=6 <target files or directory>
Review output. Filter out false positives:
- Import blocks (common imports are not duplication)
- Pydantic model boilerplate (Field declarations)
- Single-line patterns (logging, raises)
Step 3: Semantic Duplication Search
Pylint only catches textual similarity. Also look for:
- Similar function signatures — functions with near-identical parameter lists doing similar work.
- Repeated error handling — same try/except/log/return pattern across multiple files.
- Copy-pasted blocks — search for distinctive string literals or variable names that appear in multiple files.
rg "<distinctive pattern>" ols/ --type py -l
Step 4: Classify Findings
For each duplicate found, classify:
| Category | Action |
|---|---|
| Extract — identical logic in 3+ places | Recommend a shared helper |
| Parameterize — same structure, different values | Recommend a common function with parameters |
| Acceptable — similar but serving different domains | Note it, no action needed |
| Test-only — repeated test setup/fixtures | Recommend shared fixture (only if user asked) |
Step 5: Report
For each finding:
- Files and line ranges involved
- What is duplicated (brief description)
- Classification (extract / parameterize / acceptable)
- Suggested location for shared code (if applicable)
Summary: total findings, how many actionable, estimated lines saved.