How are the exact Lines of code calculated?

Please provide more clarity on LOC.
I have 2 projects and each project contain 2k line of code so does this cout 4k when it check with loc limit or each project max code branch will be calculated separately.
Please confirm

Welcome :slight_smile:

from Plans & Pricing

How are Lines of Code (LOC) counted?

LOC are computed by summing up the LOC of each project analyzed. The LOC count for a project is the LOC count of the project’s largest branch.

Gilbert

This doesn’t describe the algorithm for calculating LOC, though.

  • Is the algorithm akin to foreach (file in files) loc += file.GetLineCount;?
  • Does it ignore blank lines? (What counts as blank lines?)
  • Can I add a pre-build step in my pipeline to minify my source files to a single line before analysis? (loc = files.Count;)

“Largest branch” is helpful; it is good to know that LOC only scales with main and not branch count.

Hi @ahaleiii,

You may find the metric definition helpful.

Not quite. If your main branch is empty or for whatever reason a non-main branch has more LOC, it will be counted for license purposes.

 
HTH,
Ann

Hi Ann,

Regarding the “largest branch”, I am understanding it as you say. I used “main” to conceptually refer to the latest branch, assuming it has the most LOC in it. Apologies for not expressing that more clearly.

Also, thanks for sharing that link. I found these parts to be most relevant for me:

If I could roughly express it in pseudocode again:

// for single project
foreach (file in files)
  allLines += file.GetLineCount;
  irrelevantLines += calculateIrrelevantLines(file); // not whitespace, tabulation, or comment
loc = allLines - irrelevantLines;

Not sure if someone with insight beyond the documentation is able to comment as to whether this is on the right track.

@Subash_Uniyal, is your understanding helped by the documentation shared by Ann and what Gilbert shared about all projects adding up toward the total LOC?

No my query is still not resolved.
Simple question, I have two developer license and each developer is working on two seperate projects so how does LOC will be counted?
Would it counted license wise?

You don’t buy the license on developer base. You buy them for each server you plan to use. The number of Developers using the server (with 1 license) don’t play a role.

The LOC ist calculated over all projects hosted on the server.

If you want separate licences on base of projects, you have to setup separated server for each project too.

1 Like

I am taking about sonarqube developer license. Please check below link where I see about developer license.

https://www.sonarqube.org/trial-request/developer-edition/

Right you buy one license für the “Sonarqube Server Developer Edition”, not one license for every developer.

There is no limitation at the amount of developers using this server. Only a limitation at the amount of LOC over all projects hosted on the server.

Great thanks.

does the below link is same for the explanation of the same and if my LOC get exceeded then can i renew it with the next without making changes in server? please let me know.

https://www.sonarqube.org/trial-request/developer-edition/

If the LOC get exceeded, the server will stop accepting new analysis from your sonarscanner (for example from jenkins).

You have either to upgrade your license or delete a project fron the Sonarqube Server.

See if my LOC limit is expected then with the same developer license can I renew that in below order?

Hi @Subash_Uniyal,

The link you have provided is an accurate description of how licensing works w/r/t lines of code. SonarQube will not accept an analysis that would push you over your licensed lines of code. If you find that your projects have grown beyond what you’re licensed for, you’ll need to upgrade the size of your license. You’ll be given a new license key with the larger limit and apply that to your server. No need to make any other changes other than applying the new, larger license.

If you have further licensing questions, it might be best to direct them to your sales contact.

 
HTH,
Ann

Thanks for getting back to me.
Can you please send the installation guide document so I can start working on it.

Hi,

I don’t know what you mean by that. The docs are here.

 
Ann

Thanks for your email.

Hi @Subash_Uniyal ,

Thank you for your interest in SonarSource products!

I think the simplest thing will be to request a trial license and see it in action: Automatic Branch Analysis & Pull Request Decoration Tools | SonarQube

Best regards,

Luis