Counting lines of code for uncompiled files

SonarQube Developer edition 10.1
Scanner 5.0.1.3006
C++

Hi,
I’ve noticed that SQ scanner counts LOC for all files under the folders specified in the sonar.sources property, not for only the ones that have been compiled.

This exhausts my license line count for no good reason.

Indeed, as a workaround I could make a long list of folders specifically tailored for sonar.sources, however this is a cumbersome process.

So my question is why would SQ count lines that are outside of the build?
Thanks!

Hey there.

  • Are you sure that Lines of Code are being calculated on these files, and not just Lines (only the former is used for license purposes)
  • The scanner searches through all folders recursively from the base directory – this is why if you have multiple languages in your project, for example, it doesn’t only focus on the C/C++ files the compiler is concerned with. You can find out what files are being indexed, and why, by turning on DEBUG level logging (sonar-scanner -X).

You can also adjust the analysis scope with exclusions, if needed.

Hi,
Yes, the SQ reports “Lines of code” with all LOC under the base directory. In addition, the scanner performs line/block duplication checks (and reports them) for ALL files, not only for the built ones.
Is that intentional? If the scanner looks at all files, why would we have to build at all with the wrapper?
Thanks.

The wrapper is collecting information required to analyze C/C++ files, that isn’t present without a build. Not all languages have this requirement.

I see.
In any case is there a way to limit the line count to only the lines participating in the build?

Not without configuring the analysis scope as mentioned before (which is more options than just choosing sonar.sources – you can also set wildcard patterns for what to include/exclude).

Yes I’ve been using it, however to narrow the scope to only the compiled files I’ll have to meticulously list only the required subfolders in sonar.sources. I was hoping the lines that weren’t compiled were not to be counted.