Lines of Code (LoC) count for Pull Requests (PR) counts test code

Environment

  • GitLab Free self-managed 13.12.2-ee
  • Jenkins CI 2.289.1 with GitLab Branch Source Plugin 1.5.7
  • Gradle 6.6.1 Java 8 library project with SonarQube plugin in version 3.2.0
  • SonarQube self-managed developer edition 8.9

How to Reproduce

  1. Create a git project with at lease a main and a feature branch
  2. Create a pull request from feature too main
  3. Publish a scan to SonarQube from main
  4. Publish a scan to SonarQube from feature
  5. Publish a scan to SonarQube from the Pull Request build

Observed behavior

  • test code in branches are not count into the LoC
  • test code in pull requests are count into the LoC

Expected behavior

  • test code are not count into the LoC

Hi,

Welcome to the community!

In fact, for PRs Lines (including comments, blank lines and yes, test lines) are counted rather than Lines of Code.

 
Ann

Thanks for the reply.

This means that PRs raise my LoC count which raises my license costs?

Hi,

What counts toward LoC for license purposes is the Lines of Code of the largest branch of each project. It appears that Lines of Code aren’t even calculated for branches, so no they don’t raise your license cost.

 
Ann

The line count of a project in SonarQube is the same as the line count of the largest branch. In case a project has no branches scanned, only PRs, will the LoC be based on the largest PR? Taking into account what you write above, this means such a project most likely has a rather large LoC, since also empty lines etc are counted?

Hi,

Empty lines are not counted. Only ‘Lines of Code’ are counted. The docs should help.

The main branch counts as a ‘branch’ for these purposes. I’m not enturely certain it’s possible to analyze a PR with no branches (not even main) analyzed.

 
Ann

I’m not sure I follow.

but

I’m confused. Which is it in case of project with only PRs? I’m thinking maybe I wasn’t clear about what I mean with a project with no branches.

I was talking about a project with no branches analyzed, not even main/master. Like so (the project below has plenty of PRs analysed):