Skip to content

avoid_inconsistent_digit_separators

v1.0.0WarningFixConfigurableFormatting

This rule flags a numeric literal whose _ separators split it into irregularly sized groups.

1_000_000 is readable because every group is the same size, which is the entire point of the separator: the eye counts groups instead of digits.

10_00_000 defeats that. It looks like a number written in a different convention, and it is exactly how a literal with a wrong digit count survives review — the separator that was supposed to make the magnitude obvious is what hides it.

A literal with no separators at all is never reported. Whether to use them in the first place is a different question, and this rule does not answer it.

The leading group may be shorter than the rest, since that is what is left over: 12_345_678 is correct, 1000_000 is not.

Hexadecimal literals are grouped by hex_group_size (default 4) rather than by thousands, because hex groups by byte or half-word.

This rule is in the pedantic preset: separator style is a house style.

See also: Dart 3.6 digit separators

const population = 10_00_000; // groups of 2-2-3
const bytes = 1000_000; // leading group longer than the rest
const mask = 0xFF_FFF_FFF; // hex grouped by threes
const population = 1_000_000;
const bytes = 1_000_000;
const mask = 0xFFFF_FFFF;
const small = 12_345_678; // a short leading group is correct

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
avoid_inconsistent_digit_separators:
enabled: true
analysis_options.yaml
many_lints:
rules:
avoid_inconsistent_digit_separators:
group_size: 3
hex_group_size: 4
Option Type Default Description
group_size int 3 Digits per group in a decimal or binary literal
hex_group_size int 4 Digits per group in a hexadecimal literal

Set either option to 0 to accept any group size, as long as it is used consistently within the literal.

To disable this rule:

many_lints.yaml
rules:
avoid_inconsistent_digit_separators: false

To keep the rule on but skip certain paths, use per-rule exclude.