Duplicate detection
cargo-dupes and jscpd are maintainer checks for duplicate code. They overlap but detect different kinds of duplication.
cargo-dupes: Rust AST duplicate detector. Finds exact and near duplicate Rust code units with structural similarity.jscpd: token/text duplicate detector. Scans Rust plus Markdown/JSON/TOML repo docs and config through.jscpd.json.
Install
cargo install cargo-dupes --locked
npm install -g jscpd
Run
Run from repo root:
cargo dupes stats
cargo dupes report
cargo dupes check
jscpd --config .jscpd.json .
Generated jscpd JSON reports go under target/duplicate-reports/jscpd/; do not commit generated reports.
Interpret results
cargo dupes stats reports exact groups, near groups, duplicate units, duplicate lines, and duplicate percentages. Exact groups are copy-equivalent AST units. Near groups are structurally similar Rust units over configured similarity_threshold.
cargo dupes report lists duplicate groups and source spans. Use it to identify refactor targets before changing thresholds or ignore lists.
cargo dupes check enforces repo thresholds from dupes.toml:
max_exact_duplicatesmax_near_duplicatesmax_exact_percentmax_near_percent
jscpd --config .jscpd.json . prints clone spans and writes JSON summary. Its total percentage is duplicated lines divided by analyzed lines. Markdown code fences may be reported by their fenced language, so console rows can include formats such as bash even though config targets Markdown files.
Cleanup metrics
Round 1: P1-P5 core dedup
| Tool | Metric | Before cleanup | After round 1 | Change |
|---|---|---|---|---|
| cargo-dupes | Exact groups | 1,753 | 172 | -1,581 |
| cargo-dupes | Exact percent | 11.48% | 4.88% | -6.60 pp |
| cargo-dupes | Near groups | 462 | 100 | -362 |
| cargo-dupes | Near percent | 3.61% | 3.71% | +0.10 pp |
| jscpd | Duplication | 10.00% | 9.08% | -0.92 pp |
| jscpd | Cloned blocks | 1,499 | 1,508 | +9 |
Round 2 (historical): provider/test fixture deduplication
| Tool | Metric | After round 1 | After round 2 | Change |
|---|---|---|---|---|
| cargo-dupes | Exact groups | 172 | 167 | -5 |
| cargo-dupes | Exact percent | 4.88% | 4.64% | -0.24 pp |
| cargo-dupes | Near groups | 100 | 101 | +1 |
| cargo-dupes | Near percent | 3.71% | 3.75% | +0.04 pp |
| jscpd | Duplication | 9.08% | 8.71% | -0.37 pp |
| jscpd | Cloned blocks | 1,508 | 1,458 | -50 |
| jscpd | Duplicated lines | 15,553 | 14,878 | -675 |
Policy
Prefer fixing duplicates to ignoring them. Add excludes or ignore fingerprints only when duplicate code is generated, vendored, or intentionally repeated for safety or readability, and document the reason in review. Do not ignore actionable source areas to make thresholds pass.