This rule enforces consistent naming conventions for enum entries in Kotlin, aligning with established community guidelines. Adhering to a standard naming style, such as UPPER_SNAKE_CASE or UpperCamelCase, significantly improves code readability and maintainability. Inconsistent naming can lead to confusion, making it harder for developers to quickly understand the purpose and intent of enum members. Violations occur when enum entries do not follow either of these recommended patterns.
How to remediate
To fix this issue, ensure all enum entries follow either UPPER_SNAKE_CASE (all uppercase letters with words separated by underscores, for example, MY_ENUM_ENTRY) or UpperCamelCase (also known as PascalCase, where each word starts with an uppercase letter and no underscores, for example, MyEnumEntry). Choose one style and apply it consistently across your enum definitions for clarity and uniformity.
tests:
filename: NonCompliantCode.kt
code: |-
enum class Foo {
foo,
bAr,
Foo_Bar,
}
annotation_count: 3