Code Duplication for New Language

  • SonarQube 6.7.6 (build 38781) LTS

I created a new language and a plugin for Sonarqube. I am trying to find the duplicated code and duplicated lines. I am using Python plugin as a reference. I looked at the Python plugin code however I couldn’t find anything related to the code duplication calculation. From the documentation for duplicated_blocks, it says:

  • Non-Java projects:
    • There should be at least 100 successive and duplicated tokens.
      • 10 lines of code for other languages

Therefore, I understood that it should find the duplicated code automatically if these rules apply. However, when I tested my source code it couldn’t find the duplicated code for my new language. So what should I do to calculate duplicated code for my new language plugin?

Hi!

The code duplication is calculated by SonarQube itself using the “copy-paste detection tokens” (NewCpdTokens) provided by the plugin.

In sonar-python this data comes from the PythonCpdAnalyzer class.

4 Likes