compose-lints icon indicating copy to clipboard operation
compose-lints copied to clipboard

Rule to detect not passing modifier to all branches

Open ansman opened this issue 1 year ago • 0 comments

A common issue I find is when using a when in a composable and not propagating the modifier parameter to all branches, typically when a new branch is added. For example:

@Composable
fun SomeScreenContent(
  state: SomeViewState,
  modifier: Modifier = Modifier,
) {
  when (state) {
    is SomeViewState.Loading -> SomeScreenLoadingContent()
    is SomeViewState.Loaded -> SomeScreenLoadedContent(modifier)
  }
}

I'd like to see a warning/error on the is SomeViewState.Loading -> SomeScreenLoadingContent() branch saying that you probably want to pass the modifier parameter. The exception is if the composable doesn't accept a modifier.

ansman avatar Feb 18 '25 22:02 ansman