avoid_inconsistent_digit_separators
This rule flags a numeric literal whose _ separators split it into irregularly sized groups.
Why use this rule
Section titled “Why use this rule”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-3const bytes = 1000_000; // leading group longer than the restconst mask = 0xFF_FFF_FFF; // hex grouped by threesconst population = 1_000_000;const bytes = 1_000_000;const mask = 0xFFFF_FFFF;
const small = 12_345_678; // a short leading group is correctEnabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: avoid_inconsistent_digit_separators: enabled: trueOptions
Section titled “Options”many_lints: rules: avoid_inconsistent_digit_separators: group_size: 3 hex_group_size: 4rules: 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.
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: avoid_inconsistent_digit_separators: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”double_literal_format— Write double literals with exactly one leading zero and no redundant trailing zeros.format_comment— Write comments as capitalised, terminated sentences.always_pass_global_key— Don’t create a GlobalKey inside build.always_remove_listener— Ensure every addListener() has a matching removeListener() in dispose().