detekt-rules-compose
detekt-rules-compose copied to clipboard
False positive on `ModifierParameterPosition` and `ComposableParametersOrdering`
@Composable
fun MyComposable(
modifier: Modifier = Modifier,
content: LazyListScope.() -> Unit
) = LazyColumn(modifier = modifier, content = content)
ModifierParameterPosition and ComposableParametersOrdering raise an issue. The content parameter should be the last parameter.
Currently these rules ignore only @Composable trailing lambdas, because non-composable trailing lambdas are usually event handlers and they should follow the optional/required placement rule. We have discussed this in #12.
LazyColumn seems to be an exception here, because it's a DSL for building content, instead of content being a @Composable function.
I'm not sure yet how to best approach this:
- adding exception for
LazyListScopespecifically sounds like something flaky, other such "exceptions" may surface later - adding exception for any lambda with receiver also sounds like something which could be wrong: there can be some event handlers with scope...
Brainstorming (they are not good ideas, they are just random ideas that maybe help to find a solution):
- Ignore if the name is
content. - A configuration with a list of receivers to ignore and add
LazyListScopeas a default value. - A configuration where you need to describe ALL the lambda to be "ignored":
LazyListScope.() -> Unit. - A boolean configuration to relax this rule. If it is enabled all the trailing lambdas are allowed.
I like the second option (ignore specified receivers) and the fourth one (ignore all trailing lambdas). Maybe they both can be added as configuration parameters, although the ignoring all lambdas set to true will effectively override whatever is configured with second option, but this should not be too confusing.
I like the second option too, but I would like to add that it only makes sense to apply it to the last parameter of a function due to the DSL.