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

Allow nullable types for trailing lambdas in ComposeParameterOrder #134

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.tools.lint.detector.api.Severity
import com.android.tools.lint.detector.api.SourceCodeScanner
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtFunctionType
import org.jetbrains.kotlin.psi.KtNullableType
import org.jetbrains.kotlin.psi.KtParameter
import slack.lint.compose.util.Priorities
import slack.lint.compose.util.isModifier
Expand Down Expand Up @@ -97,5 +98,10 @@ class ParameterOrderDetector : ComposableFunctionDetector(), SourceCodeScanner {
}

private val KtFunction.hasTrailingFunction: Boolean
get() = valueParameters.lastOrNull()?.typeReference?.typeElement is KtFunctionType
get() =
when (val outerType = valueParameters.lastOrNull()?.typeReference?.typeElement) {
is KtFunctionType -> true
is KtNullableType -> outerType.innerType is KtFunctionType
else -> false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class ParameterOrderDetectorTest : BaseSlackLintTest() {

@Composable
fun MyComposable(text1: String, modifier: Modifier = Modifier, m2: Modifier = Modifier, trailing: () -> Unit) { }

@Composable
fun MyComposable(text1: String, modifier: Modifier = Modifier, m2: Modifier = Modifier, trailing: (() -> Unit)?) { }
"""
.trimIndent()
lint().files(kotlin(code)).allowCompilationErrors().run().expectClean()
Expand Down