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');
if (object case Null()) {} // LINT
if (object case Never()) {} // LINT
if (object case final Null value) {} // LINT
if (object case final Never value) {} // LINT
if (object case Never() || Null()) {} // LINT
if (object case Never() || WithField()) {} // LINT
final value = switch (object) {
Null() => 'bad', // LINT
Never() => 'bad', // LINT
};
✅ Good:
final object = WithField('hello');
if (object == null) {}
if (object case == null) {}
if (object case WithField()) {}
final value = switch (object) {
== null => 'good',
_ => 'good',
};