org.sonar.l10n.delphi.rules.community-delphi.DigitGrouping.html Maven / Gradle / Ivy
The newest version!
Why is this an issue?
From Delphi 11 onwards, digit separators _
can be used to split numeric literals
into groups.
To improve readability, this rule verifies that numeric literals using separators have groups of a
standard, homogeneous size.
- Decimal literals: groups of 3 digits
- Hexadecimal literals: groups of 2 or 4 digits
- Binary literals: groups of 2, 3, or 4 digits
Noncompliant code example
const
WrongGroupSize = 1_0000; // Noncompliant; using groups of 4 instead of 3
MixedGroupSize = $F_7F_FFFF; // Noncompliant; using mixed group sizes
Compliant code example
const
DecimalInt = 10_000;
HexadecimalInt2 = $7_FF_FF;
HexadecimalInt4 = $7_FFFF;
BinaryInt2 = %0_10_10;
BinaryInt3 = %01_010;
BinaryInt4 = %0_1010;
LongDecimalFloat = 10_000.0;
FloatWithAnySeps = 10.0_0_00_1;
Exceptions
Only the integer component of floating point numbers is checked for compliance; the fractional and
exponent parts are ignored.
How to fix it
- Pick an appropriate, standard digit group size from the above list.
- Starting from the right, group the digits in the integer using
_
between groups.
Resources
© 2015 - 2024 Weber Informatics LLC | Privacy Policy