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

Parameter order detector imporvements #459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aasitnikov
Copy link

  1. Improve lint fix by preserving original parameters structure:
fun Sample(
    modifier: Modifier = Modifier, 
    text: String
)

// Lint fix before
fun Sample(text: String, modifier: Modifier = Modifier)

// Lint fix after
fun Sample(
    text: String, 
    modifier: Modifier = Modifier
)

  1. Disallow non-composable lambdas from being the valid last parameter:
// Before - function passes because onClick is functional interface
fun Button(text: String = "click me", onClick: () -> Unit)

fun Component() {
    Button { 
        // this is not a composable lambda, but a click listener
        viewModel.onButtonClicked()
    }
}

// After - lint fix applied
fun Button(onClick: () -> Unit, text: String = "click me")

fun Component() {
    // Does not compile - No value passed for parameter 'onClick'
    Button { 
        viewModel.onButtonClicked()
    }
    // This is ok
    Button(onClick = { viewModel.onButtonClicked() })
}


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

Successfully merging this pull request may close these issues.

1 participant