feat(build): add Slack's Compose Lints

This commit is contained in:
Harsh Shandilya 2023-04-27 14:43:47 +05:30
parent f0ac9f97e2
commit 5659ad9863
No known key found for this signature in database
5 changed files with 26 additions and 2 deletions

View file

@ -128,6 +128,17 @@
column="4"/>
</issue>
<issue
id="ComposeUnstableCollections"
message="The Compose Compiler cannot infer the stability of a parameter if a List&lt;GpgIdentifier> is used in it, even if the item type is stable.&#xA;You should use Kotlinx Immutable Collections instead: `identifiers: ImmutableList&lt;GpgIdentifier>` or create an `@Immutable` wrapper for this class: `@Immutable data class IdentifiersList(val items: List&lt;GpgIdentifier>)`&#xA;See https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections for more information."
errorLine1=" identifiers: List&lt;GpgIdentifier>,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt"
line="36"
column="16"/>
</issue>
<issue
id="UnknownNullness"
message="Should explicitly declare type here since implicit type does not specify nullness (Lazy&lt;Array&lt;(GitCommand&lt;out (Any or Any?)> or GitCommand&lt;out (Any or Any?)>?)>>)"

View file

@ -7,9 +7,11 @@ import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.TestedExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
object AndroidCommon {
@ -56,5 +58,11 @@ object AndroidCommon {
}
project.extensions.findByType<ApplicationExtension>()?.run { lint.configureLint(project) }
project.extensions.findByType<LibraryExtension>()?.run { lint.configureLint(project) }
val catalog = project.extensions.getByType<VersionCatalogsExtension>()
val libs = catalog.named("libs")
project.dependencies.addProvider(
"lintChecks",
libs.findLibrary("thirdparty-compose-lints").get()
)
}
}

View file

@ -23,6 +23,6 @@ class KotlinJVMLibrary : Plugin<Project> {
apply(LintPlugin::class)
apply(KotlinCommonPlugin::class)
}
project.extensions.configure<Lint> { configureLint(project) }
project.extensions.configure<Lint> { configureLint(project, isJVM = true) }
}
}

View file

@ -4,7 +4,7 @@ import com.android.build.api.dsl.Lint
import org.gradle.api.Project
object LintConfig {
fun Lint.configureLint(project: Project) {
fun Lint.configureLint(project: Project, isJVM: Boolean = false) {
quiet = project.providers.environmentVariable("CI").isPresent
abortOnError = true
checkReleaseBuilds = true
@ -28,6 +28,10 @@ object LintConfig {
disable += "TypographyQuotes"
// False-positives abound due to use of ViewBinding
disable += "UnusedIds"
if (!isJVM) {
enable += "ComposeM2Api"
error += "ComposeM2Api"
}
baseline = project.file("lint-baseline.xml")
}
}

View file

@ -79,6 +79,7 @@ testing-turbine = "app.cash.turbine:turbine:0.12.3"
thirdparty-bouncycastle-bcpkix = { module = "org.bouncycastle:bcpkix-jdk15to18", version.ref = "bouncycastle" }
thirdparty-bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk15to18", version.ref = "bouncycastle" }
thirdparty-commons_codec = "commons-codec:commons-codec:1.14"
thirdparty-compose-lints = "com.slack.lint.compose:compose-lint-checks:1.2.0"
thirdparty-eddsa = "net.i2p.crypto:eddsa:0.3.0"
thirdparty-fastscroll = "me.zhanghai.android.fastscroll:library:1.2.0"
thirdparty-flowbinding-android = { module = "io.github.reactivecircus.flowbinding:flowbinding-android", version.ref = "flowbinding" }