deslop/duplicate-block
Disallow copy-pasted code blocks duplicated across locations.
- Category: Architecture
- Severity: warn
- Source:
deslop-js - Framework: global
- Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
- Documentation: https://github.com/millionco/deslop-js
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires when deslop's token-based detector finds a maximal repeated block over the configured minTokens/minLines/minOccurrences thresholds and reports a reason like "N occurrences spanning F files (≥T tokens, L lines)" (cross-file, confidence high) or "N occurrences within a single file (≥T tokens, L lines)" (single-file, confidence medium), with an extract-function or extract-module suggestion. The detection mode matters: strict matches only verbatim copies (identifiers, strings, and numbers all kept distinct), while semantic normalizes identifiers/string-literals/numeric-literals to wildcards so structurally-identical blocks with renamed locals or different literal values still match — semantic hits are more likely coincidental, so weigh them against the false-positive boundary harder. False positive a reviewer would suppress: the duplicated block is generated code, a test fixture/snapshot, or boilerplate (route stubs, config scaffolds, near-identical-but-independently-evolving handlers) where the two call sites are unrelated and forcing a shared helper would couple things that should change independently.
Fix prompt
Use this once validation confirms the diagnostic is real.
Extract the repeated block into one shared definition and have every instance call it: hoist the body into a named function (the extract-function hint) and replace each clone with a call, e.g. const result = sharedHelper(args), or move it to a shared module (the extract-module hint) when the clones span multiple files and belong together. Parameterize the parts that legitimately differ rather than copying the block again; if the only differences are renamed locals or literals (a semantic-mode match), confirm the call sites are truly the same concept before unifying. Skip extraction when the copies are generated, are test fixtures, or are boilerplate that genuinely reads clearer duplicated — a premature shared helper couples unrelated call sites. See https://github.com/millionco/deslop-js