Validation expressions
Required role | Rule Management |
Access | CodeChecker Server → Rules Configuration → Validation Expressions |
Validation expressions are logical conditions used in the definition of a quality rule. During the code analysis, the validation expression is compared with the metric also defined in the quality rule to return a boolean value (true or false). The result of this comparison determines if the quality rule succeeds or fails.
ARCAD CodeChecker comes with a set of standard validation expressions that are designed to cover most needs. ARCAD CodeChecker also makes it possible to create specific validation expressions if needed.
You want to create a quality rule to make sure Until statements are not used in a source code.
The validation expression Metric value is equal to uses a parameter to set the expected value for a metric. You will use this validation expression in the quality rule, and set the expected value to 0.
After the execution of the quality rule, if the metric value is 0, then the quality rule succeeds. However, if the metric value is different from 0, the quality rule fails because the metric value is not equal to 0, as the validation expression requires.
For more information about quality rules, refer to Quality rules.
For more information about metrics, refer to Metrics.
The Validation Expressions search view is accessed from the Configuration node in the Navigator.
The standard validation expressions are highlighted to be easily identified.
Enter any combination of the above search criteria, then click the Search button to display the results. To display the complete list, click the Search button without entering any search criteria.
Follow the subsequent steps to create a new validation expression.
Step 1 To access the Create Validation Expression wizard, either click the Create icon in the toolbar of the Validation Expressions search view, or right-click anywhere in the list of the view and select Create Validation Expression.
Step 2 Define the validation expression's Code, Name and Description. These values are required. The Code cannot be changed once the validation expression is created, but the Name and Description can be edited later.
Click Finish.
Result The new validation expression is created and its editor opens automatically. It is displayed in the Validation Expressions search view.
It is required to edit new validation expressions before using them.
To open a validation expression's editor, locate the it in the Validation Expressions search view, then either:
- double-click on the item in the view,
- right-click on the item in the view and select Edit, or
- select the item in the view and click the Edit icon in the toolbar.
Save the changes (, Ctrl+S
or File > Save).
- Code
- This field displays the validation expression's unique ID defined when creating the validation expression. Once an expression is created, it is not possible to edit this code.
- Name
- The validation expression's name should reflect the logical condition defined for the metric comparison to be easily identified.
- Description
- Use this description to give as many details as possible about the logical condition that should be compared with the metric when this validation expression is used.
Define the logical formula of the validation expression. Use parameters if needed.
This section helps you manage the parameters included in the validation expression's script. The values of these parameters are defined in a quality rule.
Follow the subsequent steps to create a new parameter.
Step 1 To open the New Validation Expression Parameter dialog, click Create.
Step 2 Define a Parameter ID for the new parameter. This ID is used to identify the parameter in the validation expression's script.
Step 3 Select the Type of the value from the drop-down list. This value is entered when the quality rules using the validation expression are defined.
Step 4 Enter a detailed Description of the parameter. Use this description to give as many details as possible about the value that should be entered when defining a quality rule, depending on the rule's context.
Click OK.
Result The new parameter is created and is displayed in the Parameters section in the validation expression's editor.
To edit a parameter, either double-click on it, or select it and click Edit. Click OK to save any changes made or Cancel to keep the parameter unchanged.
To delete a parameter, select it and click Delete. Click Yes to confirm or No to keep the parameter.
Deleted validation expressions cannot be accessed or recovered.
You cannot delete expressions that are currently being called by one or more quality rules. You must first delete all of the rules that employ it before deleting the expression.
Standard validation expressions cannot be deleted.
To delete a validation expression, either right-click on it in the Validation Expressions search view and select Delete, or select it and click the Delete icon in the toolbar. Click OK to confirm or click Cancel to keep the validation expression.