avoid-similar-names
Checks for names within the scope that are very similar and thus confusing.
⚙️ Config
Set show-similarity
(default is false
) to display similarity in the issue message.
Set similarity-threshold
(default is 0.8
) to tune the similarity comparison.
Set ignored-names
(default is empty) to ignore specific names (example).
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-similar-names:
show-similarity: false
similarity-threshold: 0.8
ignored-names:
- some
- name
Example
❌ Bad:
void main() {
final value = '1';
// LINT: This variable name is similar to: value. Try giving this variable a more distinctive name.
final value2 = '2';
}
✅ Good:
void main() {
final value = '1';
final anotherValue = '2';
}
Example with "ignored-names"
Config
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-similar-names:
ignored-names:
- value
✅ Good:
void main() {
final value = '1';
final value1 = '2'; // Correct, ignored
}