53 lines
1.5 KiB
Markdown
53 lines
1.5 KiB
Markdown
---
|
|
name: duplicate-code-check
|
|
description: >-
|
|
Find and report code duplication introduced by a merge request.
|
|
Use when asked to check for duplicates, repeated logic, or copy-paste code
|
|
in a branch or MR diff.
|
|
---
|
|
|
|
# Duplicate Code Check
|
|
|
|
Scans the diff of a branch or merge request for duplicated logic and produces a structured report with locations, severity and suggested actions. Does not remove any code without explicit user approval.
|
|
|
|
## Input
|
|
|
|
User should provide:
|
|
|
|
- branch name where duplication check should be done
|
|
- target branch name to compare
|
|
|
|
## Steps
|
|
|
|
1. Fetch the diff for the branch or MR
|
|
|
|
2. Scan the diff for duplicate blocks. Use criteria:
|
|
|
|
- identical or near-identical method bodies (more than 10 lines);
|
|
- copy-pasted conditional blocks or switch/case arms;
|
|
- repeated string literals or constants that could be extracted;
|
|
- utility functions that already exist elsewhere in the codebase.
|
|
|
|
3. Ask the user before suggesting any removal
|
|
|
|
4. Write the report.
|
|
|
|
## Output format
|
|
|
|
Create the file `duplication-check-<branch name>.md` with the table with next columns:
|
|
- all duplications
|
|
- risk level of removing each code duplication
|
|
- user decision is necessary.
|
|
|
|
## Rules
|
|
|
|
- Always check that safe delete is being suggested and there are no usages of removed code.
|
|
- Always ask before removing any code duplication.
|
|
|
|
## Passing criteria
|
|
|
|
The skill is complete only if:
|
|
|
|
- all files in the diff were scanned;
|
|
- no code was modified without explicit user approval;
|
|
- the report is written to `duplication-check-<branch name>.md` file. |