avoid_double_and_int_checks
避免检查 double 和 int。
详情
#避免检查类型是否为 double 或 int。
当编译为 JS 时,整数值会表示为浮点数。这在使用 is 或 is! 检查类型为 int 或 double 时可能导致一些意外行为。
不推荐
dart
f(num x) {
if (x is double) {
...
} else if (x is int) {
...
}
}推荐
dart
f(dynamic x) {
if (x is num) {
...
} else {
...
}
}启用
#要启用 avoid_double_and_int_checks 规则,请在您的 analysis_options.yaml 文件中,将 avoid_double_and_int_checks 添加到 linter > rules 下
analysis_options.yaml
yaml
linter:
rules:
- avoid_double_and_int_checks如果您使用 YAML map 语法配置 linter 规则,请在 linter > rules 下添加 avoid_double_and_int_checks: true
analysis_options.yaml
yaml
linter:
rules:
avoid_double_and_int_checks: true