From ea1d98309a0697d33c66b5b9c9ac774bd83ad0b8 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Mon, 25 Dec 2023 21:34:46 +0100 Subject: [PATCH] Document softCheckHideNull --- lib/src/checks/checks_nullability.dart | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/src/checks/checks_nullability.dart b/lib/src/checks/checks_nullability.dart index e5363a8c..52312a0f 100644 --- a/lib/src/checks/checks_nullability.dart +++ b/lib/src/checks/checks_nullability.dart @@ -28,6 +28,8 @@ extension HideNullableSubject on Subject { } } +/// Like [softCheck] but ignores isNotNull() errors when the actual value is null +/// /// Workaround allowing to use /// `hasProp((subject)=> subject.equals(X));` /// instead of @@ -38,15 +40,14 @@ CheckFailure? softCheckHideNull(T value, Condition condition) { final failure = softCheck(value, condition); if (failure == null) { return null; - } else { - final errorParts = describe(condition).map((it) => it.trim()).toList(); - final errorMessage = errorParts.join(' '); - if (errorParts.last == 'is null' && - failure.rejection.actual.firstOrNull == '') { - // property is null and isNull() was called - // not error because null == null - return null; - } - return failure; } + final errorParts = describe(condition).map((it) => it.trim()).toList(); + final errorMessage = errorParts.join(' '); + if (errorParts.last == 'is null' && + failure.rejection.actual.firstOrNull == '') { + // property is null and isNull() was called + // not error because null == null + return null; + } + return failure; }