cargo-duplicated

Crates.iocargo-duplicated
lib.rscargo-duplicated
version0.2.0
created_at2025-12-23 21:12:14.347071+00
updated_at2025-12-30 15:00:32.433355+00
descriptionA tool to detect duplicated Rust code blocks.
homepage
repositoryhttps://github.com/bircni/cargo-duplicated
max_upload_size
id2002345
size87,040
Nicolas (bircni)

documentation

README

cargo-duplicated

Crates.io Github All Releases MIT licensed CI

A command-line tool to detect duplicated Rust code blocks with configurable thresholds.

Features

  • Scans Rust source files and reports duplicated code blocks
  • Normalizes whitespace and ignores comment-only lines
  • Configurable thresholds via dups.toml
  • Optional JSON output for automation
  • Exclude patterns and test detection via #[test] / #[cfg(test)]

Installation

You need Rust installed.

cargo install cargo-duplicated

Or build locally:

cargo build --release

Usage

Find duplicated Rust code blocks

Usage: cargo-duplicated [OPTIONS] [PATH]

Arguments:
  [PATH]  Path to scan [default: .]

Options:
      --config <CONFIG>   Path to config file (defaults to <path>/dups.toml)
      --format <FORMAT>   Output format [default: human] [possible values: human, json]
      --include-tests     Include files that contain #[test] or #[cfg(test)]
      --exclude <EXCLUDE> Exclude path glob (relative to root). Can be repeated.
  -h, --help              Print help
  -V, --version           Print version

Examples:

cargo-duplicated .
cargo-duplicated --format json .
cargo-duplicated --exclude "src/generated/**" --exclude "**/fixtures/**" .
cargo-duplicated --config ./configs/dups.toml .

Configuration

Create a dups.toml file in the repo you want to scan. You can start from

dups-example.toml.

min_lines = 5
min_occurrences = 2
exclude = ["target/**", "src/generated/**"]
include_tests = false

Notes:

  • include_tests = false skips files containing #[test] or #[cfg(test)].
  • The --config flag overrides the default <path>/dups.toml.
  • Exit codes: 0 no duplicates, 1 duplicates found, 2 errors.

Development

  • Requires Rust 1.88+ (edition 2024)
  • Linting: cargo clippy
  • Tests: cargo test
Commit count: 0

cargo fmt