Request for Enhancing Code Quality Metrics Analysis in SonarQube

  • We would like to analyze and view code quality linter rule metrics directly in the SonarQube UI [example rules are Classes should not be coupled to too many other classes (Single Responsibility Principle), Classes should not have too many methods], similar to how cognitive complexity and cyclomatic complexity metrics are displayed in the “Measures” tab. This enhancement would provide better visibility and accessibility for code quality metrics with linter rules.

  • Is it possible to create a custom plugin that calculates and displays both custom and predefined code quality rule metrics [example rules are Classes should not be coupled to too many other classes (Single Responsibility Principle), Classes should not have too many methods] in the “Measures” tab? For instance, when we add the Pitest plugin to the SonarQube server, its metrics are seamlessly displayed in the “Measures” tab under mutation analysis, below i have added the sample screenshot of this example. A similar approach for linter rules metrics would be highly beneficial. Kindly let me know the possibilities.

Hey @Vimal_A

I’m not quite sure what you’re asking. Are you trying to define a list of rules (that SonarQube is already executing against your code) and display the sum issue count (of all issues raised for those rules) as a measure?

Yes exactly @Colin , can you please share how to do this?

Storing this data as a measure would be complicated (I’m not sure it’s even possible) since the data about issues raised (and on what rules) isn’t available until after the analysis is computed. I have no examples to share for doing that.

Rather than trying to store this information as a measure, I think you’d be better off creating a custom page where you query the API and display the data however you like.

There are some examples in the sonar-custom-plugin-example repo that should be useful to you.

Thanks for this information @Colin