Having all branches of a case
or if
chain with the same implementation indicates a problem.
In the following code:
if b == 0 # Noncompliant
doOneMoreThing()
else
doOneMoreThing()
end
b = a > 12 ? 4 : 4; # Noncompliant
case i # Noncompliant
when 1
doSomething()
when 2
doSomething()
when 3
doSomething()
else
doSomething()
end
Either there is a copy-paste error that needs fixing or an unnecessary case
or if
chain that needs removing.
Exceptions
This rule does not apply to if
chains nor case
without else
.
if b == 0 # no issue, this could have been done on purpose to make the code more readable
doSomething()
elsif b == 1
doSomething()
end