Custom rule builder

The core code review and quality control engine analyses PL/SQL code against over 180 standardised code review rules and allows creating custom requirements in XPath.

Follow this guide to create custom rules for code analysis.
To create a custom code review rule, the user should be familiar with the XML Path Language (XPath). To learn the XPath syntax, refer to the external resources msdn.microsoft.com and www.w3schools.com.
Let's consider the following example:
  • Use case
    The package SOME_CUSTOMER_DEPRECATED_PACKAGE has been deprecated.
    Task
    Make sure the package SOME_CUSTOMER_DEPRECATED_PACKAGE is no longer used in the code.
Solution:
1
Go to Options > Code Analyzer Options > Code Review Options, and click Add New. The Code Review Rule Editor will open.
2
Enter the code review name.
For example: Avoid use of SOME_CUSTOMER_DEPRECATED_PACKAGE package.
3
Select a severity level — Major, category — Maintainability, code element — PL/SQL.
4
On the Rationale subtab, enter a short description of the rule's usage.
For example:

<h4>Reasoning:</h4>
<p>The company has deprecated the SOME_CUSTOMER_DEPRECATED_PACKAGE package. 
Do not use this package.</p>

5
Switch to the XPath Expressions and Code Sample tab.
6
Enter an XPath expression:

//subprogram_call[compound_name[@identifier = 'SOME_CUSTOMER_DEPRECATED_PACKAGE']]

7
Enter a code sample to check how the rule works in practice:

/*
** SOME_CUSTOMER_DEPRECATED_PACKAGE should not be used any longer!
*/
BEGIN
   SOME_CUSTOMER_DEPRECATED_PACKAGE.ANY_SUBPROGRAM();
END;
/


XML source code will be created automatically once the code sample is ready.
8
Click a big green arrow or press F9 to run the XPath expression. Query results will be shown below, including the detected violation(s).
Code Review Rule Editor
Fig 1 - Code Review Rule Editor
9
Click OK to save the rule and close the window. Get back to the main page, and re-run a project analysis to apply the rule.
Want to share your code review rules with the team? Save them to PDF:

  1. Use Ctrl+Click to select rules you would like to save to a PDF-file.
  2. Click Print Preview on the pop-up menu of the Code Review Options page.
  3. Click Save to PDF in the print preview dialog box.
This document was last updated on February 20, 2020
Helpful?