I’m charge to evaluate some codemetrics tools for making the suitable election of them for some projects of our company.
Reading the SonarQube’s documentation, I didn’t clearly find a place where the following metrics at function level are included and the explanation of how to calculate and report them:
- Cyclomatic Complexity (McCabe complexity) at function level.
- Number of sentences / LoC by each function.
- % of comments per function.
Please, can anyone explain us if SonarQube calculates these metrics and how to find a report of them?
Welcome to the community!
We don’t store / report on method-level metrics.
If you reeeally have to have this, then there’s a very painful way to get it. What you can do is turn on the relevant rules (Methods should not be too complex, Methods should not have too many lines of code, …) and set all their thresholds to 0. I would suggest you activate these rules with an Info severity, because this is going to be suuuper noisy. Then you’ll have the count of each thing for each method in the issue message. Unfortunately, you’ll have to parse the issue messages to get your counts.
Thank you very much for the reply.
We need a kind of summary of what method or function is breaching the threshold allowed for a metric.
An example would be: we want to know all the functions that contain a percentage of comments below 20%.
Another example would be: we want to know all the functions that have more than 150 LoC.
Could that be achieved by setting specific rules?
And it would serve us with an output in the form of a table where the file, the function and its value are identified.
Could that simple output be available?
If you’re looking for methods that cross thresholds, then the rules are exactly what you need. Just activate them with your desired thresholds. An issue will be raised when (and only when) a method crosses the threshold. You can then use web services to extract issue data. Each issue will identify the component (file), line, and the segment of the line involved. You won’t get method names directly from that, but you’ll be able to figure it out easily. From there, you can build the tables you want.
Really we need to know the exact method (or function) that violates the thresholds. The approach mentioned is useful for developers, but for management level and for delivering to Customers, we need to know the method with out-of-limits values.
Is possible to find in any easy way to obtain this information in a table form?
I wait for your answer.
I’ve already laid out above everything I’ve got.
Good morning, Ann
Thanks for all the information, for your time and for your kindness.
Manuel A. Lea