rspec/rules/S3923/scala/rule.adoc
2022-02-04 16:28:24 +00:00

50 lines
1007 B
Plaintext

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
[source,scala]
----
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
}
----
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[]