dejadoc 0.1.1

Find duplicated Rust doctests across a workspace
Documentation

cargo-dejadoc

CI codecov Quality Gate crates.io docs.rs

Whoa, deja vu. A doctest went past us, and then another that looked just like it.

cargo dejadoc scans every doctest your workspace's rustdoc would run, canonicalizes each body through syn, and reports the groups that share a canonical form. Comment and whitespace drift collapse, and local names are alpha-renamed positionally, so bodies that differ only in how they name their variables or functions group together. #-hidden lines keep their content in the body, as rustdoc's doctest source does. Doctest attributes such as no_run are listed per site and never affect the grouping.

Usage

Usage: cargo dejadoc [OPTIONS]

Options:
  -p, --package <PACKAGE>  Restrict to one workspace member by name
      --all-targets        Scan bin and example targets in addition to lib targets
      --json               Machine-readable output
  -t, --threshold <N>      Report groups with at least this many sites (default 2)
      --min-tokens <N>     Skip blocks with fewer tokens than this (default 0)
      --config <PATH>      Explicit `.dejadoc.toml` location
      --no-fail            Exit 0 even when duplicates are found
  -v, --verbose            Print each group's code
  -h, --help               Print help
  -V, --version            Print version

Exit codes. 0 clean or --no-fail, 1 duplicates found, 2 scan or usage error.

Allowing a site

Add the dejadoc token to the fence's info list. rustdoc runs the doctest and ignores the unknown token, so nothing else about the site changes.

/// ```rust,dejadoc
/// fn deliberate_copy() { }
/// ```

Configuration

Parameters live in .dejadoc.toml at the workspace root. CLI flags win.

threshold = 2
min-tokens = 0

GitHub Action

- uses: LucaCappelletti94/cargo-dejadoc@v1
  with:
    threshold: 2

Library

let report = dejadoc::Dejadoc::default().run("tests/fixtures/dupws").unwrap();
assert_eq!(report.groups.len(), 2);

run_targets scans caller-resolved targets in memory and is the no_std entry point.

The Dejadoc builder is no_std and alloc-only. The std feature (defaulted) additionally enables run, .config, Error, exit_code, and the cargo-dejadoc binary.