how to list methods with most cyclomatic complexit

2019-07-16 13:13发布

问题:

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?

回答1:

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.



回答2:

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:

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.



标签: sonarqube