avoid_double_and_int_checks
Avoid double
and int
checks.
This rule is available as of Dart 2.0.
Details
#AVOID to check if type is double
or int
.
When compiled to JS, integer values are represented as floats. That can lead to
some unexpected behavior when using either is
or is!
where the type is
either int
or double
.
BAD:
dart
f(num x) {
if (x is double) {
...
} else if (x is int) {
...
}
}
GOOD:
dart
f(dynamic x) {
if (x is num) {
...
} else {
...
}
}
Usage
#To enable the avoid_double_and_int_checks
rule,
add avoid_double_and_int_checks
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- avoid_double_and_int_checks
除非另有说明,文档之所提及适用于 Dart 3.5.3 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。