Having all branches in a match
or if
chain with the same implementation is an error. Either a copy-paste error was made
and something different should be executed, or there shouldn’t be a match
/if
chain at all.
Noncompliant Code Example
if (b == 0) { // Noncompliant
doSomething
} else {
doSomething
}
i match { // Noncompliant
case 1 => doSomething
case 2 => doSomething
case 3 => doSomething
case _ => doSomething
}
Exceptions
This rule does not apply to if
chains without else
-s, or to match
-es without case _
alternatives.
if (b == 0) {
doSomething
} else if (b == 1) {
doSomething
}