avoid_null_checks_in_equality_operators
Don't check for null
in custom ==
operators.
This rule has been removed as of the latest Dart releases.
Details
#DON'T check for null
in custom ==
operators.
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;
@override
operator ==(Object? other) =>
other != null && other is Person && name == other.name;
}
GOOD:
dart
class Person {
final String? name;
@override
operator ==(Object? other) => other is Person && name == other.name;
}
This rule has been removed.
Usage
#To enable the avoid_null_checks_in_equality_operators
rule,
add avoid_null_checks_in_equality_operators
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- avoid_null_checks_in_equality_operators
除非另有说明,文档之所提及适用于 Dart 3.5.3 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。