]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
docs: specifically mention that braces in if blocks do not need to be symmetric
authorLuca Boccassi <luca.boccassi@gmail.com>
Mon, 1 Jun 2026 09:09:43 +0000 (10:09 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 1 Jun 2026 09:55:40 +0000 (10:55 +0100)
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

index d6580bbbecd426799e3a896db69a35b1862d6f4a..51551962f5e06e5e51ff78737b5997f70448153c 100644 (file)
@@ -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 `}`: