From 7aea615d1048ff6908dd9addf4183e475f42bb5d Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 14 Dec 2022 09:43:30 -0800 Subject: [PATCH] Fix examples in avoid_null_checks_in_equality_operators --- .../avoid_null_checks_in_equality_operators.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/rules/avoid_null_checks_in_equality_operators.dart b/lib/src/rules/avoid_null_checks_in_equality_operators.dart index 8facf47e8..fc04ab6fe 100644 --- a/lib/src/rules/avoid_null_checks_in_equality_operators.dart +++ b/lib/src/rules/avoid_null_checks_in_equality_operators.dart @@ -17,16 +17,17 @@ const _desc = r"Don't check for null in custom == operators."; const _details = r''' **DON'T** check for null in custom == operators. -As null is a special type, no class can be equivalent to it. Thus, it is -redundant to check whether the other instance is null. +As null is a special value, no instance of any class (other than `Null`) can be +equivalent to it. Thus, it is redundant to check whether the other instance is +null. **BAD:** ```dart class Person { - final String name; + final String? name; @override - operator ==(other) => + operator ==(Object? other) => other != null && other is Person && name == other.name; } ``` @@ -34,10 +35,10 @@ class Person { **GOOD:** ```dart class Person { - final String name; + final String? name; @override - operator ==(other) => other is Person && name == other.name; + operator ==(Object? other) => other is Person && name == other.name; } ```