How is the amount of Lines of Code calculated

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C#

Hi,

I’m working on getting multiple of our projects analyzed with SonarCloud. So far so good, but I’m about to hit 500k lines of code covered. So I started to look into this in a bit more detail and I have some questions on what lines of code are counted for the billing.

When I use the SonarCloud portal UI to navigate through the files I was under the impression that every using statement, white line, and comment were also counted in the total amount of LoC.

For example:

Is this indeed how I should expect the amount of LoC to be calculated for billing purposes?

Hi @AdeZwart

The “Lines” box you highlighted represents the number of lines of the file : this is not the number of LoCs of that file.
Number of Lines of Codes for files is visible one level above, when you see the list of files, example :

You can also go to the Measures tab, then expand Size, you’ll have the Lines of Codes for each files displayed here.

HTH,
Mickaël

Hi Mickaël,

Thanks a lot I see it now!

The sample I included in the screenshot shows 15 one level up. So only whitespaces are not counted in this case. Also I’ve looked at some other files and comments are not counted either.

I do see that all the usings and { } are counted, so that adds up pretty fast.

Thanks so far, it became a lot clearer to me.

Kind regards,

André

1 Like

Hello André

From SonarCloud

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.

Best,
Andrei

Hi Andrei,

I had been googling a bit, but hadn’t found this page. Thank you very much!

Kind regards,

André de Zwart

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.