Template for a good new topic, formatted with Markdown:
ALM used: GitHub
CI system used: GitHub
Scanner command used when applicable: default sonarcloud GitHub action
Languages of the repository: typescript
Potential workaround: needed
we are at the beginning of our Sonarcloud journey. I’ve successfully implemented the code coverage scan in one of our react app repos. Now our devs get 0% code coverage for lines that can not be tested (see. screenshot).
I’ve tried to Istanbul ignore this, but this does not seem to work (maybe I did something wrong if someone could show me how to ignore lines/functions that would be nice).
How should we handle this behavior?
Thank you very much
A few things:
Stating all of this – I’m not a TypeScript expert and have no idea if these lines should be considered executable. If not, I wonder if there’s something we can improve in the calculation, so I’ll flag this for a second pair of eyes.
Hey thanks for the quick reply,
I was using Istanbul like that:
and also tried to add it at the top of the file. I made some more digging and found this: Sonar doesn't respect istanbul ignore comments - #2 by ganncamp
maybe Istanbul is not the way to go?
I am aware of the
sonar.coverage.exclusions option but I am not sure if this makes for a good developer xp. It is extra maintenance to keep track of all the files a new feature has that uses
export const ... in that way. Also basically every initial scan will fail because they seem to use this everywhere. I’m not a typescript developer, but what if I have code that I actually want to test in the same file?
Dive into your coverage report or a moment (the report you’re passing to SonarCloud) – is this file mentioned? If not, is this specific line mentioned?
The files + lines are mentioned in the coverage report (
the lines mentioned there are the lines that sonarcloud will show in the web UI. When I add Istanbul ignores, only the coverage percentage of my file will change, not the mentioned lines.
Locally I have 100% coverage of the file:
Edit: the 100% only because of ignoring these cases with istanbul
lcov.info file example you don’t have any uncovered line (
DAs). Are you sure this example coverage report demonstrates that line uncovered in SQ UI?
I’m not quite sure how to read this file, so I just mapped the numbers that seemed logical to me.
Every Line/Number mentioned in the lcov.info file maps to an “uncovered line” in sonarcloud:
TBH I am lost now. We started the thread with the problem that “devs get 0% code coverage for lines that can not be tested”. And In the last message you say that there are actually covered lines which are being uncovered in SonarCloud UI.
How about you provide debug logs of your analysis?
Also note that paths in the report should be relative to the project root. Is that the case?