[PATCH v3 1/8] clang-format: indent preprocessor directives after hash
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jul 13, 2024, 13:45 UTC
- Message-ID
- <20240713134518.773053-2-karthik.188@gmail.com>
- In-Reply-To
- <20240713134518.773053-1-karthik.188@gmail.com>
We do not have a rule around the indentation of preprocessor directives. This was also discussed on the list [1], noting how there is often inconsistency in the styling. While there was discussion, there was no conclusion around what is the preferred style here. One style being indenting after the hash:
#if FOO
# if BAR
# include <foo>
# endif
#endifThe other being before the hash:
#if FOO
#if BAR
#include <foo>
#endif
#endifLet's pick the former and add 'IndentPPDirectives: AfterHash' value to our '.clang-format'. There is no clear reason to pick one over the other, but it would definitely be nicer to be consistent.
[1]: https://lore.kernel.org/r/xmqqwmmm1bw6.fsf@gitster.g
Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- .clang-format | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/.clang-format b/.clang-format index 3ed4fac753..5e128519bf 100644 --- a/.clang-format +++ b/.clang-format @@ -96,6 +96,12 @@ BreakStringLiterals: false # Switch statement body is always indented one level more than case labels. IndentCaseLabels: false +# Indents directives before the hash. +# #if FOO +# # include <foo> +# #endif +IndentPPDirectives: AfterHash + # Don't indent a function definition or declaration if it is wrapped after the # type IndentWrappedFunctionNames: false
-- 2.45.2