-
Notifications
You must be signed in to change notification settings - Fork 23
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
Use name of parameter if text is not available #274
Conversation
Thanks for the contribution! Before we can merge this, we need @kozaxinan to sign the Salesforce Inc. Contributor License Agreement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find and investigation, thanks!
compose-lint-checks/src/test/java/slack/lint/compose/ParameterOrderDetectorTest.kt
Outdated
Show resolved
Hide resolved
Revert formatting changes
Fix for src/test.kt line 20: Replace with (modifier: Modifier, text: String, lambda: Function0<Unit>): | ||
@@ -20 +20 | ||
- inline fun <reified T> MyComposable(text: String = "123", modifier: Modifier = Modifier, lambda: () -> Unit) : T { } | ||
+ inline fun <reified T> MyComposable(modifier: Modifier, text: String, lambda: Function0<Unit>) : T { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we unpack lambdas? Feels like we should be able to get the PSI text directly for the parameters and maybe just rearrange them in that range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check. I don't know how to get lambda when text is not available. I will check about sorting that differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to just get the text range for that PSI element in the worst case, which would let you just get the () ->
function syntax. My thinking is that this is the kind of thing that could be just a rearrangement of existing text, and you could do that replace in a stringy way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for PSI element idea. I updated code to create correct error message and lint fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Fixes #273
For standard compose functions,
method.uastParameters
returns parameter with delegated to KtUltraLightParameterForSource. KtUltraLightParameterForSource has proper text function to return.When method is generic with reified, delegated uast becomes UastKotlinPsiParameter and getText of UastKotlinPsiParameter returns null.
Those are from my investigation.
In this PR I suggest checking name of the parameter if text fails. If you know better way/ correct way to get text when function is reified, I can update the solution.
Example reified usage is
androidx.lifecycle.viewmodel.compose.viewModel
. We had a wrapper with wrong parameter order to hit this issue.