Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive on ModifierParameterPosition and ComposableParametersOrdering #17

Open
AfigAliyev opened this issue Sep 9, 2022 · 4 comments

Comments

@AfigAliyev
Copy link

@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.

@dimsuz
Copy link
Collaborator

dimsuz commented Sep 9, 2022

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 LazyListScope specifically 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...

@BraisGabin
Copy link
Contributor

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 LazyListScope as 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.

@dimsuz
Copy link
Collaborator

dimsuz commented Sep 12, 2022

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.

@AfigAliyev
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants