Sonarqube doesn't identify duplication code on Ruby projects

  • Using Developer Edition Version 9.9 - Helm Deployment
  • I identify a difference between the sonar analysis on MR/PR(merge or pull request) and Main branch. During the MR analysis, the Sonar wasn’t able to identify duplication in the code, but when we ran the approved MR on the Main pipeline these duplications showed up on the report.
  • I Intentionally did duplications on some projects, for all projects made in JS or TS, the duplication is shown, as expected, in the analysis, but for the Ruby projects these duplications aren’t.
    Following the Examples:
    I did some duplications in an entire file to see the duplication detection by Sonar:

Example on Ruby project:

Example on JS and TS Projects:


Hi,

Welcome to the community!

I’m confused. Your first screenshot shows 3 Ruby files, two with duplications reported.

Are you saying that those first two files show up as duplicated because it’s the same content twice in the PR, whereas the third file goes undetected because it duplicates something not in the PR? And that the .tsx files show their duplications even though what they duplicate isn’t in the PR?

 
Thx,
Ann

Hi Ann, thanks! :slight_smile:

Yes, in all these examples I’m duplicating one existing file on the repo, i.e. adding new files.
In these .tsx files, the sonar can identify the duplicity by comparing the new files with the existing ones, as expected. But isn’t happen in .rb files.
The sonar just can only identify duplicity between the files on the same PR, which means, the file duplicates twice it shows duplication code because both are on PR, but the duplicate file (base_copy.rb) doesn’t because on PR there are no files with the same content.
Just to remind you all files used on duplication are already on repo.
To add, I tried to change the “new lines” definition, to force the PR analysis to look for the main branch, but not succeed.
And again just to reinforce, these duplications aren’t identified in PR analysis, but during the Main Analysis, the sonar is able to catch them.

Hi,

Thanks for confirming. To be honest, I’m surprised you’re seeing a language-based difference because I thought duplication detection was handled at the server (mostly language agnostically). Since this doesn’t seem to be the case, I’m going to flag it for the language experts.

 
Ann

Yes, to be honest, I’ve never seen this before too, but just to be sure it’s related to the language I did the same in another Ruby-base project, a small one (<10k LOC) and I’ve got the same behavior

And, Thank you for your response.

1 Like

Hello @Jesus_Lacerda,

Thank you for reporting this issue. I can confirm that Ruby code duplication is not reported before merge, which is inconsistent with the behavior for other languages.

I created a ticket to track the issue.

Cheers,

Dorian