detekt-rules-compose icon indicating copy to clipboard operation
detekt-rules-compose copied to clipboard

[UnnecessaryEventHandlerParameter] False positive when there is a shadow variable

Open BraisGabin opened this issue 1 year ago • 1 comments

This component have little sense (infinite recursion) but it's a really easy reproducer of this false positive:

@Composable
fun Asdf(rotation: Float, onClick: (Float) -> Unit) {
    Column {
        Asdf(rotation, { rotation -> onClick(rotation) })
    }
}

This code fires UnnecessaryEventHandlerParameter but if I change the code to this:

@Composable
fun Asdf(rotation: Float, onClick: (Float) -> Unit) {
    Column {
        Asdf(rotation, { foo -> onClick(foo) })
    }
}

The rule works perfectly.

Probably using type solving this could be solvable. The other issue is on detekt itself. The shadowing rule doesn't catch that type of shadowing. I opened this other issue to track it: https://github.com/detekt/detekt/issues/7741

BraisGabin avatar Oct 24 '24 09:10 BraisGabin

Interesting! Thanks, I'll investigate this more closely and will think about how this could be solved, maybe it'll require to switch this rule to use type resolution indeed...

dimsuz avatar Oct 27 '24 15:10 dimsuz