Skip to main content

prefer-simpler-patterns-null-check

added in: 1.5.0
🛠
Dart 3.0+

Warns when a patterns check for non-nullability can be simplified.

Example

❌ Bad:

final object = WithField('hello');

if (object.field case != null && final field) {} // LINT
if (object.field case final field && != null) {} // LINT
if (object.field case != null && final String field) {} // LINT
if (object.field case final String field && != null) {} // LINT

✅ Good:

final object = WithField('hello');

if (object.field case final String field) {}
if (object.field case final field?) {}
if (object.field case != null) {}
if (object.field case != null || final field) {}