You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compose-lint-checks/src/test/java/slack/lint/compose/UnstableReceiverDetectorTest.kt
+43-18Lines changed: 43 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,6 @@ class UnstableReceiverDetectorTest : BaseComposeLintTest() {
43
43
@Composable
44
44
fun Example.OtherContent() {}
45
45
46
-
@get:Composable
47
-
val Example.OtherContentProperty get() {}
48
-
49
46
@Stable
50
47
enum class EnumExample {
51
48
TEST;
@@ -108,16 +105,13 @@ class UnstableReceiverDetectorTest : BaseComposeLintTest() {
108
105
@Composable
109
106
fun Example.OtherContent() {}
110
107
111
-
@get:Composable
112
-
val Example.OtherContentProperty get() {}
113
-
114
108
// Supertypes
115
-
interface Presenter<T> {
116
-
@Composable fun present(): T
109
+
interface Presenter {
110
+
@Composable fun present()
117
111
}
118
112
119
-
class HomePresenter : Presenter<String> {
120
-
@Composable override fun present(): String { return "hi" }
113
+
class HomePresenter : Presenter {
114
+
@Composable override fun present() { println("hi") }
121
115
}
122
116
"""
123
117
.trimIndent()
@@ -135,18 +129,49 @@ class UnstableReceiverDetectorTest : BaseComposeLintTest() {
135
129
src/ExampleInterface.kt:12: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
136
130
fun Example.OtherContent() {}
137
131
~~~~~~~
138
-
src/ExampleInterface.kt:15: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
139
-
val Example.OtherContentProperty get() {}
140
-
~~~~~~~
141
-
src/ExampleInterface.kt:19: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
142
-
@Composable fun present(): T
132
+
src/ExampleInterface.kt:16: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
133
+
@Composable fun present()
143
134
~~~~~~~
144
-
src/ExampleInterface.kt:23: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
145
-
@Composable override fun present(): String { return "hi" }
135
+
src/ExampleInterface.kt:20: Warning: Instance composable functions on non-stable classes will always be recomposed. If possible, make the receiver type stable or refactor this function if that isn't possible. See https://slackhq.github.io/compose-lints/rules/#unstable-receivers for more information. [ComposeUnstableReceiver]
136
+
@Composable override fun present() { println("hi") }
146
137
~~~~~~~
147
-
0 errors, 6 warnings
138
+
0 errors, 5 warnings
148
139
"""
149
140
.trimIndent()
150
141
)
151
142
}
143
+
144
+
@Test
145
+
fun`unstable receiver types with non-Unit return type report no errors`() {
146
+
@Language("kotlin")
147
+
val code =
148
+
"""
149
+
import androidx.compose.runtime.Composable
150
+
151
+
interface ExampleInterface {
152
+
@Composable fun Content(): String
153
+
}
154
+
155
+
class Example {
156
+
@Composable fun Content(): String { return "hi" }
157
+
}
158
+
159
+
@Composable
160
+
fun Example.OtherContent(): String { return "hi" }
161
+
162
+
@get:Composable
163
+
val Example.OtherContentProperty get() {}
164
+
165
+
// Supertypes
166
+
interface Presenter<T> {
167
+
@Composable fun present(): T
168
+
}
169
+
170
+
class HomePresenter : Presenter<String> {
171
+
@Composable override fun present(): String { return "hi" }
Copy file name to clipboardExpand all lines: docs/rules.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,9 @@ Related rule: [`ComposeMutableParameters`](https://github.com/slackhq/compose-li
71
71
In compose, all parameters must be stable or immutable in order for a composable function to be
72
72
_restartable_ or _skippable_. This _includes_ the containing class or receiver, which the compose-compiler will treat as the 0th argument. Using an unstable receiver is usually a bug, so this lint offers a warning to raise this issue.
73
73
74
+
!!! warning "Use with Strong Skipping"
75
+
If you have Strong Skipping enabled, we recommend disabling this rule to avoid potential false negatives.
76
+
74
77
More info: [Compose API Stability](https://developer.android.com/jetpack/compose/performance/stability)
75
78
76
79
Related rule: [`ComposeUnstableReceiver`](https://github.com/slackhq/compose-lints/blob/main/compose-lint-checks/src/main/java/slack/lint/compose/UnstableReceiverDetector.kt)
0 commit comments