Plugins

CodeCheck Scripts


Overview

CodeCheck scripts are special Perl scripts that let you provide custom checks for verifying your team's coding standards. They can be used to verify naming guidelines, metric requirements, published best practices, or any other rules or conventions that are important for your team.

These scripts are developed using the Understand Perl API along with a set of special functions designed to interact with the Understand CodeCheck interface.

Installation

CodeCheck script files have a .upl extension and can be installed in Understand by dragging and dropping the script file into the GUI. Alternatively the scripts can be placed in the Understand installation directory under conf\plugin\User\Codecheck

Write Your First Custom Check

To write your own check, start with this template file
codecheck_template.upl(right click, save as)

Save the template file to the Understand installation directory under conf/plugin/User/codecheck/myscript.upl and open the file in a text Editor or in Understand

Modify the name, description and detailed_description subroutines to reflect our test:

sub name { return "Files start with Letters";}

sub description { return "Verify that all files start with a letter.";}

sub detailed_description { return "Company coding standards specify that ". 
                                  "file names should start with letters.";}

Now modify the check subroutine to include the regular expression check and to signal a codecheck violation reporting the problem. Add this code at the end of the subroutine:

if ($file->name =~ /^[^a-zA-Z]/){
  $check->violation(0,$file,-1,-1,"File name does not begin with a letter");  
}

The last step is to verify that the perl syntax is correct. The easist way to do this is to open a command line and run the perl application that ships with Understand: uperl -c mysample.upl.
If needed, you can download the complete sample script here - myscript.upl.

If the CodeCheck tab is open in Understand close it and reopen it, and your new check should appear and be ready to test.

Congratulations! You wrote your first Codecheck script. The next step is to become more familiar with Understand's Perl API. Browsing the Codecheck scripts that are shipped with Understand can also be very beneficial. They can be found in conf/plugin/Codecheck. If you have questions, the SciTool's Forum can be a great place to ask them.
Good Luck!