[clang-tools-extra] [clang-tidy] Add new check readability-trailing-comma (PR #173669)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 26 08:40:43 PST 2025
================
@@ -0,0 +1,83 @@
+.. title:: clang-tidy - readability-trailing-comma
+
+readability-trailing-comma
+==========================
+
+Checks for presence or absence of trailing commas in enum definitions and
+initializer lists.
+
+The check can either append trailing commas where they are missing or remove
+them where they are present, based on the configured policy.
+
+Trailing commas offer several benefits:
+
+- Adding or removing elements may only changes a single line, making diffs
+ smaller and easier to read.
+- Formatters may change code to a more desired style.
+- Code generators avoid for need special handling of the last element.
+
+.. code-block:: c++
+
+ // Without trailing commas - adding "Yellow" requires modifying the "Blue" line
+ enum Color {
+ Red,
+ Green,
+ Blue
+ };
+
+ // With trailing commas - adding "Yellow" is a clean, single-line change
+ enum Color {
+ Red,
+ Green,
+ Blue,
+ };
+
+
+Limitations
+-----------
+
+The check currently don't analyze code inside macros.
----------------
localspook wrote:
```suggestion
The check currently doesn't analyze code inside macros.
```
https://github.com/llvm/llvm-project/pull/173669
More information about the cfe-commits
mailing list