Skip to content

[duplication]

[duplication] tunes the builtin.duplication.tokens rule.

[duplication]
min_tokens = 100
FieldDefaultEffect
min_tokens100Minimum run length (in tokens) to count as a clone. Lower = more findings.

A run of 100 tokens is roughly 20 lines of typical code — a comfortable “could probably be a helper” threshold.

Use casemin_tokens
Catch every refactor candidate40-60 (noisy)
Default100
Only flag substantial copy-paste200+

Lowering increases recall at the cost of precision; raising does the opposite.

The rule walks the tree-sitter token stream and hashes by token kind — the parser’s terminal type, not the text. Two snippets are “the same” if they share the same sequence of kinds, even with different identifiers and literals.

That makes the rule sensitive to “type-2” clones (renamed copies) but also to incidental structural matches: 100 tokens of let x = 1; let y = 2; ... will match 100 tokens of let foo = "a"; let bar = "b"; .... Tune min_tokens higher if your codebase’s idioms produce false positives.

To turn off the rule entirely, ship a stub override. See Authoring rules → override a built-in.