rspec/rules/S1119/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

38 lines
887 B
Plaintext

== Why is this an issue?
Labels are not commonly used in Java, and many developers do not understand how they work. Moreover, their usage makes the control flow harder to follow, which reduces the code's readability.
=== Noncompliant code example
[source,text]
----
int matrix[][] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
outer: for (int row = 0; row < matrix.length; row++) { // Non-Compliant
for (int col = 0; col < matrix[row].length; col++) {
if (col == row) {
continue outer;
}
System.out.println(matrix[row][col]); // Prints the elements under the diagonal, i.e. 4, 7 and 8
}
}
----
=== Compliant solution
[source,text]
----
for (int row = 1; row < matrix.length; row++) { // Compliant
for (int col = 0; col < row; col++) {
System.out.println(matrix[row][col]); // Also prints 4, 7 and 8
}
}
----