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
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.
@jamesrgregg or @Fabrice_Bellingard - Do you have another link that covers this topic of duplication, and how to disable/configure per file or per project?
Another +1 - It would be great to ignore a duplicated block or line or mark it as not an issue.
We’ve been struggling with this issue. While code duplication is important to avoid it seems crazy to apply it to such short snippets (when pulling them out into a separate function would require almost as many duplicated characters to call)
Hi! Is there a way to ignore blocks of code marked with a specific annotation rather than using start/end comments as explained here?
I’m already marking generated code with @Generated and more comments would be redundant. At the same time, I don’t want to ignore entire files only to suppress duplicate warnings in some legit parts.