avoid-duplicate-collection-elements
- Group
- Correctness
- Path
lint/correctness/avoid-duplicate-collection-elements- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 47 of 512
Flags repeated scalar literals and stable local reads in list and set literals.
Duplicate entries often indicate a copy-and-paste mistake. Comparisons retain
literal spelling. Calls, getters, spreads, and control-flow elements end the
comparison region, since they can change values or contribute unknown items.
Map keys are covered separately by avoid-duplicate-map-keys.
Invalid
void f(int value, String text) {
final a = [1, 1];
final b = {'a', 'a'};
final c = [true, true];
final d = [null, null];
final e = [value, value];
final g = [text, text];
final h = [1, 2, 1];
}void f(int value, String text) { final a = [1, 1]; final a = [1, 1]; final b = {'a', 'a'}; final b = {'a', 'a'}; final c = [true, true]; final c = [true, true]; final d = [null, null]; final d = [null, null]; final e = [value, value]; final e = [value, value]; final g = [text, text]; final g = [text, text]; final h = [1, 2, 1];Valid
int next() => 1;
void f(int value, bool condition, List<int> other) {
final a = [1, 2];
final b = ['a b', 'ab'];
final c = [next(), next()];
final d = [value, value++];
final e = [value, next(), value];
final g = [1, ...other, 1];
final h = [if (condition) 1 else 1];
final i = [[1], [1]];
final j = ['$value', '$value'];
}
class Base {
int value = 0;
List<int> values() => [value, value];
}
class Changing extends Base {
int counter = 0;
@override
int get value => counter++;
@override
set value(int next) {}
}Configure avoid-duplicate-collection-elements
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-duplicate-collection-elements": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-duplicate-collection-elements: <reason>More correctness rules
- avoid-duplicate-exports
Flags export directives whose visible names are already covered by another export.
- avoid-duplicate-factories
Flags factories in one type with the same implementation, ignoring factory names and alpha-renaming parameters by position.
- avoid-duplicate-initializers
Flags final/const variables with identical initializers in the same scope.
- avoid-duplicate-map-keysrecommended
Flags repeated literal keys in map literals, including literal spreads and collection
ifentries. - avoid-duplicate-mixins
Flags repeated mixins in a with clause or a same-library superclass chain.
- avoid-duplicate-named-imports
Flags imports of the same library that differ only in their name prefix.
- avoid-duplicate-switch-case-conditionsrecommended
Flags repeated
whenguards on syntactically identical switch patterns. - avoid-duplicate-test-assertionsrecommendedtest
Reports repeated identical, side-effect-free assertions in a straight-line block.