Skip to content

Commit 7a62c39

Browse files
authored
Fix plugin application in lint module (#32)
1 parent 2ee89b7 commit 7a62c39

File tree

8 files changed

+77
-75
lines changed

8 files changed

+77
-75
lines changed

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ streamProject {
2727

2828
coverage {
2929
includedModules = setOf("stream-android-core")
30-
sonarCoverageExclusions = setOf(
31-
"**/lint/**",
32-
)
3330
}
3431
}
3532

stream-android-core-lint/build.gradle.kts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import com.vanniktech.maven.publish.JavadocJar
22
import com.vanniktech.maven.publish.KotlinJvm
33

44
plugins {
5-
libs.plugins.stream.java.library
5+
alias(libs.plugins.stream.java.library)
66
alias(libs.plugins.jetbrains.kotlin.jvm)
77
alias(libs.plugins.maven.publish)
88
alias(libs.plugins.dokka)
99
}
1010

11-
1211
dependencies {
1312
compileOnly(libs.lint.api)
1413
compileOnly(libs.lint.checks)
@@ -28,12 +27,12 @@ mavenPublishing {
2827
coordinates(
2928
groupId = io.getstream.core.Configuration.artifactGroup,
3029
artifactId = "stream-android-core-lint",
31-
version = rootProject.version.toString()
30+
version = rootProject.version.toString(),
3231
)
3332
configure(
3433
KotlinJvm(
3534
javadocJar = JavadocJar.Dokka("dokkaJavadoc"),
3635
sourcesJar = true,
37-
)
36+
),
3837
)
3938
}

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/StreamIssueRegistry.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint
1718

1819
import com.android.tools.lint.client.api.IssueRegistry

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/detectors/ExposeAsStateFlowDetector.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint.detectors
1718

1819
import com.android.tools.lint.client.api.UElementHandler
@@ -229,20 +230,20 @@ class ExposeAsStateFlowDetector : Detector(), Detector.UastScanner {
229230
briefDescription = "Expose MutableStateFlow as read-only via asStateFlow()",
230231
explanation =
231232
"""
232-
Exposing a MutableStateFlow directly (even when typed as StateFlow) allows consumers to downcast
233-
and mutate your internal state. Wrap the internal MutableStateFlow with asStateFlow() when you
234-
expose it.
235-
236-
Problematic:
237-
private val _state = MutableStateFlow(initial)
238-
val state: StateFlow<State> = _state
239-
val state: StateFlow<State> get() = _state
240-
241-
Correct:
242-
private val _state = MutableStateFlow(initial)
243-
val state: StateFlow<State> = _state.asStateFlow()
244-
val state: StateFlow<State> get() = _state.asStateFlow()
245-
"""
233+
Exposing a MutableStateFlow directly (even when typed as StateFlow) allows consumers to downcast
234+
and mutate your internal state. Wrap the internal MutableStateFlow with asStateFlow() when you
235+
expose it.
236+
237+
Problematic:
238+
private val _state = MutableStateFlow(initial)
239+
val state: StateFlow<State> = _state
240+
val state: StateFlow<State> get() = _state
241+
242+
Correct:
243+
private val _state = MutableStateFlow(initial)
244+
val state: StateFlow<State> = _state.asStateFlow()
245+
val state: StateFlow<State> get() = _state.asStateFlow()
246+
"""
246247
.trimIndent(),
247248
category = Category.CORRECTNESS,
248249
priority = 7,

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/detectors/KeepInstanceDetector.kt

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint.detectors
1718

1819
import com.android.tools.lint.client.api.UElementHandler
@@ -373,13 +374,13 @@ class KeepInstanceDetector : Detector(), Detector.UastScanner {
373374
"Comma-separated FQNs of stateful types that must not be used as temporaries",
374375
explanation =
375376
"""
376-
Any constructor/factory call whose expression type is the same as, or a subtype of, one of these
377-
fully-qualified names will be treated as a stateful instance that needs to be kept (stored or returned),
378-
not created and immediately used or discarded.
377+
Any constructor/factory call whose expression type is the same as, or a subtype of, one of these
378+
fully-qualified names will be treated as a stateful instance that needs to be kept (stored or returned),
379+
not created and immediately used or discarded.
379380
380-
Example:
381-
com.example.SomeType, io.getstream.video.android.core.StreamClient
382-
"""
381+
Example:
382+
com.example.SomeType, io.getstream.video.android.core.StreamClient
383+
"""
383384
.trimIndent(),
384385
)
385386

@@ -391,32 +392,32 @@ class KeepInstanceDetector : Detector(), Detector.UastScanner {
391392
"Don’t use stateful instances as temporaries or discard them",
392393
explanation =
393394
"""
394-
Types that expose observable or long-lived state (for example, via StateFlow) must be kept.
395-
Creating an instance inline and immediately chaining a call, or creating it as a standalone
396-
expression and discarding the value, can stop updates from being delivered and may leak resources.
397-
398-
Flags:
399-
• SomeType(...).state.collect { ... } // calling members on a temporary instance
400-
• SomeType(...) // created and discarded
401-
402-
How to fix:
403-
• Store the instance in a variable and use it, or
404-
• Return the instance from the current function.
405-
406-
Correct:
407-
val client = StreamClient(config)
408-
client.connectionState.collect { /* ... */ }
409-
410-
Problematic:
411-
StreamClient(config).connectionState.collect { /* ... */ }
412-
413-
Configuration:
414-
You can configure which types are considered stateful via lint.xml:
415-
<issue id="NotKeepingInstance">
416-
<option name="keepInstanceOf"
417-
value="com.example.SomeType, io.getstream.video.android.core.StreamClient"/>
418-
</issue>
419-
"""
395+
Types that expose observable or long-lived state (for example, via StateFlow) must be kept.
396+
Creating an instance inline and immediately chaining a call, or creating it as a standalone
397+
expression and discarding the value, can stop updates from being delivered and may leak resources.
398+
399+
Flags:
400+
• SomeType(...).state.collect { ... } // calling members on a temporary instance
401+
• SomeType(...) // created and discarded
402+
403+
How to fix:
404+
• Store the instance in a variable and use it, or
405+
• Return the instance from the current function.
406+
407+
Correct:
408+
val client = StreamClient(config)
409+
client.connectionState.collect { /* ... */ }
410+
411+
Problematic:
412+
StreamClient(config).connectionState.collect { /* ... */ }
413+
414+
Configuration:
415+
You can configure which types are considered stateful via lint.xml:
416+
<issue id="NotKeepingInstance">
417+
<option name="keepInstanceOf"
418+
value="com.example.SomeType, io.getstream.video.android.core.StreamClient"/>
419+
</issue>
420+
"""
420421
.trimIndent(),
421422
category = Category.CORRECTNESS,
422423
priority = 7,

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/detectors/MustBeInternalDetector.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint.detectors
1718

1819
import com.android.tools.lint.client.api.UElementHandler
@@ -195,9 +196,9 @@ class MustBeInternalDetector : Detector(), Detector.UastScanner {
195196
"Comma-separated package **glob** patterns that represent internal packages; declarations here must not be public.",
196197
explanation =
197198
"""
198-
Supports wildcards: '*' matches any sequence (including dots), '?' matches a single char. " +
199-
Examples: 'io.getstream.core.internal', 'io.getstream.*.internal', 'com.example.internal*'."
200-
"""
199+
Supports wildcards: '*' matches any sequence (including dots), '?' matches a single char. " +
200+
Examples: 'io.getstream.core.internal', 'io.getstream.*.internal', 'com.example.internal*'."
201+
"""
201202
.trimIndent(),
202203
)
203204

@@ -208,9 +209,9 @@ class MustBeInternalDetector : Detector(), Detector.UastScanner {
208209
briefDescription = "Disallow `public` in internal packages",
209210
explanation =
210211
"""
211-
Declarations located in packages marked as internal must not be `public`. \
212-
Use `internal` (preferred) or `private`.
213-
"""
212+
Declarations located in packages marked as internal must not be `public`. \
213+
Use `internal` (preferred) or `private`.
214+
"""
214215
.trimIndent(),
215216
category = Category.CORRECTNESS,
216217
priority = 7,

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/detectors/StreamApiExplicitMarkerDetector.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint.detectors
1718

1819
import com.android.tools.lint.client.api.UElementHandler
@@ -230,12 +231,12 @@ class StreamApiExplicitMarkerDetector : Detector(), Detector.UastScanner {
230231
description = "Comma-separated package **glob** patterns where the rule applies.",
231232
explanation =
232233
"""
233-
Supports wildcards: '*' (any sequence) and '?' (single char).
234-
Examples:
235-
- 'io.getstream.android.core.api'
236-
- 'io.getstream.android.core.*.api'
237-
- 'io.getstream.android.*'
238-
"""
234+
Supports wildcards: '*' (any sequence) and '?' (single char).
235+
Examples:
236+
- 'io.getstream.android.core.api'
237+
- 'io.getstream.android.core.*.api'
238+
- 'io.getstream.android.*'
239+
"""
239240
.trimIndent(),
240241
)
241242

@@ -245,8 +246,8 @@ class StreamApiExplicitMarkerDetector : Detector(), Detector.UastScanner {
245246
description = "Comma-separated package **glob** patterns to exclude from the rule.",
246247
explanation =
247248
"""
248-
Same glob syntax as 'packages'. Evaluated after includes.
249-
"""
249+
Same glob syntax as 'packages'. Evaluated after includes.
250+
"""
250251
.trimIndent(),
251252
)
252253

@@ -259,9 +260,9 @@ class StreamApiExplicitMarkerDetector : Detector(), Detector.UastScanner {
259260
"StreamApiExplicitMarkerMissing",
260261
"Public API must be explicitly marked",
261262
"""
262-
To prevent accidental exposure, all top-level public declarations must be explicitly \
263-
marked as @StreamPublishedApi (allowed to leak) or @StreamInternalApi (not allowed to leak).
264-
"""
263+
To prevent accidental exposure, all top-level public declarations must be explicitly \
264+
marked as @StreamPublishedApi (allowed to leak) or @StreamInternalApi (not allowed to leak).
265+
"""
265266
.trimIndent(),
266267
Category.CORRECTNESS,
267268
7,

stream-android-core-lint/src/main/java/io/getstream/android/core/lint/detectors/SuspendRunCatchingDetector.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package io.getstream.android.core.lint.detectors
1718

1819
import com.android.tools.lint.client.api.UElementHandler
@@ -116,11 +117,11 @@ class SuspendRunCatchingDetector : Detector(), Detector.UastScanner {
116117
briefDescription = "Use runCatchingCancellable in suspend contexts",
117118
explanation =
118119
"""
119-
Using `kotlin.runCatching { ... }` inside a suspend \
120-
function or a suspend lambda, cancellation is not propagated as expected. \
121-
Prefer `runCatchingCancellable { ... }`, which rethrows `CancellationException` while \
122-
still returning `Result` for other failures.
123-
"""
120+
Using `kotlin.runCatching { ... }` inside a suspend \
121+
function or a suspend lambda, cancellation is not propagated as expected. \
122+
Prefer `runCatchingCancellable { ... }`, which rethrows `CancellationException` while \
123+
still returning `Result` for other failures.
124+
"""
124125
.trimIndent(),
125126
category = Category.CORRECTNESS,
126127
priority = 7,

0 commit comments

Comments
 (0)