[PATCH 1/2] clang-format: do not allow short enums on a single line

Michael Riesch posted 2 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH 1/2] clang-format: do not allow short enums on a single line
Posted by Michael Riesch 10 months, 1 week ago
clang-format 11 introduced the option "AllowShortEnumsOnASingleLine".
Set it to "false" in order to avoid short enums of the form:

    enum my_short_num { green, red };

With the option set to "false", they will be converted to

    enum my_short_num {
            green,
            red
    };

which is consistent with the definition of enums with more items.

Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
---
 .clang-format | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.clang-format b/.clang-format
index fe1aa1a30d40..8040b516185b 100644
--- a/.clang-format
+++ b/.clang-format
@@ -19,6 +19,7 @@ AlignTrailingComments: false
 AllowAllParametersOfDeclarationOnNextLine: false
 AllowShortBlocksOnASingleLine: false
 AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: false
 AllowShortFunctionsOnASingleLine: None
 AllowShortIfStatementsOnASingleLine: false
 AllowShortLoopsOnASingleLine: false

-- 
2.34.1
Re: [PATCH 1/2] clang-format: do not allow short enums on a single line
Posted by Nathan Chancellor 10 months, 1 week ago
On Mon, Feb 10, 2025 at 09:21:00AM +0100, Michael Riesch wrote:
> clang-format 11 introduced the option "AllowShortEnumsOnASingleLine".
> Set it to "false" in order to avoid short enums of the form:
> 
>     enum my_short_num { green, red };
> 
> With the option set to "false", they will be converted to
> 
>     enum my_short_num {
>             green,
>             red
>     };
> 
> which is consistent with the definition of enums with more items.
> 
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>

Seems reasonable to me.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  .clang-format | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.clang-format b/.clang-format
> index fe1aa1a30d40..8040b516185b 100644
> --- a/.clang-format
> +++ b/.clang-format
> @@ -19,6 +19,7 @@ AlignTrailingComments: false
>  AllowAllParametersOfDeclarationOnNextLine: false
>  AllowShortBlocksOnASingleLine: false
>  AllowShortCaseLabelsOnASingleLine: false
> +AllowShortEnumsOnASingleLine: false
>  AllowShortFunctionsOnASingleLine: None
>  AllowShortIfStatementsOnASingleLine: false
>  AllowShortLoopsOnASingleLine: false
> 
> -- 
> 2.34.1
>