avoid-bottom-type-in-patterns
Warns when a pattern contains a void
, Never
or Null
type.
Presence of these types inside a pattern is most likely a bug.
Example
❌ Bad:
final object = WithField('hello');
// LINT: Avoid the 'Null' type inside patterns. Try using a different type.
if (object case Null()) {}
// LINT: Avoid the 'Never' type inside patterns. Try using a different type.
if (object case Never()) {}
// LINT: Avoid the 'Null' type inside patterns. Try using a different type.
if (object case final Null value) {}
// LINT: Avoid the 'Never' type inside patterns. Try using a different type.
if (object case final Never value) {}
final value = switch (object) {
// LINT: Avoid the 'Null' type inside patterns. Try using a different type.
Null() => 'bad',
// LINT: Avoid the 'Never' type inside patterns. Try using a different type.
Never() => 'bad',
};
✅ Good:
final object = WithField('hello');
if (object == null) {}
if (object case == null) {} // Correct, 'null' instead of 'Null'
if (object case WithField()) {}
final value = switch (object) {
== null => 'good',
_ => 'good',
};