rspec/rules/S2968/swift/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

57 lines
1.8 KiB
Plaintext

== Why is this an issue?
Trailing closure syntax can only be used with the last argument to a function call. Place a function type parameter anywhere else in the list and you limit the options of the caller.
=== Noncompliant code example
[source,swift]
----
func foo(p1: Int->Int, p2: Int){ // Noncompliant; p1 should come at the end
print(p1(p2))
}
foo({a in a * 2}, 42) // Trailing closure syntax can't be used here
----
=== Compliant solution
[source,swift]
----
func foo(p2: Int, p1: Int->Int){
print(p1(p2))
}
foo(42) {a in a * 2}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move "x" to the end of the parameter list.
'''
== Comments And Links
(visible only on this page)
=== on 21 May 2015, 17:33:56 Ann Campbell wrote:
\[~freddy.mallet] what do you think of the SQALE characteristic? I'm not sure what to pick for rules about making your API easier to use.
=== on 27 May 2015, 09:01:12 Freddy Mallet wrote:
Hi @Ann, according to the description of this rule the code provided in the "Non-Compliant Code Example" will lead to a runtime error so I would associate this rule to the SQALE "Reliability " characteristic. But at the same time I'm not sure to fully understand this rule.
=== on 27 May 2015, 19:13:52 Ann Campbell wrote:
Thanks for weighing in [~freddy.mallet], but what we're looking at in the first line of the Noncompliant example is the function declaration, and as-is, you cannot use trailing closure syntax to call it. (This code made my eyes cross, and [~elena.vilchik] had to talk to me like I was 6 when explaining it.)
So this really is just about making your API easier to use, & I'm afraid the exactly right SQALE category doesn't exist for it. :-/
endif::env-github,rspecator-view[]