From ab693f7b8a975b393b3c376f0603d6177e2fc15b Mon Sep 17 00:00:00 2001 From: ali Date: Sat, 7 Mar 2026 19:31:59 +0100 Subject: [PATCH] fix: address remaining PR review comments for Kotlin/Android/KMP docs --- rules/kotlin/patterns.md | 12 ++++++------ rules/kotlin/testing.md | 2 +- skills/compose-multiplatform-patterns/SKILL.md | 2 +- skills/kotlin-coroutines-flows/SKILL.md | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rules/kotlin/patterns.md b/rules/kotlin/patterns.md index 483a68bf..ee5e4f14 100644 --- a/rules/kotlin/patterns.md +++ b/rules/kotlin/patterns.md @@ -15,14 +15,14 @@ Prefer constructor injection. Use Koin (KMP) or Hilt (Android-only): // Koin — declare modules val dataModule = module { single { ItemRepositoryImpl(get(), get()) } - factory { GetItemsUseCase(get()) } + factory { GetItemUseCase(get()) } viewModelOf(::ItemListViewModel) } // Hilt — annotations @HiltViewModel class ItemListViewModel @Inject constructor( - private val getItems: GetItemsUseCase + private val getItem: GetItemUseCase ) : ViewModel() ``` @@ -36,7 +36,7 @@ data class ScreenState( val isLoading: Boolean = false ) -class ScreenViewModel(private val useCase: GetItemsUseCase) : ViewModel() { +class ScreenViewModel(private val useCase: GetItemUseCase) : ViewModel() { private val _state = MutableStateFlow(ScreenState()) val state = _state.asStateFlow() @@ -90,21 +90,21 @@ expect class SecureStorage { actual fun platformName(): String = "Android" actual class SecureStorage { actual fun save(key: String, value: String) { /* EncryptedSharedPreferences */ } - actual fun get(key: String): String? { /* ... */ } + actual fun get(key: String): String? = null /* ... */ } // iosMain actual fun platformName(): String = "iOS" actual class SecureStorage { actual fun save(key: String, value: String) { /* Keychain */ } - actual fun get(key: String): String? { /* ... */ } + actual fun get(key: String): String? = null /* ... */ } ``` ## Coroutine Patterns - Use `viewModelScope` in ViewModels, `coroutineScope` for structured child work -- Use `stateIn(WhileSubscribed(5_000))` for StateFlow from cold Flows +- Use `stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), initialValue)` for StateFlow from cold Flows - Use `supervisorScope` when child failures should be independent ## Builder Pattern with DSL diff --git a/rules/kotlin/testing.md b/rules/kotlin/testing.md index 98a2e38d..1356ec82 100644 --- a/rules/kotlin/testing.md +++ b/rules/kotlin/testing.md @@ -21,7 +21,7 @@ paths: fun `loading state emitted then data`() = runTest { val repo = FakeItemRepository() repo.addItem(testItem) - val viewModel = ItemListViewModel(GetItemsUseCase(repo)) + val viewModel = ItemListViewModel(GetItemUseCase(repo)) viewModel.state.test { assertEquals(ItemListState(), awaitItem()) // initial state diff --git a/skills/compose-multiplatform-patterns/SKILL.md b/skills/compose-multiplatform-patterns/SKILL.md index 70e4ac65..62b01e28 100644 --- a/skills/compose-multiplatform-patterns/SKILL.md +++ b/skills/compose-multiplatform-patterns/SKILL.md @@ -31,7 +31,7 @@ data class ItemListState( ) class ItemListViewModel( - private val getItems: GetItemsUseCase + private val getItems: GetItemUseCase ) : ViewModel() { private val _state = MutableStateFlow(ItemListState()) val state: StateFlow = _state.asStateFlow() diff --git a/skills/kotlin-coroutines-flows/SKILL.md b/skills/kotlin-coroutines-flows/SKILL.md index 6650b0b7..12c8756d 100644 --- a/skills/kotlin-coroutines-flows/SKILL.md +++ b/skills/kotlin-coroutines-flows/SKILL.md @@ -218,7 +218,7 @@ viewModelScope.launch { @Test fun `search updates item list`() = runTest { val fakeRepository = FakeItemRepository(items = testItems) - val viewModel = ItemListViewModel(GetItemsUseCase(fakeRepository)) + val viewModel = ItemListViewModel(GetItemUseCase(fakeRepository)) viewModel.state.test { assertEquals(ItemListState(), awaitItem()) // initial