Kotlin / kotlinx-kover

Apache License 2.0
1.28k stars 48 forks source link

Exclusion rule using annotatedBy does not work if multiple annotations are present #528

Closed NasiaKoutsopoulou closed 4 months ago

NasiaKoutsopoulou commented 4 months ago

Describe the bug If we set an exclusion rule using annotatedBy, for annotation that uses AnnotationRetention.BINARY or AnnotationRetention.RUNTIME, but the given function has multiple annotations set, and one of those is AnnotationRetention.SOURCE, exclusion is not working.

Expected behavior We would expect to be able to exclude a function based on a specific annotation, regardless of other annotations being present.

Reproducer

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun TestComposable() {
  Text("This is a test composable")
}

Note that OptIn is using AnnotationRetention.SOURCE whereas Composable annotation is using AnnotationRetention.BINARY.

Our Kover.gradle contains the following rule:

koverReport {
  filters {
    excludes {
      classes(
         ...
      )
      annotatedBy(
        "androidx.compose.runtime.Composable",
        ...
      )
    }
    ...
  }

Environment

shanshin commented 4 months ago

Hi, in your case, if you remove the @OptIn annotation, will function TestComposable be excluded from the HTML report?

If so, could you please create a complete producer project, because I can't reproduce the problem locally (the TestComposable function successfully excluded from the report)

NasiaKoutsopoulou commented 4 months ago

Hey @shanshin. Apologies for the misunderstanding.

Upon further investigation, it appears that the issue is not related to the additional annotation after all. The problem seems to stem from our composable, the lambda parameter and the associated underlying Java bytecode.

I am attaching some screenshots for additional clarification. Below is our composable:

@Composable
@OptIn(ExperimentalMaterialApi::class)
fun DismissibleUpcomingRequest(
  state: UpcomingTimeOffRequestUIState,
  onActionA: (UpcomingTimeOffRequestUIState, Dp) -> Unit,
  onActionB: () -> Unit
) {
...
}

I looked into the HTML report because we were using Danger and the PR reporting seemed off. Turns out, the exclusion of annotated composables is working, but the generated bytecode, related to our lambda parameter, isn't giving us the exclusion we wanted.

Not sure if it's our Compose usage or something up with Kover.

I am closing this as a false issue report, intending to delve further into identifying the root cause. Should we require support from Kover, I will revisit the matter accordingly.

Screenshot 2024-01-25 at 1 59 53 PM Screenshot 2024-01-25 at 1 59 45 PM
mirianfonkam commented 1 month ago

I ran into the same issue. This solved it for me:

excludes {
       classes(
                "*ComposableSingletons*"
       )
}