KT.IMPLICIT_DEFAULT_LOCALE

Implicit default locale

Prefer passing [java.util.Locale] explicitly than using implicit default value when formatting strings or performing a case conversion. The default locale is almost always inappropriate for machine-readable text like HTTP headers. For example, if locale with tag ar-SA-u-nu-arab is a current default then %d placeholders will be evaluated to a number consisting of Eastern-Arabic (non-ASCII) digits. [java.util.Locale.US] is recommended for machine-readable output.

Noncompliant Code

Copy
String.format("Timestamp: %d", System.currentTimeMillis())

val str: String = getString()
str.toUpperCase()
str.toLowerCase()

Compliant Code

Copy
String.format(Locale.US, "Timestamp: %d", System.currentTimeMillis())

val str: String = getString()
str.toUpperCase(Locale.US)
str.toLowerCase(Locale.US)

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html