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?

2
  • Does this answer your question? How can we ignore some SonarQube rules in Java? Commented Dec 29, 2022 at 13:44
  • (note that you should look at the accepted answer, not the most voted one) Commented Dec 29, 2022 at 13:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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
That's what the 'Rule Key' parameter is for @Prasann - to specify which rule to ignore.
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?
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.
Thanks @g-ann-sonarsource-team. But is there an option to set it from the .properties file at all?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.