Skip to main content

avoid_js_rounded_ints

Learn about the avoid_js_rounded_ints linter rule.

Stable

Avoid JavaScript rounded ints.

Details

#

AVOID integer literals that cannot be represented exactly when compiled to JavaScript.

When a program is compiled to JavaScript int and double become JavaScript Numbers. Too large integers (value < Number.MIN_SAFE_INTEGER or value > Number.MAX_SAFE_INTEGER) may be rounded to the closest Number value.

For instance 1000000000000000001 cannot be represented exactly as a JavaScript Number, so 1000000000000000000 will be used instead.

BAD:

dart
int value = 9007199254740995; 

GOOD:

dart
BigInt value = BigInt.parse('9007199254740995'); 

Enable

#

To enable the avoid_js_rounded_ints rule, add avoid_js_rounded_ints under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:  rules:  - avoid_js_rounded_ints 

If you're instead using the YAML map syntax to configure linter rules, add avoid_js_rounded_ints: true under linter > rules:

analysis_options.yaml
yaml
linter:  rules:  avoid_js_rounded_ints: true