From ed321869842f5e586901bf4ccfd0dbf18fc7c342 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 28 Sep 2023 14:09:09 +0530 Subject: [PATCH] refactor(build): adopt Slack lints --- android/build.gradle.kts | 3 +++ .../dev/msfjarvis/claw/android/ui/LobstersApp.kt | 10 ++++++++-- .../dev/msfjarvis/claw/gradle/AndroidCommonPlugin.kt | 1 + common/build.gradle.kts | 1 + .../dev/msfjarvis/claw/common/comments/CommentEntry.kt | 4 +++- .../dev/msfjarvis/claw/common/comments/Comments.kt | 8 +++++--- .../dev/msfjarvis/claw/common/user/UserProfile.kt | 8 +++++--- .../claw/core/coroutines/DispatcherProvider.kt | 2 +- .../claw/core/injection/CoroutineDispatcherModule.kt | 2 +- gradle/libs.versions.toml | 3 +++ 10 files changed, 31 insertions(+), 11 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 999b9c9d..2a7fc3ac 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -46,6 +46,9 @@ licensee { allow("MIT") ignoreDependencies("org.commonmark") { because("Commonmark is BSD licensed") } allowUrl("https://jsoup.org/license") { because("Jsoup is MIT licensed") } + allowUrl("https://opensource.org/licenses/isc-license.txt") { + because("kotlin-result is ISC licensed") + } } moduleGraphAssert { diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt index 55366158..214da83b 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt @@ -262,7 +262,10 @@ fun LobstersApp( navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}" }, ), ) { backStackEntry -> - val postId = requireNotNull(backStackEntry.arguments?.getString("postId")) + val postId = + requireNotNull(backStackEntry.arguments?.getString("postId")) { + "Navigating to ${Destinations.Comments.route} without necessary 'postId' argument" + } setWebUri("https://lobste.rs/s/$postId") CommentsPage( postId = postId, @@ -278,7 +281,10 @@ fun LobstersApp( deepLinks = listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.placeholder}" }), ) { backStackEntry -> - val username = requireNotNull(backStackEntry.arguments?.getString("username")) + val username = + requireNotNull(backStackEntry.arguments?.getString("username")) { + "Navigating to ${Destinations.User.route} without necessary 'username' argument" + } setWebUri("https://lobste.rs/u/$username") UserProfile( username = username, diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/AndroidCommonPlugin.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/AndroidCommonPlugin.kt index 8c7a4680..251cbe5a 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/AndroidCommonPlugin.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/AndroidCommonPlugin.kt @@ -62,6 +62,7 @@ class AndroidCommonPlugin : Plugin { val catalog = project.extensions.getByType() val libs = catalog.named("libs") project.dependencies.addProvider("lintChecks", libs.findLibrary("slack-compose-lints").get()) + project.dependencies.addProvider("lintChecks", libs.findLibrary("slack-lints").get()) } private fun Project.configureSlimTests() { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index fda29d97..c97e3f07 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -50,6 +50,7 @@ dependencies { implementation(libs.compose.richtext.ui) implementation(libs.kotlinx.collections.immutable) implementation(libs.kotlinx.coroutines.core) + implementation(libs.kotlinResult.coroutines) implementation(libs.napier) compileOnly(libs.androidx.compose.ui.tooling.preview) diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt index 7aa2d16c..2a402cae 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt @@ -37,6 +37,8 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp +import com.github.michaelbull.result.coroutines.runSuspendCatching +import com.github.michaelbull.result.onSuccess import dev.msfjarvis.claw.common.posts.PostActions import dev.msfjarvis.claw.common.posts.PostTitle import dev.msfjarvis.claw.common.posts.Submitter @@ -61,7 +63,7 @@ internal fun CommentsHeader( produceState( initialValue = LinkMetadata(postDetails.url, null), ) { - runCatching { postActions.getLinkMetadata(postDetails.url) } + runSuspendCatching { postActions.getLinkMetadata(postDetails.url) } .onSuccess { metadata -> value = metadata } } diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt index 5da029b1..043597e7 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt @@ -25,6 +25,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import com.github.michaelbull.result.coroutines.runSuspendCatching +import com.github.michaelbull.result.fold import dev.msfjarvis.claw.common.NetworkState import dev.msfjarvis.claw.common.NetworkState.Error import dev.msfjarvis.claw.common.NetworkState.Loading @@ -109,10 +111,10 @@ fun CommentsPage( ) { val postDetails by produceState(Loading) { - runCatching { postActions.getComments(postId) } + runSuspendCatching { postActions.getComments(postId) } .fold( - onSuccess = { details -> value = Success(details) }, - onFailure = { value = Error(error = it, description = "Failed to load comments") } + success = { details -> value = Success(details) }, + failure = { value = Error(error = it, description = "Failed to load comments") }, ) } val commentState by diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/user/UserProfile.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/user/UserProfile.kt index aae8cebf..3e351787 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/user/UserProfile.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/user/UserProfile.kt @@ -25,6 +25,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp +import com.github.michaelbull.result.coroutines.runSuspendCatching +import com.github.michaelbull.result.fold import dev.msfjarvis.claw.common.NetworkState import dev.msfjarvis.claw.common.NetworkState.Error import dev.msfjarvis.claw.common.NetworkState.Loading @@ -44,10 +46,10 @@ fun UserProfile( ) { val user by produceState(Loading) { - runCatching { getProfile(username) } + runSuspendCatching { getProfile(username) } .fold( - onSuccess = { profile -> value = Success(profile) }, - onFailure = { + success = { profile -> value = Success(profile) }, + failure = { value = Error( error = it, diff --git a/core/src/main/kotlin/dev/msfjarvis/claw/core/coroutines/DispatcherProvider.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/coroutines/DispatcherProvider.kt index d1711e24..81c77f70 100644 --- a/core/src/main/kotlin/dev/msfjarvis/claw/core/coroutines/DispatcherProvider.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/coroutines/DispatcherProvider.kt @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -@file:Suppress("InjectDispatcher") // False-positive +@file:Suppress("RawDispatchersUse") // False-positive package dev.msfjarvis.claw.core.coroutines diff --git a/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/CoroutineDispatcherModule.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/CoroutineDispatcherModule.kt index 2c87c2b5..b358c8a1 100644 --- a/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/CoroutineDispatcherModule.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/CoroutineDispatcherModule.kt @@ -28,7 +28,7 @@ import kotlinx.coroutines.CoroutineDispatcher @ContributesTo(ApplicationScope::class) interface CoroutineDispatcherModule { - @Binds fun DefaultDispatcherProvider.bind(): DispatcherProvider + @Binds fun bindDispatcherProvider(impl: DefaultDispatcherProvider): DispatcherProvider companion object { @[Provides IODispatcher] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6441ba7f..2819913b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ glance = "1.0.0" junit = "5.10.0" konvert = "2.3.0" kotlin = "1.9.10" +kotlinResult = "1.1.18" retrofit = "2.9.0" richtext = "0.17.0" sentry-sdk = "6.29.0" @@ -78,6 +79,7 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" } kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" } +kotlinResult-coroutines = { module = "com.michael-bull.kotlin-result:kotlin-result-coroutines", version.ref = "kotlinResult" } napier = "io.github.aakira:napier:2.6.1" okhttp-bom = "com.squareup.okhttp3:okhttp-bom:4.11.0" okhttp-core = { module = "com.squareup.okhttp3:okhttp" } @@ -88,6 +90,7 @@ retrofit-kotlinxSerializationConverter = "com.jakewharton.retrofit:retrofit2-kot sentry-bom = { module = "io.sentry:sentry-bom", version.ref = "sentry-sdk" } sentry-okhttp = { module = "io.sentry:sentry-android-okhttp", version.ref = "sentry-sdk" } slack-compose-lints = "com.slack.lint.compose:compose-lint-checks:1.2.0" +slack-lints = "com.slack.lint:slack-lint-checks:0.6.0" sqldelight-androidDriver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" } sqldelight-extensions-coroutines = { module = "app.cash.sqldelight:coroutines-extensions-jvm", version.ref = "sqldelight" } sqldelight-jvmDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }