4

I am running sonarqube analysis for one of my java project and it is reporting a lot of violations and majority of the violations reported are for the maximum number of parents a class can have squid:MaximumInheritanceDepth

This class has 6 parents which is greater than 5 authorized

I have more than 100 classes in the project and I do not want to add @SuppressWarning annotation for each of the classes.

Is there a way I can disable this rule for all the Java files in my project?

Prasann
  • 1,263
  • 2
  • 11
  • 18
  • Does this answer your question? [How can we ignore some SonarQube rules in Java?](https://stackoverflow.com/questions/39109228/how-can-we-ignore-some-sonarqube-rules-in-java) – Didier L Dec 29 '22 at 13:44
  • (note that you should look at the accepted answer, not the most voted one) – Didier L Dec 29 '22 at 13:45

1 Answers1

6

One option is to analyze this project with a copy of that profile from which you've removed this rule.

Another is to create a another profile, inherit the rules from your existing profile and update the parameter value on this particular rule, bumping the value to 6 (or 7 or ...)

A third option is to use exclusions to effectively turn that rule off for the files in your project.

Go to Project Administration > General Settings > Analysis Scope > Ignore Issues on Multiple Criteria and fill in the rule key (squid:MaximumInheritanceDepth) and file pattern (**/*.java) and that should do the trick.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Hi @g-ann-sonarsource-team, thank you for your response on this. I cannot really use first 2 options as we don't maintain the sonarqube server and it is centrally controlled. With the 3rd option - I know that with exclusions I can exclude specific types of files, but how do I exclude specific type of rules? Thanks – Prasann Aug 18 '17 at 13:25
  • That's what the 'Rule Key' parameter is for @Prasann - to specify which rule to ignore. – G. Ann - SonarSource Team Aug 18 '17 at 13:38
  • Hi @g-ann-sonarsource-team, Sorry for responding late, I was on holidays for few days and thank you for your reply. Disabling rules from Administration is on the sonarqube server... but I am looking for an option if it is possible from sonar-project.properties or by setting any JVM parameters to ignore rules. Can you please let me know if there is anything that kind? – Prasann Sep 12 '17 at 13:58
  • I don't recommend setting this type of multi-value exclusion via properties, but this can be set via project-level administration. JVM params will do you no good here. – G. Ann - SonarSource Team Sep 12 '17 at 14:18
  • Thanks @g-ann-sonarsource-team. But is there an option to set it from the .properties file at all? – Prasann Sep 12 '17 at 14:27