Quality Gate failed because Cognitive Complexity

(Jose Antonio Suarez Guerrero) #1

We are using SonarQube 7.1 (build 11001)
In our custom Quality Gate we have the next Metric:

  • Cognitive Complexity is greater than 10(warning) 15(error)

We have no method with Cognitive Complexity greater than 15 but Quality Gate is failing because the aggregated Cognitive Complexity of the whole project is 628

Without Cognitive Complexity metric in the Quality Gate, methods above 15 are included in Critical Issues that is perfect. But I would like to understand what is the meaning of having the metric fail aggregating my whole project with a lot of methods with values under 15 instead of only counting methods above 15.

(G Ann Campbell) #2


First, congrats on having all your methods at 15 and below! :smile:

To your problem, rules are (generally) at the method level and below. Metrics are file level and above. That means it’s not possible to set a Quality Gate condition on a metric related to method-level complexity. By its nature, your QG condition is testing aggregate complexity.

If you really want to make manageable complexity a release requirement (:clap:) then your best bet is to do something like elevate the rule to Blocker level and set a QG condition on Blocker Issues.


(Jose Antonio Suarez Guerrero) #3

Thank you very much Ann.
Based on your feedback, we will remove Cognitive Complexity as a metric in QG and follow your recommendations.

It’s been very helpful, thank you again.

1 Like