java:S115 (Naming convention for constant names) applies to enum constant names too

Hello,

Per java:S115:

public enum MyEnum {
  OptionOne, 
  OptionTwo; 
}

is non-compliant and should be written as

public enum MyEnum {
  OPTION_ONE,
  OPTION_TWO;
}

While we understand that enforcing UPPER_SNAKE_CASE follows java conventions, we sometimes find it too restrictive and would actually prefer the PascalCase instead for enum constants.

Would it be possible to introduce a separate Sonar rule for enum-constant names? It would default to the same (customizable) pattern as java:s115 (so there’d be no change for most users), but could be overridden if needed.

Many thanks

1 Like

Hi FD,

Thank you for the suggestion! I think we can just change S115 a bit without introducing a new rule. I created a ticket, SONARJAVA-5676, to track this.

Even better! Many thanks