This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

See latest version
Start Free
10.1 | Instance administration | Lines of Code

Lines of Code

On this page

In SonarQube, the number of Lines of Code (LOC) you plan on analyzing plays an important role in your choice of subscription plan. Your LOC consumption is relevant only for Commercial Editions (Developer, Enterprise, and Data Center). Commercial Support is included with some plans; see the Sonar Plans and Pricing page for more details. 

Checking your lines of code consumption

Go to Administration > Configuration > License Manager to check how many lines of code you are currently using. Select Edit notification threshold to define when an email should be sent with information in regards to the impending lines of code limit. You cannot exceed your LOC threshold. If you're near your limit, you may need to purchase additional lines of code. 

You can check your LOC per project, per branch, in three different locations:

  • Select Project Information to reveal the LOC on your main branch (for that project). Note that this may not exactly be your max LOC, for example, another branch or PR might have more lines of code.
  • Navigate to the Your Project > Measures > Size page via the UI for a list of folders & files with a count of each folders’ and files’ LOC.
  • Navigate to Your Project > Code page for a list of folders & files with a count of each folders’ and files’ LOC.

Exceeding your LOC threshold

Once you are near your limit, you will receive a notification with advice to upgrade your current subscription plan to a higher LOC limit, or to reduce the number of LOC in your projects. On the License Manager page, select the Edit notification threshold button to define when notifications will be sent.

If you reach your limit, you will receive an error message and the SonarQube instance will stop accepting new analyses which will make the LOC exceed the limit defined by the license. 

If you reach your limit, you will receive an error message and the SonarQube instance will reject any analysis whose total lines of code exceed the limit defined by your license. In no way does this affect access to basic functionalities such as saving configuration changes and allowing project browsing. In all cases, you can still analyze your code if the new analysis doesn't surpass the LOC limit defined by your license.

Calculating lines of code

Lines of code are calculated by summing the LOC 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 LOC will be counted from the most recent 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 500 lines of code on its main branch and a PR is issued with 540 lines of code, then the number of LOCs counted for the project is 540.
  • 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 your lines of code is by adding:

  • Project 1 LOC  + Project 2 LOC  + Project 3 LOC = Total LOC

Now that it’s clear that LOC is calculated from your largest branch, it’s important to note that your lines of test code do not count toward your License Usage.

There are a number of exceptions to take into account when calculating your LOC:

  • Lines of test code do not count as LOC.
  • Files excluded from analysis are not counted. See the page on setting your Analysis scope for more details about file exclusions.
  • Code in unsupported languages does not count as LOC. However, if you run a 3rd party plugin that introduces support (for that language), the newly analyzed code will be counted towards your LOC.
  • Comments or blank lines do not count as LOC.
  • You can’t use up your license by reanalyzing the same code (with the same number of lines).

For more details on subscription plans and what’s included with your plan, see our Plans & Pricing page. 


Was this page helpful?

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

Creative Commons License