Duplicate Code Feedback in PR

  • ALM used: GitHub
  • CI system used: n/a, using GitHub actions for feedback
  • Languages of the repository: C#, JS, HTML

Hello!

We have a large codebase that (unfortunately) includes a lot of duplicated code, and I am looking for a specific piece of functionality that I hope Sonarcloud (or Sonarqube) can provide.

I see that Sonarcloud can provide PR feedback to indicate whether a PR creates code duplication. This is good, but it’s not what I’m looking for. I am hoping to be able to indicate on each PR whether it modifies a section of code that was already duplicated before the PR.

In other words, I’m looking for Sonar to provide a proactive “heads up” to say, “It looks like you modified some logic that is identical in 3 other places. You probably want to update those as well (or, even better, consolidate them.)”

Is there a way to configure Sonarcloud or Sonarqube to do this?

Thanks!

Hey @charlie-effectual

For Pull Request Analysis, the calculation of duplication only considers the files changed in the Pull Request. It won’t be until the code is merged that you can be sure you are introducing no duplicate code in the context of your entire codebase.

If this is your concern (please confirm it is!) – I think it’s a valid one, and, I don’t think there’s anything we can do about in the short-term.

Hi Colin, that’s not exactly my concern, but it is similar.

I don’t want to know if I’m introducing duplicated code.

I want to know if I’m modifying code that is already duplicated.

So, if my project has three identical methods, and I modify the body of one of them, I’d like to be notified that the existing unmodified code was already duplicated somewhere else.