Numbers are formatted with String.format or format without a locale, so the output changes with the device
What it finds
"%.2f".format(price) writes 3,50 on a German device and 3.50 on an English one. Text meant for machines, files or protocols gets a fixed locale, such as Locale.ROOT.
From the rule's source, format_without_locale.rs.
fun show(price: Double, name: String) { val a = "%.2f".format(price)tx0 reports: numbers are formatted in the default locale of the device val b = String.format("%d items", 3)tx0 reports: numbers are formatted in the default locale val c = String.format(Locale.ROOT, "%d items", 3) val d = "%s".format(name)} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:number-format-without-locale" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:number-format-without-locale] reason="..."tx0 explain tx0/kotlin:number-format-without-locale shows the same in the terminal. Found a false positive? Report it.