Repository navigation
Checks
dejadoc runs up to three checks. Each one turns code into a canonical form, groups the sites that share a form, and reports every group with at least --threshold sites, 2 by default.
| 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 |
Size floors are inclusive and independent of each other. For functions and contexts a path, a lifetime or a multi-character operator weighs one token, and commas and brackets weigh nothing, so long paths do not inflate small functions.
Every doctest in the scanned targets is compared with every other one. Library doctests are scanned by default, and --all-targets adds binaries and examples. A block that several items share counts once.
Each group names a copy to keep. A copy whose code names its own item comes first, so the example on Vec::push that calls push wins over a copy elsewhere. File and line order break ties. The other copies can always go.
Functions compare within their own module, across every target and cfg variant. Test markers, #[should_panic] and #[ignore] keep otherwise identical tests apart.
Comparisons use the module's original files, its imports and each function's enclosing owner. Two calls to different helpers that share a name stay different. Copies in different impl blocks match up to their owner and its generic parameters, while two methods of one owner that use different parameters stay apart.
A function group names a copy to keep in the same way as a doctest group, and it carries a remedy. The first row that applies wins.
| Remedy | When | What to do |
|---|---|---|
generic-or-macro |
Methods on different self types | Share one body through a generic or a macro |
helper-or-macro |
A trait or an exported symbol needs each copy | Keep the signatures and move the body into a helper or a macro |
merge-cfg |
Free functions or inherent methods differ only by cfg
|
Write one function that covers both cfg cases |
delete |
Anything else | Delete all copies but the first, or point their callers at it |
Only free functions and inherent methods receive deletion suggestions. Public library API, exported symbols and copies with different cfg or self types need a refactor instead.
The context check compares smaller pieces of code: whole function bodies, explicit blocks, complete match arms and closures. Each one is normalized on its own, so a duplicated block inside two otherwise different functions is found. Arm patterns, guards and closure inputs count towards the size.
These matches are approximate. The check cannot see what surrounds a block, so it never names a copy to keep and never suggests a deletion. Context groups also never appear in GitHub Action reviews.
When a larger group contains every site of a smaller one, only the larger group is reported. Each site carries a half-open source range with 1-based lines and 1-based byte columns, counted in the original file bytes, including any BOM or shebang.
cargo dejadoc --context-blocks --context-min-tokens 30