Is there a lint check to prevent not invoking a la...
# announcements
l
Is there a lint check to prevent not invoking a lambda such as doing
onClick
instead of
onClick()
when
val onClick: () -> Unit
?
r
What if you want to do something like
a.onClick = b.onClick
?
l
A lint check should be able to verify not assigned not invoked lambda reference
r
What do you mean by "not assignment"? I believe assignment checks would handle the left side (
a.onClick
), but not the right side (
b.onClick
).
Also, you'd have to take into account things like custom getters that people would be accessing purely for the side effects and don't actually want to invoke the returned lambda.
l
I’m not saying that language has to prevent that, but a lint warning would be great
The side-effecty getter doesn’t seem like a good pattern to follow
I’m looking for a lint rule / warning to check if someone is not invoking a lambda and not assigning it.
r
I would agree, it's generally quite the code smell, but that doesn't mean it shouldn't be taken into account. I've unfortunately seen it used several times on delegated properties.
I'm not saying there shouldn't be such a lint check, just that there are a number of things to take into account to make sure it's good for most use cases as opposed to most of my use cases.
l
I’m guessing there is no such check currently
r
I don't believe so, but you can go to Project > Settings > Editor > Inspections and search through the Kotlin inspections (searching for "lambda" may help narrow the list down).
Sorry, I misread your original question and though you were requesting a lint check, not just asking if it exists.
l
Please, suggest this feature on kotl.in/issue I reported a similar one in the past and it was addressed: https://youtrack.jetbrains.com/issue/KT-23710