How to ignore code duplication rule for certain files and dirs without using UI

Hey,

We need help turning of code duplication rule for certain files, but we need it to work through file config in a repo, and that it works on PR. How to do that?

Example repo: GitHub - asyncapi/modelina: Library for generating data models based on inputs such as AsyncAPI or JSO
We have this file already modelina/sonar-project.properties at master · asyncapi/modelina · GitHub
But rule is still complaining: https://sonarcloud.io/component_measures?id=asyncapi_generator-model-sdk&metric=duplicated_blocks&view=list

It is pretty frustrating and on many repositories. The only way to ignore atm is to do it directly in the UI but that approach is not good and a bottleneck for the organization.

Please help,
Lukasz

Greeting @derberg
and welcome to the SonarSource community!

As per SonarCloud Analysis Parameters documentation page:

Most of the property keys shown in the interface at both global and project levels can also be set as analysis parameters.

From there you should be able to exclude project files from duplication either at command line level (with your pipeline definition file if you have any) or through your analyzed repository sonar-project.properties. Just set your sonar.cpd.exclusions parameter there.

Important:
In case your project analysis is automated, the properties file is you may use should be .sonarcloud.properties

And in fact I reproduced your case

  • a ‘regular’ scanner analysis of your project (thanks for sharing) did pick up the parameter well enough,
  • then I forced automatic analysis on the project and it was ignored
  • last I just copied your sonar-project.properties as .sonarcloud.properties and it was taken into account.

Let me know if this helps.
Sylvain

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.