use_is_even_rather_than_modulo
Prefer intValue.isOdd/isEven instead of checking the result of % 2.
This rule is available as of Dart 2.9.0.
Details
#PREFER the use of intValue.isOdd/isEven to check for evenness.
BAD:
dart
bool isEven = 1 % 2 == 0;
bool isOdd = 13 % 2 == 1;
GOOD:
dart
bool isEven = 1.isEven;
bool isOdd = 13.isOdd;
Usage
#To enable the use_is_even_rather_than_modulo
rule,
add use_is_even_rather_than_modulo
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- use_is_even_rather_than_modulo
除非另有说明,文档之所提及适用于 Dart 3.5.0 版本,本页面最后更新时间: 2024-09-22。 查看文档源码 或者 报告页面问题。