
Co-authored-by: Amélie Renard <44666826+amelie-renard-sonarsource@users.noreply.github.com>
61 lines
1.0 KiB
Plaintext
61 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Having all branches of a `case` or `if` chain with the same implementation indicates a problem.
|
|
|
|
In the following code:
|
|
|
|
[source,ruby]
|
|
----
|
|
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`.
|
|
|
|
|
|
[source,ruby]
|
|
----
|
|
if b == 0 # no issue, this could have been done on purpose to make the code more readable
|
|
doSomething()
|
|
elsif b == 1
|
|
doSomething()
|
|
end
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|