Kotlin / kotlinx-kover

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

NasiaKoutsopoulou opened this issue · comments

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

  • Kover Gradle Plugin version: 0.7.3
  • Gradle version: 8.2.1
  • Kotlin project type: Kotlin/Android
  • Coverage Toolset (if customized in build script): Kover

If it feasible to support such cases or is there any workaround for this?

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)

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

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

excludes {
       classes(
                "*ComposableSingletons*"
       )
}