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.

Earlier measurements

The cleanup record preserves previous comparisons. Rerun the tools to assess the current tree; changing the scanned file set can change percentages without removing duplication.

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 ↗