From 6b94de76e0225b5ca2190851fa9e9ae8ef2c2479 Mon Sep 17 00:00:00 2001 From: Andrii Date: Thu, 14 Mar 2024 11:49:35 +0200 Subject: [PATCH 1/3] - Fixed unexpected avoid_unnecessary_type_assertions --- lib/src/utils/typecast_utils.dart | 4 ++-- .../avoid_unnecessary_type_assertions_test.dart | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/src/utils/typecast_utils.dart b/lib/src/utils/typecast_utils.dart index be228d16..f9c4d137 100644 --- a/lib/src/utils/typecast_utils.dart +++ b/lib/src/utils/typecast_utils.dart @@ -67,7 +67,7 @@ class TypeCast { final objectCastedType = castTypeInHierarchy(); if (objectCastedType == null) { - return isReversed; + return false; } final objectTypeCast = TypeCast( @@ -77,7 +77,7 @@ class TypeCast { if (!objectTypeCast.areGenericsWithSameTypeArgs) { return false; } - + return !isReversed; } diff --git a/lint_test/avoid_unnecessary_type_assertions_test.dart b/lint_test/avoid_unnecessary_type_assertions_test.dart index c95e47f6..222441eb 100644 --- a/lint_test/avoid_unnecessary_type_assertions_test.dart +++ b/lint_test/avoid_unnecessary_type_assertions_test.dart @@ -1,4 +1,4 @@ -// ignore_for_file: prefer_const_declarations +// ignore_for_file: prefer_const_declarations, prefer_match_file_name, unused_element // ignore_for_file: unnecessary_nullable_for_final_variable_declarations // ignore_for_file: unnecessary_type_check // ignore_for_file: unused_local_variable @@ -34,3 +34,14 @@ void fun() { // casting `Type? is Type` is allowed final castedD = nullableD is double; } + +class _A {} + +class _B extends _A {} + +class _C extends _A {} + +void noLint() { + final _A a = _B(); + if (a is! _C) return; +} From df1f4bb4eb5d48a8b2d88d3df3ba475314e63b55 Mon Sep 17 00:00:00 2001 From: Andrii Date: Thu, 14 Mar 2024 11:52:44 +0200 Subject: [PATCH 2/3] - Fixed formatting --- lib/src/utils/typecast_utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/utils/typecast_utils.dart b/lib/src/utils/typecast_utils.dart index f9c4d137..5c566df7 100644 --- a/lib/src/utils/typecast_utils.dart +++ b/lib/src/utils/typecast_utils.dart @@ -77,7 +77,7 @@ class TypeCast { if (!objectTypeCast.areGenericsWithSameTypeArgs) { return false; } - + return !isReversed; } From e5ec878935cba2cdaec61af413e64653551dc230 Mon Sep 17 00:00:00 2001 From: Andrii Date: Thu, 14 Mar 2024 15:03:31 +0200 Subject: [PATCH 3/3] - Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9c8b8b8..0295bf8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `avoid_debug_print` rule - Fixed an issue with no_magic_number lint +- Fixed unexpected avoid_unnecessary_type_assertions ## 0.1.4