diff mbox series

[v2,1/5] clang-format: fix indentation width for preprocessor directives

Message ID c33ad700d68b5d8b5940dd803d116ec19bb75c7e.1722323818.git.ps@pks.im (mailing list archive)
State Accepted
Commit 395726717bcc4073d2adba4ee5016a350dfa8d3a
Headers show
Series Documentation: some coding guideline updates | expand

Commit Message

Patrick Steinhardt July 30, 2024, 7:24 a.m. UTC
In [1], we have improved our clang-format configuration to also specify
the style for how to indent preprocessor directives. But while we have
settled the question of where to put the indentation, either before or
after the hash sign, we didn't specify exactly how to indent.

With the current configuration, clang-format uses tabs to indent each
level of nested preprocessor directives, which is in fact unintentional
and never done in our codebase. Instead, we use a mixture of indenting
by either one or two spaces, where using a single space is somewhat more
common.

Adapt our clang-format configuration accordingly by specifying an
indentation width of one space.

[1]: <20240708092317.267915-1-karthik.188@gmail.com>

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 .clang-format | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Karthik Nayak July 30, 2024, 2:19 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> In [1], we have improved our clang-format configuration to also specify
> the style for how to indent preprocessor directives. But while we have
> settled the question of where to put the indentation, either before or
> after the hash sign, we didn't specify exactly how to indent.
>
> With the current configuration, clang-format uses tabs to indent each
> level of nested preprocessor directives, which is in fact unintentional
> and never done in our codebase. Instead, we use a mixture of indenting
> by either one or two spaces, where using a single space is somewhat more
> common.
>
> Adapt our clang-format configuration accordingly by specifying an
> indentation width of one space.
>
> [1]: <20240708092317.267915-1-karthik.188@gmail.com>
>

I totally missed this, thanks for fixing it up. The patch looks good.
diff mbox series

Patch

diff --git a/.clang-format b/.clang-format
index 16fd12253e..0b82f3c776 100644
--- a/.clang-format
+++ b/.clang-format
@@ -100,11 +100,13 @@  BreakStringLiterals: false
 # Switch statement body is always indented one level more than case labels.
 IndentCaseLabels: false
 
-# Indents directives before the hash.
+# Indents directives before the hash. Each level uses a single space for
+# indentation.
 # #if FOO
-# #  include <foo>
+# # include <foo>
 # #endif
 IndentPPDirectives: AfterHash
+PPIndentWidth: 1
 
 # Don't indent a function definition or declaration if it is wrapped after the
 # type