Kotlin enum entries must follow naming conventions

This product is not supported for your selected Datadog site. ().
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください

Metadata

ID: kotlin-code-style/enum-entry-naming

Language: Kotlin

Severity: Notice

Category: Code Style

Description

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
  • filename: CompliantCode.kt code: |- enum class Foo { FOO, Foo, FOO_BAR, FooBar, } annotation_count: 0

Non-Compliant Code Examples

enum class Foo {
    foo,
    bAr,
    Foo_Bar,
}

Compliant Code Examples

enum class Foo {
    FOO,
    Foo,
    FOO_BAR,
    FooBar,
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security