Name warning for constant property

AndroidStudio gives me the following warning…

Private property name DEFAULT_CIPHER_TRANSFORMATION should not contain underscores in the middle or the end

…for the following code:

class Secretify {

private val DEFAULT_CIPHER_TRANSFORMATION = “RSA/ECB/PKCS1Padding”

But according to the Kotlin naming conventions it should be correct:

Property names
Names of constants (properties marked with const, or top-level or object val properties with no custom get function that hold deeply immutable data) should use uppercase underscore-separated names:

const val MAX_COUNT = 8
val USER_NAME_FIELD = “UserName”

https://kotlinlang.org/docs/reference/coding-conventions.html#naming-rules

Do I understand the naming conventions wrong?

1 Like

Might it be the missing const modifier?

const is also not used in the example from the coding conventions.

After all, you are actually defining a strong that is stored in every new instance of the class.
Have you tried using object companion object or the global scope?

Both works without warning and I will use a companion object.
After reading the coding conventions again I found my problem. I misinterpreted the term “top-level”.

You have not misinterpreted anything. Coding conventions state " Names of constants (properties marked with const , or top-level or object val properties with no custom get function that hold deeply immutable data) should use uppercase underscore-separated names"

So there is a bug in Intellij regarding checking of style.

But the original post has

class Secretify {

private val DEFAULT_CIPHER_TRANSFORMATION = “RSA/ECB/PKCS1Padding”

Which means the variable is:

  • not marked with const
  • not top-level (it’s inside a class declaration)
  • not an object property (it’s in a class, NOT object declaration)

So I think the warning is correct according to the conventions.

2 Likes

You are right, thank you