66 lines
1018 B
Plaintext
66 lines
1018 B
Plaintext
include::../description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,go]
|
|
----
|
|
func example(condition1, condition2 bool) {
|
|
if condition1 {
|
|
} else if condition1 { // Noncompliant
|
|
}
|
|
}
|
|
----
|
|
|
|
[source,go]
|
|
----
|
|
func SwitchWithMultipleConditions(param int) {
|
|
switch param {
|
|
case 1, 2, 3:
|
|
fmt.Println(">1")
|
|
case 3, 4, 5: // Noncompliant; 3 is duplicated
|
|
fmt.Println("<1")
|
|
}
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,go]
|
|
----
|
|
func example(condition1, condition2 bool) {
|
|
if condition1 {
|
|
} else if condition2 { // Compliant
|
|
}
|
|
}
|
|
----
|
|
|
|
[source,go]
|
|
----
|
|
func SwitchWithMultipleConditions(param int) {
|
|
switch param {
|
|
case 1, 2, 3:
|
|
fmt.Println(">1")
|
|
case 4, 5: // Compliant
|
|
fmt.Println("<1")
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
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[]
|