We have seen in our previous post how to analyze Cobol code with Sonar and Jenkins.
But in fact we have not used all the existing Cobol rules. Why? Some rules are disabled because they are specific to a particular context and then require some setup. For example, naming rules are not standardized in Cobol, and will often be different between different departments or even between teams from the same department.
So we need to manage different Quality models corresponding to different set of rules, depending on the project. Sonar gives us that opportunity, thanks to the ‘Quality profiles’ which include active rules during a code analysis.
We will see in this post, how to create a new profile with all the Cobol rules, and assign it to an existing project.
Create a new Quality profile
Our objective is to examine all the existing Cobol rules, so we’ll start by creating a Quality profile with all these rules. To do this:
- Connect as an Admin.
- In ‘Configuration’, the first screen lists all the existing Quality profiles. We can see that the profile ‘Sonar Way’ has 34 active rules.
- Create a new profile by copying (button ‘Copy’) the profile ‘Sonar Way’.
- Name the new profile: ‘Complete Sonar Cobol’, for example. It now appears in the list of ‘Cobol profiles’.
Manage the rules of a Quality profile
We want to use all existing Cobol rules when performing some analysis, to check and comment on these Cobol ‘best practices’. To do this:
- Select the new profile: the page ‘Coding rules’ lists the 34 active rules.
- Select ‘Inactive’ in the list-box ‘Status’ and activate the button ‘Search’ : 51 inactive rules are displayed.
- Back in the screen ‘Quality Profiles’ you can set this new profile as default.
Similarly, you can change the settings of certain rules. For example, the Cyclomatic Complexity threshold for a complex Cobol program.
Assign a Quality profile to a project
This new profile will be activated for any new project. But what about existing projects? They have been analyzed with the profile ‘Sonar way’.
Now to use the new profile we have created, we must go to the tab ‘Projects’ in the page ‘Quality profiles’ and associate existing projects to the new profile.
We have seen in this post how to create a Quality profile corresponding to a specific quality model of different rules, their level of severity or their settings. It is therefore possible to manage different profiles according to different quality standards for different teams or applications.
If you analyze again your projects with all the Cobol rules activated, you will of course see a sharp increase in the number of violations. To be continued, in our next post.