Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluded annotated methods not ignored in Sonar #703

Closed
lawfulpepper opened this issue Nov 6, 2024 · 5 comments
Closed

Excluded annotated methods not ignored in Sonar #703

lawfulpepper opened this issue Nov 6, 2024 · 5 comments
Assignees
Labels
Question Support request issue type S: waiting for clarification Status: additional information required to proceed

Comments

@lawfulpepper
Copy link

lawfulpepper commented Nov 6, 2024

This is related to Issue #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!

@lawfulpepper lawfulpepper added Question Support request issue type S: untriaged Status: issue reported but unprocessed labels Nov 6, 2024
@shanshin
Copy link
Collaborator

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?

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels Nov 12, 2024
@lawfulpepper
Copy link
Author

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.

@shanshin
Copy link
Collaborator

@lawfulpepper, it seems that this is a feature of Sonar, it additionally analyze the classes present in the project.
Unfortunately, the only thing that Kover can control is the contents of the XML report, its interpretation lies with an external tool. Perhaps additional parameters can be passed to Sonar to exclude certain classes, like https://community.sonarsource.com/t/how-to-exclude-java-files/61786

If it is not possible to exclude classes by annotation now, then it may be worth to create such a feature request on the Sonar issue tracker.

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

As far as I understand, this was added to Sonar so that its behavior coincides with JaCoCo, because it also does not show classes marked with an annotation containing the word generated in the name.

@lawfulpepper
Copy link
Author

Hi @shanshin , thanks for looking into this. Could you point me to where the XML report generation tool is used in the Kover codebase? I'll close this comment and try to see if there's a way to override the behavior internally.

Thanks

@shanshin
Copy link
Collaborator

@lawfulpepper, https://github.com/JetBrains/coverage-report/tree/master/report-builder/src/jetbrains/coverage/report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Support request issue type S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

No branches or pull requests

2 participants