S122 — Statements should be on separate lines

Language
C#
Type
Code smell
Severity
Major
Tags
convention

Why is this an issue?

Putting multiple statements on a single line lowers the code readability and makes debugging the code more complex.


if (someCondition) { DoSomething(); } // Noncompliant

DoSomething(); DoSomethingElse(); // Noncompliant

Write one statement per line to improve readability.


if (someCondition)
{
  DoSomething();
}

DoSomething();
DoSomethingElse();

Exceptions

The rule ignores:


Func<object, bool> item1 = o => { return true; }; // Compliant by exception
Func<object, bool> item1 = o => { var r = false; return r; }; // Noncompliant

Resources

Documentation

↑ Back to top