Duplicate code detection
Finds copied blocks so a fix in one copy is not missed in the others, and flags new code that re-implements an existing helper.
Sub-techniques
2
| ID | Name | Description |
|---|---|---|
V1011.001 | Token clone detection | Report token-identical or near-identical blocks above a size threshold. |
V1011.002 | Semantic reuse check | Search the codebase for an existing function that does what the new code does, by embedding or by name. |
Craft it
- Run a clone detector with a minimum token count that ignores tests and generated code.
- Report only clones introduced by the change.
- For reuse, index function signatures and docstrings and query with each new function.
Reverse engineer it
Signs that a codebase already runs this technique, and where to read how it is configured.
- .jscpd.json or a cpd task in the build.
- Review comments asking to reuse an existing helper point at where this is missing.
Open-source packages
3
- jscpd kucherenko/jscpd
- PMD (CPD) pmd/pmd
- Sentence Transformers huggingface/sentence-transformers