I was reading this post about Lcov.info vs SonarQube coverage. It was helpful in understanding why we are getting uncovered lines of code in one of our angular projects.
I have noticed that a lot of lines that are uncovered in SonarQube (and not the lcov.info) are where we export constants. I noticed this is not mentioned in the examples of things that are ignored for coverage in the sonar executable lines.
My questions are:
Is there a reason why export const is considered as executable code in SonarQube?
If not, could it be possible to add this to ignored executable lines?
Additional Info:
We are using the following:
SonarQube Enterprise Edition, Version 9.8
SonarQubePrepare@5, SonarQubeAnalyze@5 and SonarQubePublish@5 azure pipeline tasks
If you’re providing an lcov.info for a file, that file itself is saying whether or not that line can be covered by code.
If there’s no information being provided for a file, SonarQube has to “guess” (it runs this code to determine if the line is executable or not).
Is this falling into that second category? This can happen if, for example, there is no coverage being reported on that file at all. It would be very weird if some coverage is being reported on that file by an lcov.info file, but saying nothing about the export const line.
In the lcov.info those files do not exist, but they are appearing in sonar so I believe it is the second category. For example, some environment files where a replacement is done or some routes files.
We could ignore those files by using sonar.coverage.exclusions but I just found it strange that export const was part of the executable code.
I tend to agree that export const should not be counted as executable. I want to confirm that we are talking about “purely declarative” export const foo; lines as opposed to when there is an initializer, eg
export const foo = () => { bar(); }
I guess we would still want to see coverage for such lines, right?