From 36896a27b1247e53d7293eff0422089786365d2b Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Mon, 1 Jun 2026 10:09:43 +0100 Subject: [PATCH] docs: specifically mention that braces in if blocks do not need to be symmetric The claude bot keeps getting this wrong again and again: Claude: nit: systemd coding style requires braces on both branches of an if/else when one branch uses them. Here the if branch is a single statement without braces but the else branch uses braces Specifically mention this is not the case in the coding style doc to hopefully make it stop hallucinating this rule --- docs/CODING_STYLE.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index d6580bbbec..51551962f5 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -94,6 +94,28 @@ SPDX-License-Identifier: LGPL-2.1-or-later } ``` +- Braces in `if` blocks are not required to be symmetric. Write this: + + ```c + if (foobar) + waldo(); + else { + foo(); + bar(); + } + ``` + + instead of this: + + ```c + if (foobar) { + waldo(); + } else { + foo(); + bar(); + } + ``` + - Do not write `foo ()`, write `foo()`. - `else` blocks should generally start on the same line as the closing `}`: