Skip to content

Rule to detect not passing modifier to all branches #466

@ansman

Description

@ansman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions