rspec/rules/S3087/rule.adoc

41 lines
683 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:48:39 +02:00
The point of using closure expressions is to clearly express a succinct bit of logic. Start nesting closure expressions too deeply and you create a logic snarl that will likely snare both you and future maintainers.
=== Noncompliant code example
2020-06-30 12:48:39 +02:00
With the maximum depth of 2:
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
foo(42) { (x: Int) in
bar(x) { (x: Int) in
foobar(x) { // Noncompliant
print(x * 42)
}
print(x + 42)
}
print(x - 42)
}
----
=== Compliant solution
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
func multPlus(x:Int) {
foobar(x) {
print(x * 42)
}
print(x + 42)
}
foo(42) { (x: Int) in
bar(x, multPlus)
print(x - 42)
}
----