slackhq/compose-lints

False Positive Reusing Modifier in Composable when inner composable parameters have the same name

Closed this issue · 1 comments

Got a false positive because the modifier from the Circuit UI composable's had the same name as another nested Composable higher order function that also provided a Modifier that was named modifier. To Android Studio, the inner modifier wasn't a problem and wasn't referencing the outer TestScreenUi modifier.

@CircuitInject(TestScreen::class, UserScope::class)
@Composable
fun TestScreenUi(state: TestScreen.State, modifier: Modifier = Modifier) {
  Scaffold(
    modifier = modifier,
    topBar = {
      SKTopAppBar(
        ...
      )
    },
  ) { paddingValues ->
    SKList(
      ...
      customView = { vm, modifier ->
        when (vm.customViewType) {
          VIEW_TYPE_MY_CUSTOM -> {
            MyCustomRow(viewModel = vm, modifier = modifier)
          }
          ...
        }
      }
    )
  }
}

If I changed to the following, the error would disappear.

@CircuitInject(TestScreen::class, UserScope::class)
@Composable
fun TestScreenUi(state: TestScreen.State, modifier: Modifier = Modifier) {
  Scaffold(
    modifier = modifier,
    topBar = {
      SKTopAppBar(
        ...
      )
    },
  ) { paddingValues ->
    SKList(
      ...
      customView = { vm, rowModifier -> // <---- Here to rowModifier
        when (vm.customViewType) {
          VIEW_TYPE_MY_CUSTOM -> {
            MyCustomRow(viewModel = vm, modifier = rowModifier). // <---- Here to rowModifier
          }
          ...
        }
      }
    )
  }
}

Duplicate of #268. In short, you should avoid name shadowing anyway