prefer-shorthands-with-enums
Suggests using dot shorthands with enums.
Example
❌ Bad:
void fn(MyEnum? e) {
switch (e) {
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
case MyEnum.first:
print(e);
}
final v = switch (e) {
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
MyEnum.first => 1,
_ => 2,
};
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
final MyEnum another = MyEnum.first;
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
if (e == MyEnum.first) {}
}
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
void another({MyEnum value = MyEnum.first}) {}
// LINT: Prefer dot shorthands instead of explicit enum prefixes. Try removing the enum prefix.
MyEnum getEnum() => MyEnum.first;
enum MyEnum { first, second }
✅ Good:
void fn(MyEnum? e) {
switch (e) {
case .first:
print(e);
}
final v = switch (e) {
.first => 1,
_ => 2,
};
final MyEnum another = .first;
if (e == .first) {}
}
void another({MyEnum value = .first}) {}
MyEnum getEnum() => .first;
Object getObject() => MyEnum.first;