rspec/rules/S1871/swift/compliant.adoc
2023-10-24 12:02:02 +00:00

30 lines
575 B
Plaintext

If the same logic is needed for both instances, then:
* in an `if` statement, they should be merged.
[source,swift,diff-id=1,diff-type=compliant]
----
if (a >= 0 && a < 10) || (if a >= 20 && a < 50) {
doFirstThing()
doTheThing()
} else if a >= 10 && a < 20 {
doTheOtherThing()
} else {
doTheRest()
}
----
* for a `switch`, the values should be put in the `case` expression list.
[source,swift,diff-id=2,diff-type=compliant]
----
switch i {
case 1, 3:
doFirstThing()
doSomething()
case 2:
doSomethingDifferent()
default:
doTheRest()
}
----