2

I have installed sonar 2.12. Going to Violations > Major > Cyclomatic Complexity I can see the number of methods with CC over 10, but I need to go method by mehod to see its actual CC. I wonder if there a way to see a list of the methods with most CC?

ejaenv
  • 2,117
  • 1
  • 23
  • 28

3 Answers3

4

There should be a rule to check for methods with high complexity; configure the threshold and run your analisys.

Then use Sonar REST api to query for hits of that rule. The result will include filename, line number and the message will tell you complexity value.

This is the operation you will have to invoke: http://docs.codehaus.org/pages/viewpage.action?pageId=229743298

3

Our tool, SourceMeter has a plug-in for SonarQube that can list the most complex methods. It provides widgets for method level metrics. You can check it out here.

1

With Sonar 2.12, you can customize the dashboard of your project (with admin rights) in order to display the "metric hotspot widget" which you can configure to display the cyclomatic complexity metric. This way, you will see the highest CC of your project.

Read more on how to customize your dashboard.

Sled
  • 18,541
  • 27
  • 119
  • 168
  • Fabrice, I have looked up the metric hotspot widget, but I haven't seen the CC metric, just the complexity/method average metric, which is a different value. – ejaenv Dec 06 '11 at 20:29
  • 2
    Indeed, I forgot to mention that we do not store yet the CC for each method, but only the global CC and the average/method for a file. Maybe one day we'll add info at methdo level, but for the moment this would cause DB volume problems. – Fabrice - SonarSource Team Dec 07 '11 at 09:42
  • @Fabrice-SonarSourceTeam is it still true today, that I cannot get the CC marked for an individual function to immediately see the worst offenders in a class? – Harald Jun 30 '15 at 12:06
  • @Harald Yes, this is still true today. – Fabrice - SonarSource Team Jul 02 '15 at 13:51
  • There is a SourceMeter SonarQube plug-in (https://github.com/FrontEndART/SonarQube-plug-in) which provides class and method levels metrics as well and its customized dashboard is able to list the worst classes and methods. See the online demo: https://sonarqube.sourcemeter.com/ –  Aug 09 '15 at 15:05