appKODE / detekt-rules-compose

A collection of Detekt rules for Jetpack Compose
MIT License
136 stars 8 forks source link

ComposableParametersOrdering should not consider one last function parameter #36

Closed DHosseiny closed 6 months ago

DHosseiny commented 6 months ago

It is a good practice to pass function as last parameter to use it as lambda:

fun someFunction(
    modifier: Modifier = Modifier,
    onClick: () -> Unit
)

someFunction(
    modifier = Modifier.width(1.dp)
) {
  doSomething()
}

But when last function parameter has no default value ComposableParametersOrdering considers it as error. It is good to allow one mandatory function as last parameter in this rule.

DHosseiny commented 6 months ago

Anyway, I can contribute on this if it is desirable.

dimsuz commented 6 months ago

We had it like this at first, but then it turned out that this violates the parameter order recommended by Google, where required parameters must go first. Also Android Studio has the lint check which reports this rule violation. Now we follow this too, and it actually makes sense, you can read more on the reasoning in the official guidelines documentation.

DHosseiny commented 6 months ago

It makes sense.