Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive on UnnecessaryEventHandlerParameter #13

Closed
BraisGabin opened this issue Jul 25, 2022 · 4 comments
Closed

False positive on UnnecessaryEventHandlerParameter #13

BraisGabin opened this issue Jul 25, 2022 · 4 comments

Comments

@BraisGabin
Copy link
Contributor

Given this code:

internal sealed class State {
    object Loading : State()
    data class Data(val id: String) : State()
}

@Composable
internal fun MyButton(
    state: State,
    onClick: (String) -> Unit,
) {
    when (state) {
        State.Loading -> Text("Loading")
        is State.Data -> Button(onClick = { onClick(state.id) }) { Text("Click here") }
    }
}

UnnecessaryEventHandlerParameter raises an issue. But in this case the parameter is necessary because state.id is accesible because of the smart cast that you don't have in the function that call this component.

@dimsuz
Copy link
Collaborator

dimsuz commented Jul 25, 2022

Ugh, right. Not sure how to solve this without converting this rule to use type resolution (to check that State is a sealed class - it could be defined in other file/subproject).

(I'm still a bit hesitant to use type resolution, because I feel that it's not widely adopted at the moment, but perhaps I'm wrong. And maybe putting some direct advice + instructions on enabling it in the README would help)

@BraisGabin
Copy link
Contributor Author

BraisGabin commented Jul 26, 2022

Yes, to fix this we will need type resolution.

Right now I'm working on this on the detekt side:

With those type resolution will not be experimental anymore and we will inform users about the rules that they have active but they aren't working.

@dimsuz
Copy link
Collaborator

dimsuz commented Jul 26, 2022

Great work! So I'll get started. Both in adopting type resolution in our work projects and learning to write rules for it (only saw examples in the Detekt repo, didn't try myself).

@BraisGabin
Copy link
Contributor Author

To be honest, they are more complex. But the good part is that there are enoght examples in the detekt repo to find what you need.

@dimsuz dimsuz closed this as completed in 44b0f68 Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants