How Duplications Metrics Works on New Code in Sonarqube?

Hi Team,

We are using Sonarqube 8.9.6 Community Edition.

I want to understand little bit about How duplications metrics on new code works in Sonarqube.

If I see lines of code marked as duplicate under the “New Code” section, does it mean the lines of code are duplicate in the same file or across all the files considered as new code?

                                               [or]

Across all files in the repo?

Regards,
Murali Sulam

Hi Murali,

There’s a brown/grey marginal marker next to duplicated code. Click it to see the duplication details.

 
HTH,
Ann

Hi,

Thanks for the response.

Yes I can see the duplication details marked with grey. My question was more on-if a block of new code is marked as duplicate, which files are being referred to while identifying this block as new code - All files marked under New Code or All files under overall code?

Regards,
Murali Sulam

Hi Murali,

Ehm… the file that’s marked ‘new’ is the file being referred to.

Or maybe I don’t understand the question?

 
Ann

Hi,

Let me try explaining with an example.

Assume there are 100 files in my enentire repo. Out of which 5 files are shown under new code due to changes made say File1, File2, File3, File4 & File5.

Now in File 5 there is a block of 20 lines of code marked as Duplicate by SonarQube.

My question is - how is the duplicate code identified?

Does it check this block of 20 codes against the 5 files under new code
OR
Does it compare it with all 100 files in the Repo?

Hope the question is clear now.

Regards,
Murali Sulam

Hi Murali,

Thanks for your patience. :joy:

Yes, duplication detection is run against the entire code base. And then out of all duplications found, the ones that happen on new code are reported as duplications on new code.

 
HTH,
Ann

Hi,

Thanks for your response. We got the info what we are looking for.

Regards,
Murali Sulam

1 Like