Skip to main content

prefer-simpler-patterns-null-check

added in: 1.5.0
🛠
Dart 3.0+
Pro+
preset: recommended

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

Example

❌ Bad:

final object = WithField('hello');

// LINT: Prefer simpler non-null checks. Try replacing it with 'final field?'.
if (object.field case != null && final field) {}

// LINT: This null-check is fully covered by the type annotation. Try removing it.
if (object.field case != null && final String field) {}

✅ 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) {}