avoid-missing-enum-constant-in-map
- Group
- Correctness
- Path
lint/correctness/avoid-missing-enum-constant-in-map- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 86 of 512
Require enum-keyed map literals to include every declared enum value.
Key types and constant identities come from resolution, including contextual types, imported enums, aliases and dot shorthands. Build-independent constant branches and statically known spreads contribute keys; unknown coverage disables the check.
Invalid
enum Color { red, green, blue }
const redAlias = Color.red;No diagnostics in this file.
Valid
enum Color { red, green, blue }
enum Other { red, green, blue }
const redAlias = Color.red;
final complete = {Color.red: 1, Color.green: 2, Color.blue: 3};
final aliases = {redAlias: 1, Color.green: 2, Color.blue: 3};
final strings = {'red': 1};
final integers = <int, String>{};
final unrelated = <Object, int>{Color.red: 1, Other.green: 2};
final nullable = <Color?, int>{null: 0, Color.red: 1, Color.green: 2, Color.blue: 3};
Map<Color, int> unknownKey(Color color) => {color: 1};
Map<Color, int> unknownSpread(Map<Color, int> source) => {...source};
Map<Color, int> dynamicBranch(bool flag) => {
Color.red: 1,
if (flag) Color.green: 2 else Color.blue: 3,
};
Map<Color, int> forValues() => {for (final color in Color.values) color: 1};
class NotAnEnum {
static const first = NotAnEnum();
static const second = NotAnEnum();
const NotAnEnum();
}
final notEnum = {NotAnEnum.first: 1};
final environmentBranch = <Color, int>{
if (const bool.fromEnvironment('HAS_RED')) Color.red: 1 else Color.green: 1,
Color.green: 2,
Color.blue: 3,
};
const environmentFlag = bool.fromEnvironment('HAS_RED');
final nestedEnvironmentBranch = <Color, int>{
...{
if (environmentFlag) Color.red: 1 else Color.green: 1,
},
Color.green: 2,
Color.blue: 3,
};
const accent = bool.fromEnvironment('ACCENT') ? Color.red : Color.green;
final environmentKey = <Color, int>{accent: 1, Color.green: 2, Color.blue: 3};
final inlineEnvironmentKey = <Color, int>{
(const bool.fromEnvironment('ACCENT') ? Color.red : Color.green): 1,
Color.green: 2,
Color.blue: 3,
};
const environmentTable = <Color, int>{
if (bool.fromEnvironment('HAS_RED')) Color.red: 1,
Color.green: 2,
Color.blue: 3,
};
final namedEnvironmentSpread = <Color, int>{...environmentTable};
const conditionalEnvironmentTable = bool.fromEnvironment('HAS_RED')
? <Color, int>{Color.red: 1, Color.green: 2, Color.blue: 3}
: <Color, int>{};
final conditionalEnvironmentSpread = <Color, int>{
...conditionalEnvironmentTable,
Color.green: 2,
Color.blue: 3,
};
void localEnvironmentCoverage() {
const accent = bool.fromEnvironment('ACCENT') ? Color.red : Color.green;
final map = <Color, int>{accent: 1, Color.green: 2, Color.blue: 3};
const table = bool.fromEnvironment('HAS_RED')
? <Color, int>{Color.red: 1, Color.green: 2, Color.blue: 3}
: <Color, int>{};
final spread = <Color, int>{...table, Color.green: 2, Color.blue: 3};
}
const shadowedKey = Color.green;
void shadowedLocalKey() {
const shadowedKey = Color.red;
const key = shadowedKey;
for (final shadowedKey in Color.values) {
final map = <Color, int>{key: 1, Color.green: 2, Color.blue: 3};
}
}Configure avoid-missing-enum-constant-in-map
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-missing-enum-constant-in-map": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-missing-enum-constant-in-map: <reason>More correctness rules
- avoid-missing-interpolationrecommended
Flags missing interpolation around visible String variables or member accesses and calls.
- avoid-misused-hooksrecommendedflutter_hooks
Flags confirmed Flutter hooks called directly in non-hook Flutter widget builds.
- avoid-mounted-in-setstateflutter
Check mounted before invoking Flutter State.setState, never inside its callback.
- avoid-mutable-equatable-subclass-fieldsrecommendedequatable
Flags mutable instance fields on subclasses inheriting Equatable equality.
- avoid-mutable-global-variables
avoid_mutable_global_variablesDisallow mutable top-level variables.
- avoid-nested-futures
Avoid
Future<Future<T>>,FutureOr<Future<T>>, and other directly nested future wrappers. - avoid-nested-streams-and-futures
Avoid directly nesting SDK streams and futures:
Stream<Future<T>>andFuture<Stream<T>>complicate consumption. - avoid-read-inside-buildrecommendedprovider
Flags non-listening Provider reads directly inside Flutter widget builds.