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


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/ at master · asyncapi/modelina · GitHub
But rule is still complaining:

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,

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 Just set your sonar.cpd.exclusions parameter there.

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

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 as and it was taken into account.

Let me know if this helps.

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