Kotlin / kotlinx-kover

Apache License 2.0
1.37k stars 53 forks source link

Excluded annotated methods not ignored in Sonar #703

Open lawfulpepper opened 1 week ago

lawfulpepper commented 1 week ago

This is related to Issue https://github.com/Kotlin/kotlinx-kover/issues/576.

Applies to version 0.8.3 and 0.9.0-RC.

I have Kover XML reports setup with Sonar.

Unfortunately excluding @Composable functions are not excluded in the Sonar coverage report.

If ignored, the @Composable is not added to the Kover XML report.

However, adding a simple Data Class in the same file causes Sonar to understand that this function should be ignored. Adding the Data Class adds the file to the XML report because of the uncovered Data Class.

data class UIData(
    val someData: String
)

@Composable
fun MyComposable() {
    Text("some text")
}

In the other issue, you had asked them if the XML report is used with Sonar. For us, yes, we are using the xml report path with Sonar.

Thanks!

shanshin commented 2 days ago

Unfortunately excluding @Composable functions are not excluded in the Sonar coverage report.

If ignored, the @Composable is not added to the Kover XML report.

Hi, do I understand correctly that the marked function is missing in the xml report, but it is still displayed in Sonar?

lawfulpepper commented 2 days ago

Hi shanshin, thanks for your reply!

Yes that's correct. Sonar interprets the absence of any report on a class as "Uncovered".

When I run the xmlReport for the following example:

@Composable
fun MyComposeTest() {
    Text("some text")
}

MyComposeTest is not added to the reportDebug.xml file. This is what Sonar reports:

sonar2

When I add the extra UIData class at the top:

data class UIData(
    val someData: String
)

@Composable
fun MyComposeTest() {
    Text("some text")
}

This is what the XML file report looks like:

<class name="com/abcd/xyz/tools/ui/UIData" sourcefilename="MyComposeTest.kt">  
<method name="&lt;init&gt;" desc="(Ljava/lang/String;)V">  
<counter type="INSTRUCTION" missed="7" covered="0"/>  
<counter type="BRANCH" missed="0" covered="0"/>  
<counter type="LINE" missed="2" covered="0"/>  
</method>

When Sonar receives this report, it shows that everything else is ignored except for the UIData data class.

sonar

Surprisingly, Jacoco's Generated annotation is able to exclude code from Sonar.

Thank you for looking into this.