| name | deduplicate-code |
| description | Use when the user wants to find and remove code duplication, says "deduplicate", "art-dupl", or wants to reduce duplication to ZERO. This skill is all about JUDGMENT and ZERO HARMFUL duplication. It does NOT mean zero report lines.
|
| metadata | {"tags":"deduplication, quality, cleanup, art-dupl"} |
Deduplicate Code
Run
art-dupl --semantic --sort total-tokens -t 5 --html
View the HTML output directly — do not save it as a file. Threshold (-t)
counts duplicated statements (not AST nodes); 5 skips one-liner idioms
while catching real clones. Use whatever threshold the user specifies.
Generated code (sqlc, protobuf, mockgen, stringer, templ) and test-file
noise are auto-excluded by default — add --exclude-pattern only when a
path genuinely slips past the detector.
Iterate to Zero
For every clone group: read it, then extract, accept, or exclude.
Re-run art-dupl after each refactor — keep going until only intentional
duplication remains. Run tests after every change. Do not stop at "good
enough"; stop when the report is clean or every remaining clone has a
defensible reason to exist.
Judgment: Harmful vs Acceptable
Eliminate — the duplication is a real maintenance burden:
- Same logic, different names (a semantic clone)
- Must change in N places to keep behavior consistent
- A clear domain name exists for the shared concept
- Shared setup, fixtures, or boilerplate across multiple packages
Accept — the similarity is intentional or idiomatic:
- Different business rules or domain contexts behind a similar shape
- Table-driven tests, standard assertions (
Expect(err).ToNot(HaveOccurred()))
- Generated code (never hand-edit — exclude it, or
--include-generated to inspect)
- An abstraction would take more parameters than the duplicated code has lines
When accepting, leave a one-line rationale so the next reader knows it was
deliberate.
Done
Zero harmful duplication — not zero report lines. Every remaining clone
is there on purpose, every change is verified by tests.