- which versions are you using: SonarQube Developer Edition 126.96.36.199466
- how is SonarQube deployed: Docker
- what are you trying to achieve: get accurate coverage metrics that skip comments nested in the function body
- what have you tried so far to achieve this: nothing, as those comments cannot be excluded or moved on the top of the function
Description of a problem:
If there are comments nested in the function body, above the uncovered lines, those will be counted as
uncovered lines, so eventually, those are considered by Sonar as uncovered code that affects the final
coverage metric. However, as soon as the real code line is covered, coverage metrics are accurately provided, ignoring comments during counting (or considering them as covered). Do I understand correctly, that If I have 98 lines of nested comments out of 100 (2 lines of actual code), I will get 2% of coverage?
SonarQube figures out what lines can be covered by tests based on the reports that were generated by your coverage tool. If your report says those lines can be covered… you probably want to raise an issue with that tool. SonarQube just reads the report.
I have a similar issue, but I don’t think the tool is the problem. Here’s my case:
However, istanbul sees the file as fully covered:
lcov.info file shows the following:
All found lines were hit (LH = LN), so I think this is SonarQube’s bug.
Edit: I’m using SonarQube 9.7.1.
If you can put together a minimal reproducer and attach it (or link to a public repo), it would really help us investigate!
@Colin Do we have an update this case? we are having a similar issue.
Nope. @rkrisztian hasn’t come back with a reproducer. If you can come back with one (and details about your setup, like what SonarQube verison you’re using), that would help us investigate!