Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
Integrate Compose Lint Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Feb 10, 2023
1 parent df25f32 commit c6731df
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.accompanist.navigation.animation)
implementation(libs.accompanist.navigation.material)

Expand Down
6 changes: 6 additions & 0 deletions common/ui/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ android {
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composecompiler.get()
}

lint {
baseline = file("lint-baseline.xml")
}
}

dependencies {
Expand All @@ -57,5 +61,7 @@ dependencies {
implementation(libs.androidx.paging.runtime)
implementation(libs.androidx.paging.compose)

lintChecks(libs.slack.lint.compose)

implementation(libs.coil.compose)
}
37 changes: 37 additions & 0 deletions common/ui/compose/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.0.0-beta02" type="baseline" client="gradle" dependencies="false" name="AGP (8.0.0-beta02)" variant="all" version="8.0.0-beta02">

<issue
id="ComposeParameterOrder"
message="Parameters in a composable function should be ordered following this pattern: params without defaults, modifiers, params with defaults and optionally, a trailing function that might not have a default param.&#xA;Current params are: [title: @Composable () -> Unit, modifier: Modifier = Modifier, navigationIcon: @Composable () -> Unit, bottomContent: @Composable (() -> Unit)? = null, actions: @Composable RowScope.() -> Unit = {}, containerColor: Color = MaterialTheme.colorScheme.surface, contentColor: Color = contentColorFor(containerColor), elevation: Dp = 0.dp] but should be [title: @Composable () -> Unit, navigationIcon: @Composable () -> Unit, modifier: Modifier = Modifier, bottomContent: @Composable (() -> Unit)? = null, actions: @Composable RowScope.() -> Unit = {}, containerColor: Color = MaterialTheme.colorScheme.surface, contentColor: Color = contentColorFor(containerColor), elevation: Dp = 0.dp].&#xA;See https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly for more information."
errorLine1="/**"
errorLine2="^">
<location
file="src/main/java/app/tivi/common/compose/ui/AppBar.kt"
line="39"
column="1"/>
</issue>

<issue
id="ComposeUnstableCollections"
message="The Compose Compiler cannot infer the stability of a parameter if a List&lt;SortOption> is used in it, even if the item type is stable.&#xA;You should use Kotlinx Immutable Collections instead: `sortOptions: ImmutableList&lt;SortOption>` or create an `@Immutable` wrapper for this class: `@Immutable data class SortOptionsList(val items: List&lt;SortOption>)`&#xA;See https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections for more information."
errorLine1=" sortOptions: List&lt;SortOption>,"
errorLine2=" ~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/tivi/common/compose/ui/SortChip.kt"
line="43"
column="18"/>
</issue>

<issue
id="ComposeUnstableCollections"
message="The Compose Compiler cannot infer the stability of a parameter if a List&lt;SortOption> is used in it, even if the item type is stable.&#xA;You should use Kotlinx Immutable Collections instead: `sortOptions: ImmutableList&lt;SortOption>` or create an `@Immutable` wrapper for this class: `@Immutable data class SortOptionsList(val items: List&lt;SortOption>)`&#xA;See https://slackhq.github.io/compose-lints/rules/#avoid-using-unstable-collections for more information."
errorLine1=" sortOptions: List&lt;SortOption>,"
errorLine2=" ~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/tivi/common/compose/ui/SortMenuPopup.kt"
line="32"
column="18"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* limitations under the License.
*/

// Will be fixed by https://github.com/slackhq/compose-lints/pull/52
@file:SuppressLint("ComposeCompositionLocalUsage")

package app.tivi.common.compose

import android.annotation.SuppressLint
import androidx.compose.runtime.staticCompositionLocalOf
import app.tivi.util.TiviDateFormatter
import app.tivi.util.TiviTextCreator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import app.tivi.common.compose.theme.TiviTheme
fun ScrimmedIconButton(
showScrim: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
invertThemeOnScrim: Boolean = true,
icon: @Composable () -> Unit,
) {
IconButton(onClick = onClick) {
IconButton(onClick = onClick, modifier = modifier) {
if (invertThemeOnScrim) {
val isLight = MaterialTheme.colorScheme.surface.luminance() > 0.5

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ retrofit-mock = { module = "com.squareup.retrofit2:retrofit-mock", version.ref =

robolectric = "org.robolectric:robolectric:4.9.2"

slack-lint-compose = "com.slack.lint.compose:compose-lint-checks:1.0.0"

store = "org.mobilenativefoundation.store:store5:5.0.0-alpha03"

threeTenAbp = "com.jakewharton.threetenabp:threetenabp:1.4.4"
Expand Down
2 changes: 2 additions & 0 deletions ui/account/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.coil.compose)

implementation(libs.androidx.hilt.navigationcompose)
Expand Down
2 changes: 2 additions & 0 deletions ui/discover/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 2 additions & 0 deletions ui/episodedetails/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

api(libs.accompanist.navigation.material)

implementation(libs.coil.compose)
Expand Down
2 changes: 2 additions & 0 deletions ui/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.coil.compose)

implementation(libs.androidx.hilt.navigationcompose)
Expand Down
2 changes: 2 additions & 0 deletions ui/popular/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 2 additions & 0 deletions ui/recommended/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 2 additions & 0 deletions ui/search/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 2 additions & 0 deletions ui/showdetails/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ dependencies {

implementation(libs.coil.compose)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 2 additions & 0 deletions ui/showseasons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.coil.compose)

implementation(libs.androidx.hilt.navigationcompose)
Expand Down
2 changes: 2 additions & 0 deletions ui/trending/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation(libs.compose.animation.animation)
implementation(libs.compose.ui.tooling)

lintChecks(libs.slack.lint.compose)

implementation(libs.androidx.hilt.navigationcompose)
implementation(libs.hilt.library)
kapt(libs.hilt.compiler)
Expand Down

0 comments on commit c6731df

Please sign in to comment.