Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can SonarQube code duplication detector be parameterized to stop on method boundaries?

I’m using SonarQube on my Java projects, and want to eliminate code duplications from our code as far as possible.

My problem is that SonarQube’s code duplication detection doesn’t take into account method boundaries. It lists identical parts of files as duplications, and it often happens that a duplication starts in the middle of a method and ends in the middle of another. These can hardly be refactored.

Here is an example. Click on file MavenArtifactRepository.java in the upper right list box, and take a look at the 4th duplication block in the lower part of the page.

Is there any way to parameterize the code duplication detector plug-in to show duplications, which are syntactically coherent?

like image 869
f.r Avatar asked May 05 '14 16:05

f.r


People also ask

How do I ignore duplicate lines in SonarQube?

To do so, you can either ignore files in the SonarQube UI under General Settings > Analysis Scope > Duplications using e.g. **/*. html , or make this restriction directly in your sonar-project. properties using the sonar.

How do you stop the problem in SonarQube?

For most languages, SonarQube supports the use of the generic mechanism: //NOSONAR at the end of the line of the issue. This will suppress all issues - now and in the future - that might be raised on the line.


1 Answers

Currently you cannot achieve that by configuring SonarQube itself. However, you can try our tool, SourceMeter with its SonarQube plug-in, which implements an AST based clone detection and therefore it presents syntactically coherent duplications inside SonarQube. For an example, you may take a look at the online demo.

like image 87
Tibor Bakota - FrontEndART Avatar answered Sep 28 '22 12:09

Tibor Bakota - FrontEndART