Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/src/rules/avoid_null_checks_in_equality_operators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ 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;
}
```

**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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best practice is for the parameter to be Object because a null can't be passed in. (I haven't checked to see whether we have another warning for that.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I know. But the lint won't fire under that practice.

}
```

Expand Down