Comments nested in the function body affect coverage metrics

  • which versions are you using: SonarQube Developer Edition 9.9.0.65466
  • 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?

Hey there.

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.

1 Like

I have a similar issue, but I don’t think the tool is the problem. Here’s my case:

image

However, istanbul sees the file as fully covered:

The lcov.info file shows the following:

TN:
SF:src/app/team-roster.component.ts
FNF:0
FNH:0
DA:18,1
DA:20,2
LF:2
LH:2
BRF:0
BRH:0
end_of_record

All found lines were hit (LH = LN), so I think this is SonarQube’s bug.

Edit: I’m using SonarQube 9.7.1.

Hey @rkrisztian

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!