rspec/rules/S3973/rule.adoc
Fred Tingaud bffcad6e53
Modify rule S3973: LaYC Indenting if (#1947)
Co-authored-by: vilchik.elena <elena.vilchik@sonarsource.com>
2023-06-05 08:31:02 +00:00

38 lines
890 B
Plaintext

== Why is this an issue?
include::description.adoc[]
[source,java]
----
if (condition) // Noncompliant
doTheThing();
doTheOtherThing(); // Was the intent to call this function unconditionally?
----
It becomes even more confusing and bug-prone if lines get commented out.
[source,java]
----
if (condition) // Noncompliant
// doTheThing();
doTheOtherThing(); // Was the intent to call this function conditionally?
----
Indentation alone or together with curly braces makes the intent clear.
[source,java]
----
if (condition)
doTheThing();
doTheOtherThing(); // Clear intent to call this function unconditionally
// or
if (condition) {
doTheThing();
}
doTheOtherThing(); // Clear intent to call this function unconditionally
----
This rule raises an issue if the line controlled by a conditional has the same indentation as the conditional and is not enclosed in curly braces.