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

Ignore context receivers in multiple content emissions lint #135

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 @@ -96,6 +96,10 @@ constructor(
// things like
// BoxScope which are legit, and we want to avoid false positives.
.filter { it.hasBlockBody() }
// Same applies to context receivers: we could have a BoxScope/ColumnScope/RowScope
// and it'd be legit.
// We don't have a way to know for sure, so we'd better avoid the issue altogether.
.filter { it.contextReceivers.isEmpty() }
// We want only methods with a body
.filterNot { it.hasReceiverType }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ class MultipleContentEmittersDetectorTest : BaseSlackLintTest() {
lint().files(kotlin(code)).allowCompilationErrors().run().expectClean()
}

@Test
fun `passes when the composable is a context receiver`() {
@Language("kotlin")
val code =
"""
context(ColumnScope)
@Composable
fun Something() {
Text("Hi")
Text("Hola")
}
context(RowScope)
@Composable
fun Something() {
Spacer16()
Text("Hola")
}
"""
.trimIndent()
lint().files(kotlin(code)).allowCompilationErrors().run().expectClean()
}

@Test
fun `errors when a Composable function has more than one UI emitter at the top level`() {
@Language("kotlin")
Expand Down