Cannot ignore specific code duplication (only option is to turn off the check?)

Hi, we have started using the SonarCloud service recently and are still tweaking the settings to make sure how to get the most out of the analysis without blocking our work too much. So far pretty good but still things pop up here and there that are really annoying.

This case is regarding code duplication. Overall I think it’s a great idea to have an option to prevent our PRs from being merged before code duplications are solved. However, sometimes code duplication are acceptable and even desirable. Below is a case like so. Its two data models that happen to share the same first part of the file in look, even though the tableName does differ.

See screenshots below.

My suggestion (if there are no good existing solution to this problem) would be to make this an issue that can be ignored, just like most of the other problems the analysis finds out.
Please tell me you have an even better way to solve this problem, without us having to turn off the Merge blocker in BB for having code duplication.

Details:

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Cloud
  • Languages: JavaScript (Node)
  • Potential workaround: Turn of the blocking feature

PS
Why preventing new users from uploading multiple images, that just makes me spend more time having to arrange one screenshot of two windows (like above)?
DS

Best regards,
Marcus Bergman

1 Like

Have you looked at this guidance?
https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/#ignore-duplications

1 Like

Hi @dp-bergman, and welcome to our community! :slight_smile:

I understand your case, and here are some ways to get around such situation which might happen from time to time:

  • like @jamesrgregg said, you can exclude these files from the duplication detection in the project settings
    • And once the PR is merged, you might want to remove this exclusion
  • you can also relax the % of code duplication authorized on the quality gate you are using for your project
    • And again here, you might want to set it back to its previous value once the PR is merged
  • I don’t know how that works on BB, but maybe there is a way for project admins to force the merge even when some checks are failed (this is possible on GitHub for instance). This allows teams to overcome edge-case situations like this.

As you said, managing duplication through issues would be a solution to “properly” handle such situation. This is something we’ve already talked in the past but there was not enough traction to move forward.

1 Like

Is it possible to have different % ratios for different set of files (like ‘.test.js’ have one percentage and the rest of '.js’ have another)?

It’s possible to have BB not requiring passes but that makes it easy to just go for “merge” without realising something is afoot.

–M

I’m afraid that this is not possible.