[clang-tidy] Add a new check in cppcoreguidelines for checking enum values' names
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
ISO C++ Core Guidelines section [Enum.5](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#enum5-dont-use-all_caps-for-enumerators) states that ALL_CAPS should be avoided for enum names. The reason for this mentioned there is to avoid clashes with macros.
Example given there:
```c++
// webcolors.h (third party header)
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
// productinfo.h
// The following define product subtypes based on color
enum class Product_info { RED, PURPLE, BLUE }; // syntax error
```
Check can be something like - iterate through each possible enum value, check if it matches the regex `[A-Z0-9_]` and if it does, flag it.
Possible fix suggestion:
```c++
enum class Product_info { Red, Purple, Blue };
```
Contributor guide
Research direction
Start in clang-tidy's cppcoreguidelines checks and compare how existing checks are implemented and tested. Define the naming pattern precisely from the issue's Enum.5 example, then add coverage for uppercase and suggested mixed-case enumerators; done means the new check reliably reports the former without flagging the latter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100