proposal: equality_operator_override_with_nullable_parameter
#58965
Labels
devexp-linter
Issues with the analyzer's support for the linter package
legacy-area-analyzer
Use area-devexp instead.
linter-lint-proposal
linter-set-recommended
linter-status-pending
equality_operator_override_with_nullable_parameter
Description
Do not override the equality operator to have a nullable parameter.
Details
No Dart implementation will ever pass
null
to an equality operator, so no equality operator should accept a nullable parameter. Object.== accepts anObject
.Kind
Improves readability, guards against misunderstanding...
Bad Examples
Good Examples
Discussion
I have found a number of cases of classes which override to accept a
dynamic
parameter, while switching mockito-dependant tests to use code-generated mockito. Code-generated mockito includes an override for==
, which stumbles, trying to re-narrow the parameter type toObject
.This rule would more-or-less replace https://dart-lang.github.io/linter/lints/avoid_null_checks_in_equality_operators.html.
Discussion checklist
The text was updated successfully, but these errors were encountered: