SonarCloud | Managing your subscription | Lines of code

Was this page helpful?

On this page

Start FreeLog in

Lines of code

In SonarCloud, the number of lines of code (LOC) you plan on analyzing plays an important role in your choice of subscription plan. While you can analyze an indefinite number of LOCs in your open-source projects, for private projects, the number of LOCs that can be analyzed is limited by your subscription plan.  You need to ensure that your choice of plan is enough to cover all of the LOCs you want to analyze as otherwise, you may not be able to onboard all of your projects. 

Checking your lines of code consumption

If you are concerned that you might be close to the LOC limit defined in your subscription plan, you can check your current consumption as follows:

To view overall consumption to date for all projects in your organization, go to Your Organization > Administration > Billing > Current plan.

Manage your SonarCloud lines of code for billing.

The dashboard shows details of the total LOC analyzed to date, as well as the total number of projects.

Click on the number of projects to view a breakdown of the number of lines of code contained in each project within your organization. 

SonarCloud lines of code distribution per project.

Exceeding your LOC threshold

You cannot exceed your LOC threshold in SonarCloud. Once you are near your LOC limit, you will receive a notification informing you of this and advising you to upgrade your current subscription plan to a higher LOC limit or to reduce the number of LOC in your projects.

You can analyze the same code as often as you like. If you try to analyze more LOC than is allowed as part of your current subscription, SonarCloud will not perform the analysis and you will also receive an error message clearly explaining the reason for this.  

Calculating lines of code

Lines of code are calculated by adding up the LOCs of each project analyzed. The LOCs that are counted are those found on the largest branch of the project. If you have set up branch analysis, then the LOCs will be counted from the latest analysis of the project with the largest branch or PR.  This means that if your main branch, for whatever reason, does not contain any LOC, then the largest branch (or PR) will be counted instead. 

For example:

  • If a project has 500 lines of code on its main branch and 400 on a secondary branch, then the number of LOCs counted for the project is 500.
  • If a project has 0 lines of code on its main branch (provisioned but never analyzed) and 200 on a secondary branch, then the number of LOCs counted is 200.

Typically, the simple formula for calculating the total number of lines of code (LOC) for the projects in your organization is by adding:

(P1 LOC) + (P2 LOC) + (P3 LOC) + (P4 LOC) = Total LOC

There are a number of exceptions that are not counted when calculating consumption on your LOC limit:

  • Test code
  • Files excluded from analysis  
  • Code in unsupported languages
  • Comments or blank lines
  • Code from public projects within your organization

For full details on pricing plans, see our product website

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License