appKODE / detekt-rules-compose

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

[ModifierParameterPosition] Modifier with LazyListScope #37

Closed aptech73 closed 1 month ago

aptech73 commented 1 month ago

Good afternoon, colleagues.

I found an interesting feature, if Modifier is located above the required parameter of LazyListScope type (probably for all elements of Scope type) in the argument list, the linker generates an error:

@Composable fun CustomLazyColumn(modifier: Modifier = Modifier, content: LazyListScope.() -> Unit,) { ... } Modifier parameter should be the first parameter after required parameters (put it after "content") [ModifierParameterPosition]

However, if you arrange the arguments this way, the Modifier will not be available when CustomLazyColumn is called:

CustomLazyColumn(modifier = Modifier) { ... } Unresolved reference: modifier

I note that in LazyColumn the modifier is placed above all arguments: image

BraisGabin commented 1 month ago

🤔 No sure how this could be fixed. Should the name "content" be treated as an special case? Or should this be a good candidate for a suppress?

dimsuz commented 1 month ago

I know that Compose libraries have the similar rule for Android Lint, I wonder how they solve it, might check this.

But I also remembered that we have already had similar issue and discussed the possible solutions there, and even found one which seemed nice to few of us, see this comment.

I'll try implement and include the proposed solution in the next release!

I'll close this issue in favor of #17, thanks for the report!

BraisGabin commented 1 month ago

🤣🤣 I need to apply DRY to my issue comments 🤣🤣