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