Whoa, deja vu. A doctest went past us, and then another that looked just like it.
cargo dejadoc finds duplicated Rust doctests, and optionally duplicated functions and code blocks, across a workspace. The wiki explains each check, the options and the Action in depth.
cargo install dejadoc
cargo dejadoc --functions --context-blocks| Check | Enable | Default minimum size | Set the size |
|---|---|---|---|
| Doctests | On by default | 0 tokens |
--min-tokens |
| Functions | --functions |
30 weighted body tokens |
--fn-min-tokens |
| Contexts | --context-blocks |
30 canonical weighted tokens |
--context-min-tokens |
Options can also live in .dejadoc.toml at the workspace root, and cargo dejadoc --help lists them all. Keep an intentional copy with a rust,dejadoc fence or a // dejadoc: allow line above the function. The wiki lists what counts as the same code.
on: pull_request
jobs:
dejadoc:
runs-on: ubuntu-latest
permissions:
contents: read
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 }}
functions: trueThe action reviews the pull request and suggests removing each copy it introduces. action.yml lists every input, and these two workflows review pull requests from forks.
let report = dejadoc::Dejadoc::default()
.functions()
.context_blocks()
.run(".")
.unwrap();
println!("{}", dejadoc::human(&report, false));Use default-features = false, features = ["std"] to drop the CLI. Coding agents get the same guidance from the dejadoc skill.
npx skills add LucaCappelletti94/cargo-dejadoc