* [PATCH 0/2] clang-format: format short enums and macro definitions correctly
@ 2025-02-10 8:20 Michael Riesch
2025-02-10 8:21 ` [PATCH 1/2] clang-format: do not allow short enums on a single line Michael Riesch
2025-02-10 8:21 ` [PATCH 2/2] clang-format: align consecutive macros Michael Riesch
0 siblings, 2 replies; 5+ messages in thread
From: Michael Riesch @ 2025-02-10 8:20 UTC (permalink / raw)
To: Miguel Ojeda, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Justin Stitt
Cc: linux-kernel, llvm, Michael Riesch
Habidere,
These patches set two previously unset clang-format options to
(hopefully) sane values.
Looking forward to your comments!
Best regards,
Michael
Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
---
Michael Riesch (2):
clang-format: do not allow short enums on a single line
clang-format: align consecutive macros
.clang-format | 2 ++
1 file changed, 2 insertions(+)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250210-clang-format-fixes-914ded0e682d
Best regards,
--
Michael Riesch <michael.riesch@wolfvision.net>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] clang-format: do not allow short enums on a single line
2025-02-10 8:20 [PATCH 0/2] clang-format: format short enums and macro definitions correctly Michael Riesch
@ 2025-02-10 8:21 ` Michael Riesch
2025-02-11 18:13 ` Nathan Chancellor
2025-02-10 8:21 ` [PATCH 2/2] clang-format: align consecutive macros Michael Riesch
1 sibling, 1 reply; 5+ messages in thread
From: Michael Riesch @ 2025-02-10 8:21 UTC (permalink / raw)
To: Miguel Ojeda, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Justin Stitt
Cc: linux-kernel, llvm, Michael Riesch
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] clang-format: align consecutive macros
2025-02-10 8:20 [PATCH 0/2] clang-format: format short enums and macro definitions correctly Michael Riesch
2025-02-10 8:21 ` [PATCH 1/2] clang-format: do not allow short enums on a single line Michael Riesch
@ 2025-02-10 8:21 ` Michael Riesch
2025-02-11 18:14 ` Nathan Chancellor
1 sibling, 1 reply; 5+ messages in thread
From: Michael Riesch @ 2025-02-10 8:21 UTC (permalink / raw)
To: Miguel Ojeda, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Justin Stitt
Cc: linux-kernel, llvm, Michael Riesch
clang-format 9 introduced the option "AlignConsecutiveMacros".
Set it to "AcrossEmptyLinesAndComments" in order to avoid macro
definitions of the form:
#define MAGIC_REGISTER_1 0x42
#define MAGIC_REGISTER_BIT_FLIP BIT(2)
/* important comment */
#define MAGIC_REGISTER_BIT_ENABLE BIT(12)
#define MAGIC_REGISTER_2 0x43
With the option set to "AcrossEmptyLinesAndComments", they will
be converted to
#define MAGIC_REGISTER_1 0x42
#define MAGIC_REGISTER_BIT_FLIP BIT(2)
/* important comment */
#define MAGIC_REGISTER_BIT_ENABLE BIT(12)
#define MAGIC_REGISTER_2 0x43
which seems to be the convention in the kernel code base.
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 8040b516185b..30d09cb88170 100644
--- a/.clang-format
+++ b/.clang-format
@@ -13,6 +13,7 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
+AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] clang-format: do not allow short enums on a single line
2025-02-10 8:21 ` [PATCH 1/2] clang-format: do not allow short enums on a single line Michael Riesch
@ 2025-02-11 18:13 ` Nathan Chancellor
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2025-02-11 18:13 UTC (permalink / raw)
To: Michael Riesch
Cc: Miguel Ojeda, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-kernel, llvm
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] clang-format: align consecutive macros
2025-02-10 8:21 ` [PATCH 2/2] clang-format: align consecutive macros Michael Riesch
@ 2025-02-11 18:14 ` Nathan Chancellor
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2025-02-11 18:14 UTC (permalink / raw)
To: Michael Riesch
Cc: Miguel Ojeda, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-kernel, llvm
On Mon, Feb 10, 2025 at 09:21:01AM +0100, Michael Riesch wrote:
> clang-format 9 introduced the option "AlignConsecutiveMacros".
> Set it to "AcrossEmptyLinesAndComments" in order to avoid macro
> definitions of the form:
>
> #define MAGIC_REGISTER_1 0x42
> #define MAGIC_REGISTER_BIT_FLIP BIT(2)
> /* important comment */
> #define MAGIC_REGISTER_BIT_ENABLE BIT(12)
>
> #define MAGIC_REGISTER_2 0x43
>
> With the option set to "AcrossEmptyLinesAndComments", they will
> be converted to
>
> #define MAGIC_REGISTER_1 0x42
> #define MAGIC_REGISTER_BIT_FLIP BIT(2)
> /* important comment */
> #define MAGIC_REGISTER_BIT_ENABLE BIT(12)
>
> #define MAGIC_REGISTER_2 0x43
>
> which seems to be the convention in the kernel code base.
>
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
I could see this being controversial in some cases but let's see what
happens.
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> .clang-format | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/.clang-format b/.clang-format
> index 8040b516185b..30d09cb88170 100644
> --- a/.clang-format
> +++ b/.clang-format
> @@ -13,6 +13,7 @@ AccessModifierOffset: -4
> AlignAfterOpenBracket: Align
> AlignConsecutiveAssignments: false
> AlignConsecutiveDeclarations: false
> +AlignConsecutiveMacros: AcrossEmptyLinesAndComments
> AlignEscapedNewlines: Left
> AlignOperands: true
> AlignTrailingComments: false
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-11 18:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 8:20 [PATCH 0/2] clang-format: format short enums and macro definitions correctly Michael Riesch
2025-02-10 8:21 ` [PATCH 1/2] clang-format: do not allow short enums on a single line Michael Riesch
2025-02-11 18:13 ` Nathan Chancellor
2025-02-10 8:21 ` [PATCH 2/2] clang-format: align consecutive macros Michael Riesch
2025-02-11 18:14 ` Nathan Chancellor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox