slackhq / compose-lints

Lint checks to aid with a healthy adoption of Compose
https://slackhq.github.io/compose-lints
Apache License 2.0
388 stars 21 forks source link

ComposeViewModelForwarding doesn't check nested blocks #148

Open Ilya-Gh opened 1 year ago

Ilya-Gh commented 1 year ago

The following codes report the error(as expected):

@Composable
fun ComposableOk(
    viewModel: ViewModel,
    modifier: Modifier = Modifier
) {
    ComposableWithViewModel(viewModel = viewModel)
}

In the following screnario, the rule fails to detect the issue when the viewModel is transferred between Composable layers, leading to a false-negative:

@Composable
fun ComposableFalseNegative(
    viewModel: ViewModel,
    modifier: Modifier = Modifier
) {
    Row {
        ComposableWithViewModel(viewModel = viewModel)
    }
}
ZacSweers commented 1 year ago

Can you please paste the error or screenshot?

Ilya-Gh commented 1 year ago

@ZacSweers Sorry for not stating it clear enough. The issue is that the ComposeViewModelForwarding rule does not report the error when it should.

The case:

@Composable
fun ComposableFalseNegative(
    viewModel: ViewModel,
    modifier: Modifier = Modifier
) {
    Row {
        ComposableWithViewModel(viewModel = viewModel)
    }
}
mkaomwakuni commented 11 months ago

Could be the ViewModel logic since this approach makes it hard to reuse or replace it some cases