avoid-duplicate-map-keys
- Group
- Correctness
- Path
lint/correctness/avoid-duplicate-map-keys- Default
- On (recommended)
- Origin
- Falcon
- Rule
- 51 of 512
Flags repeated literal keys in map literals, including literal spreads and collection if entries.
A later key replaces the earlier value. Only scalar literal keys with equal
token spelling are compared; arbitrary expressions and unknown spreads are
left alone. Mutually exclusive if branches are checked independently.
Invalid
void f(bool condition) {
final first = {'a': 1, 'a': 2};
final second = {1: 'a', 1: 'b'};
final third = {true: 1, true: 2};
final fourth = {null: 1, null: 2};
final fifth = {'a': 1, ...{'a': 2}};
final sixth = {'a': 1, if (condition) 'a': 2};
final seventh = {if (condition) 'a': 1, 'a': 2};
}void f(bool condition) { final first = {'a': 1, 'a': 2}; final first = {'a': 1, 'a': 2}; final second = {1: 'a', 1: 'b'}; final second = {1: 'a', 1: 'b'}; final third = {true: 1, true: 2}; final third = {true: 1, true: 2}; final fourth = {null: 1, null: 2}; final fourth = {null: 1, null: 2}; final fifth = {'a': 1, ...{'a': 2}}; final fifth = {'a': 1, ...{'a': 2}}; final sixth = {'a': 1, if (condition) 'a': 2}; final sixth = {'a': 1, if (condition) 'a': 2}; final seventh = {if (condition) 'a': 1, 'a': 2};Valid
int next() => 1;
void f(bool condition, Map<String, int> other) {
final distinct = {'a': 1, 'b': 2};
final types = <Object, int>{1: 1, '1': 2};
final branches = {if (condition) 'a': 1 else 'a': 2};
final unknown = {'a': 1, ...other};
final effects = {next(): 1, next(): 2};
final spaces = {'a b': 1, 'ab': 2};
final scopes = {'a': {'a': 1}};
final interpolated = {'$condition': 1, '$condition': 2};
}Configure avoid-duplicate-map-keys
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-duplicate-map-keys": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-duplicate-map-keys: <reason>More correctness rules
- 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.
- avoid-dynamic-calls
avoid_dynamic_callsrecommendedAvoid method calls or property accesses on a
dynamictarget. - avoid-emit-outside-blocrecommendedbloc
Flags external calls and tear-offs of a Bloc or Cubit's
emitmethod. - avoid-empty-setstaterecommendedflutter
Avoid setState callbacks with empty block bodies.
- avoid-empty-test-groupstest
Reports inline framework groups without any test registrations.