avoid_duplicate_code
A lint rule that detects duplicated code blocks (clones) within a single file and across multiple files in the project.
When two or more function/method/constructor bodies have structurally identical AST subtrees (Type 2 clones — same structure, variable names may differ), the rule reports all copies and provides context messages linking to the other occurrences.
Cross-file detection works on a "best-effort" basis: duplicates are detected against files that have already been analyzed in the current session. The detection improves as more files are analyzed.
Example config:
plugins:
solid_lints:
diagnostics:
avoid_duplicate_code:
min_tokens: 50
ignore_literals: false
ignore_identifiers: true
check_blocks: false
exclude:
- method_name: build
Parameters
min_tokens (int)
Minimum number of tokens in a function body or block to be considered for clone detection. Bodies/blocks shorter than this are ignored.
ignore_literals (bool)
When true, literal values (strings, numbers, booleans) are excluded
from the structural hash, making the check ignore literal differences.
ignore_identifiers (bool)
When true, local variable and parameter names are excluded
from the structural hash, allowing detection of renamed variables
(Type 2). Note that method, class, and field names are NOT ignored
to prevent excessive false positives.
check_blocks (bool)
When true, statement blocks (like if-blocks or loops) inside functions
are also checked for duplication.
exclude (String | Map | List<String | Map>)
A list of methods/functions that should be excluded from the lint.