Sonar -LOC & Cyclomatic complexity

送分小仙女□ 提交于 2020-01-15 09:28:46

问题


How does Sonar calculates software metrics particularly LOC and cyclomatic complexity? Does it uses any particular tools? IF yes, please also give the names.


回答1:


For each supported language, a "squid" plugin is used to parse the source code and determine some base metrics such as LOC and complexity. How the complexity is calculated varies based on the plugin.

For example, here's the source code files for the JavaScript plugin: https://github.com/SonarCommunity/sonar-javascript/tree/master/javascript-squid/src/main/java/org/sonar/javascript/metrics In this case, the complexity is calculated in the plugin itself using a very simple formula.

And here is the same set of classes for the C# support: https://github.com/SonarCommunity/sonar-dotnet/tree/master/sonar/csharp/sonar-csharp-squid/csharp-squid/src/main/java/com/sonar/csharp/squid/metric

The creation of metrics, though, can be done by any plugin, so you could write your own plugin if you wanted to supplement the data, or display the data in a different way.

Also take a look at the answer to this question (about creating a new plugin) by Fabrice, one of the .Net plugin maintainers: SonarQube - help in creating a new language plugin




回答2:


You can browse http://docs.codehaus.org/display/SONAR/Metric+definitions for more details.



来源:https://stackoverflow.com/questions/19178315/sonar-loc-cyclomatic-complexity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!