Is there a more reliable way to check if a paramet...
# detekt
d
Is there a more reliable way to check if a parameter is a lambda, besides this horror?
Copy code
private fun isLambda(parameter: KtParameter) = ") -> " in parameter.text
Note that
isLambdaParameter
and
isFunctionTypeParameter
evaluate the
KtParameter
as a parameter of a lambda block
b
🤔 I'm on my modile so I can't check. But I know that I did some like this for forbiddenMethodCall. I mean, I had code there to check if a parameter is a lambda. You could check there.
d
I'm from mobile as well, so I might be wrong, but seems like that code is not there anymore
b
The magic is inside
FunctionMatcher
. You receive the
lambda
as a
kotlin.FunctionN
type.
where
N
can be 0, 1, 2, 3...
d
Thank you so much! I'll try that tomorrow first thing!
I looked into the class, but it seems like also there, we make a string comparison (
param.startsWith("(")
). Side note: I might misunderstood the use case, but from that function, I noted 2 things: • It never matches a lambda, as the String would be something like
block: () -> Unit
, so it would never start with
(
• Does it consider lambda with a receiver? Even matching the type only, it would fail with
Scope.() -> Unit
Are these intended, or are they bugs? 🙂
b
That class does two things: • Parse a String that comes from the config • Match that configuration with functions.
d
Oh, I see 🙏