rspec/rules/S1871/common/exceptions.adoc
2023-10-24 12:02:02 +00:00

17 lines
598 B
Plaintext

When all blocks are identical, either this rule will trigger if there is no default clause or rule S3923 will raise if there is a default clause.
=== Exceptions
Unless all blocks are identical, blocks in an `if` chain that contain a single line of code are ignored.
The same applies to blocks in a `switch` statement that contains a single line of code with or without a following `break`.
[source,{language}]
----
if (a == 1) {
doSomething(); // Compliant, usually this is done on purpose to increase the readability
} else if (a == 2) {
doSomethingElse();
} else {
doSomething();
}
----