Browse documentation

Technical documentation / Reference

Duplicate detection

cargo-dupes and jscpd are maintainer checks for duplicate code. They overlap but detect different kinds of duplication.

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:

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

ToolMetricBefore cleanupAfter round 1Change
cargo-dupesExact groups1,753172-1,581
cargo-dupesExact percent11.48%4.88%-6.60 pp
cargo-dupesNear groups462100-362
cargo-dupesNear percent3.61%3.71%+0.10 pp
jscpdDuplication10.00%9.08%-0.92 pp
jscpdCloned blocks1,4991,508+9

Round 2 (historical): provider/test fixture deduplication

ToolMetricAfter round 1After round 2Change
cargo-dupesExact groups172167-5
cargo-dupesExact percent4.88%4.64%-0.24 pp
cargo-dupesNear groups100101+1
cargo-dupesNear percent3.71%3.75%+0.04 pp
jscpdDuplication9.08%8.71%-0.37 pp
jscpdCloned blocks1,5081,458-50
jscpdDuplicated lines15,55314,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.

Edit this page on GitHub ↗