prefer_ int_ literals
Prefer int literals over double literals.
Details
#DO use int literals rather than the corresponding double literal.
BAD:
const double myDouble = 8.0;
final anotherDouble = myDouble + 7.0e2;
main() {
someMethod(6.0);
}
GOOD:
const double myDouble = 8;
final anotherDouble = myDouble + 700;
main() {
someMethod(6);
}
Enable
#
To enable the
prefer_int_literals
rule, add
prefer_int_literals
under
linter > rules
in your
analysis_options.yaml
file:
linter:
rules:
- prefer_int_literals
If you're instead using the YAML map syntax to configure linter rules,
add
prefer_int_literals: true
under
linter > rules:
linter:
rules:
prefer_int_literals: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.