Check naming convention of enums

Currently, there are several rules ensuring adherence to a naming convention. E.g., for classes, abstract classes, methods, members, constants and so forth. However, there is no rule which checks whether an enum complies to any naming convention. The is rule S00101, but it does only check classes. There is a issue from 2014 in the bugtracker (, but no description is available and the Google Groups thread I wasn’t able to find.
So I’d like to suggest to either create a specific rule for enums or to adapt the S00101 to also handle enums. If you’d be willing to accept a pull request even without an RSPEC number, please let me know

Wow, I never noticed that SQ doesn’t cover enum constants; good catch!

As I was curious about the page linked in the issue, I went ahead and looked it up on (and added it to SONARJAVA-689 for posterity). Here it is: Codepro AnalytiX: Enumerated Type Naming Convention. Note that the page itself does not define a naming convention, but only a rule that can be used to enforce one.

Hey SonarSourcers, could you perhaps give the rationale why SONARJAVA-689 was closed as “Won’t fix” in 2015? Maybe your opinion has changed in the meantime :slight_smile:.

Best regards,

Re-reading this now, I realize that I (and probably others) misread the original request - this is about the name of the enum type, e.g. “Color” in public enum Color { RED, GREEN, BLUE; }, not being checked at all. For example, public enum my_enum {...} would be accepted, but public class my_class {...} would be rejected.

Given that I have never seen a Java project where naming conventions for enums and regular classes are different, I would vote to extend the implementation of S101 (“Class names should comply with a naming convention”) to also cover enums. However, interfaces already have their own rule (S114). Then again, there do not seem to be rules for records (Java 14) or annotation types.

If S101 is not changed, one should at least add a note to the S101 description for Java that it does not cover enum type names.

Note: the names of enum constants, e.g. “GREEN” in public enum Color { RED, GREEN, BLUE; }, are checked by S100 (“Constant names should comply with a naming convention”).

1 Like