use_is_even_rather_than_modulo
Prefer intValue.isOdd/isEven instead of checking the result of % 2.
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;
Enable
#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
If you're instead using the YAML map syntax to configure linter rules, add use_is_even_rather_than_modulo: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
use_is_even_rather_than_modulo: true
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-03-07. View source or report an issue.