https://kotlinlang.org logo
#detekt
Title
# detekt
d

dimsuz

11/03/2021, 4:01 PM
During refactoring I often do something like:
Copy code
// before
val itemId = 3
onClick = { someListener(itemId) }
// after
onClick = { someListener() }
// OR
onClick = { itemId -> someListener(itemId) }
in the latter cases this can be simplified to (no extra wrapping lambda):
Copy code
onClick = someListener
I'm about to try to write a custom check for this, but I thought maybe there already is one?
c

chao

11/03/2021, 4:03 PM
I think the closest in the detekt repo is https://detekt.github.io/detekt/style.html#objectliteraltolambda, but there could be other detekt custom extensions that implemented this. If you have time, please help us by contributing a rule like such 🙏
d

dimsuz

11/03/2021, 4:04 PM
I suspect it would need to use type resolution to work correctly. This feature is new to me, most of my checks are not using it. But that makes it more interesting:)
e

ephemient

11/03/2021, 4:33 PM
that conversion can be ambiguous in case of overloaded functions, so it probably is only sound with type resolution. seems interesting though
c

chao

11/03/2021, 4:44 PM
The longer term solution for type resolution is going to be either detekt-compiler-plugin or the incoming frontend-IR based solution in the new K2 compiler
4 Views