If I use the API I get:
curl -k -u : ‘https://sonarqube-somewhere.co.uk/api/measures/component?componentKey=-services-cao&metricKeys=ncloc’
{“component”:{“id”:“AXGc2zG76a-oVcNnzxZL”,“key”:"-cao",“name”:"-services-cao",“qualifier”:“TRK”,“measures”:[{“metric”:“ncloc”,“value”:“6670”}]}}
If I count the lines of c# using a command line:
$ find . -name ‘*.cs’ | xargs wc -l
…
28304 total
I’m having issues with the development teams not wanting to run the tool because of this as the disparity is huge.
Can anyone explain?
It looks to me like in your screenshot you’ve drilled into a single, specific file in the Measures tab. So that’s going to give you the LOC of that one, single file. That’s as opposed to your API call, which appears to retrieve the value for - if not the entire project - at least something farther up the hierarchy than a single file.
The API query is now showing a figure that appears in the web interface for lines of code.
~/xxxxxxx-services-cao (master) $ curl -k -u eacb592928981596eac03e7fcef5bfa0e78a804f: ‘https://sonarqube-xxxxxx.co.uk/api/measures/component?componentKey=xxxxxx-services-cao&metricKeys=ncloc’
{“component”:{“id”:“AXGc2zG76a-oVcNnzxZL”,“key”:“xxxxxxxx-services-cao”,“name”:“xxxxx-services-cao”,“qualifier”:“TRK”,“measures”:[{“metric”:“ncloc”,“value”:“6670”}]}}
But a manual check for lines of code is still way higher than what is being reported by sonarqube:
~/xxxxxxx-services-cao (master) $ find . -name ‘*.cs’ | xargs wc -l
…
28304 total
So how does ‘Lines of code’ get derived?
I’d also be interested in how Lines is derived as this is way off from a manual check as well…
~/xxxxxxxx-services-cao (master) $ find . -name ‘.’ | xargs wc -l
…
61625 total
Lines ( lines )
Number of physical lines (number of carriage returns).
Lines of code ( ncloc )
Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment.