2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2020-06-30 12:48:39 +02:00
|
|
|
include::description.adoc[]
|
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
[source,java]
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
|
|
|
if (condition) // Noncompliant
|
|
|
|
doTheThing();
|
2023-06-05 10:31:02 +02:00
|
|
|
doTheOtherThing(); // Was the intent to call this function unconditionally?
|
|
|
|
----
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
It becomes even more confusing and bug-prone if lines get commented out.
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
[source,java]
|
|
|
|
----
|
|
|
|
if (condition) // Noncompliant
|
|
|
|
// doTheThing();
|
|
|
|
doTheOtherThing(); // Was the intent to call this function conditionally?
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
Indentation alone or together with curly braces makes the intent clear.
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
[source,java]
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
|
|
|
if (condition)
|
|
|
|
doTheThing();
|
2023-06-05 10:31:02 +02:00
|
|
|
doTheOtherThing(); // Clear intent to call this function unconditionally
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
// or
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
if (condition) {
|
|
|
|
doTheThing();
|
|
|
|
}
|
|
|
|
doTheOtherThing(); // Clear intent to call this function unconditionally
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
2020-06-30 12:48:39 +02:00
|
|
|
|
2023-06-05 10:31:02 +02:00
|
|
|
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.
|