Putting multiple statements on a single line lowers the code readability and makes debugging the code more complex.
foo(); bar(); // Noncompliant
Write one statement per line to improve readability.
foo();
bar();
Exceptions
The rule ignores:
- control flow statements with a single nested statement
if (condition) doSomething(); // Compliant by exception
while (condition) doSomething(); // Compliant by exception
-
case
or default
statements containing a single statement followed by break
switch (foo) {
case 0: doSomething(); break; // Compliant by exception
default: doSomething(); break; // Compliant by exception
}
- statements enclosed in curly braces on the same line
auto lambda = [](int x) { doSomething(x); return x; }; // Compliant by exception