dejadoc 0.1.8

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 and canonicalizes every doctest your workspace's rustdoc would run, reporting any identified duplicates. Items are kept by their cfg as rustdoc sees them on a 64-bit Linux host with every feature on, test off and custom cfgs off.

A pull request review by dejadoc, with an inline comment on a duplicated doctest and a suggestion that removes the copy

The flags under cargo dejadoc --help restrict the package, set the threshold and minimum token count, point at a config file, and switch the output to JSON. Without flags, parameters come from .dejadoc.toml at the workspace root.

To allow a known copy, add the dejadoc token to the fence's info list, as in rust,dejadoc. rustdoc runs the doctest and ignores the unknown token, so nothing else about the site changes.

In CI, the composite action installs the crate and runs the gate.

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

In a pull request, the action posts the findings as a review instead of failing the job.

on: pull_request
jobs:
  dejadoc:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: LucaCappelletti94/cargo-dejadoc@v1
        with:
          pr-number: ${{ github.event.pull_request.number }}

Review mode reports only the duplicates your pull request introduces, comparing each site against a scan of the base commit. Comments land on the copies to remove, a kept copy never gets one. Each comment links the copy that survives and GitHub renders those lines right in the comment, long ones collapsed behind a show link. The link points at the base commit for pre-existing copies and at the first added copy for groups the pull request created, and the removal suggestion deletes the copy together with an empty line left behind. Sites GitHub cannot anchor get permalinks in the review body. Set only-new: false to also report duplicates that predate the pull request.

Forks run with a read-only GITHUB_TOKEN, the action skips the review and the job passes. To review forks, trigger on pull_request_target and check out the pull request head as below, a trigger that runs with write access, so read GitHub's guidance before opting the checkout in with allow-unsafe-pr-checkout.

on: pull_request_target
jobs:
  dejadoc:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          allow-unsafe-pr-checkout: true
      - uses: dtolnay/rust-toolchain@stable
      - uses: LucaCappelletti94/cargo-dejadoc@v1
        with:
          pr-number: ${{ github.event.pull_request.number }}

On a private repository, the setting Send write tokens to workflows from pull requests under Settings > Actions > General does the same without changing the trigger.

The library builds the same report in memory.

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