|How To: Create Analysis Rule with Rule Designer|
This topic describes the steps to create a new analysis rule using the Analysis Rule Designer.
Open SQL Enlight Options dialog and go to the Analysis > Rules tab.
Select an analysis group which will be parent group of the rule
Open group's context menu and use the New -> Batch Rule or New -> Context Only Rule commands
The analysis rule properties can be set in on the Rule > Details tab:
There are several properties which can be configured:
Unique name which to identify the rule. This is a required field that can contain only alphanumeric characters.
The field can be referenced inside the XSLT rule expression using the $v-rulename.
Short message which usually (but not necessarily) is displayed when the rule is triggered.
The field can be referenced inside the XSLT rule expression using the $v-ruledescription.
More detailed description of the rule.
The field is only informational and cannot be referenced inside the rule expression.
Informational field that can contain the author of the rule.
The filed contains the rule severity level and can have one of the following values:
Task and Undefined
The field can be referenced inside the XSLT rule expression using the $v-ruleseverity.
The field determines the scope of the rule – Batch or Context Only.
The analysis rule parameters can be set on the Parameters tab.
A single analysis rule parameter can have none or several predefined values from which the user will be able to choose before executing the Static Code Analysis command.
The Always require parameters to be set check box will make the Analysis Parameters dialog always appear when the rule is applied.
If this option is not checked, the default values of the parameters will be used.
Refer to Analysis Rule topic to learn more about the analysis rule expression.
The editor at the Expression tab can be used to enter and edit the rule's XSLT expression.
Use the toolbar buttons to edit, format and validate the XSLT expression.
Any XML or XSLT errors messages found during expression validation will be displayed in the Error List and the error will be marked inside the analysis rule expression.
The Test Analysis Context tab contains the context XML which is used for testing the analysis rule.
The toolbar also contains a XPlath test field which can be used to test XPath expressions against the loaded context and see the results in the Errors List.
The connection to the default Analysis Context which to be used for rule testing can be set on the SQL Enlight -> Options menu, an on the Analysis -> Options -> Context tab:
This connection will be used by default in the Analysis Rule Designer to load the context when testing the rule.
The setting can be overridden and the connection can be changed in the designer with the Connection... button located on the Test Analysis Context tab toolbar.
Use the XML Tree tab to examine the Analysis Context and also generate sample XPath expression to the selected node.
Analysis context can be accessed inside the rule expression using the $context variable.
The current context database can be accessed with the $database variable.
1<xsl:value-of select="$context/Database/Tables/Table/@Name"/> 2<xsl:value-of select="$database/Tables/Table/@Name"/>
Refer to the Analysis Context topic to learn more.
When creating an analysis rule you can test the rule expression it against real T-SQL script and see whether it gives expected result.
You can also use the XML view of the T-SQL script to examine the script's SQML and test XPath expressions.
The test script is saved with the rule and can be reused is loaded when the rule is opened in the designer.
Use the Test Rule button to run the analysis rule over the test SQL script and see if the rule is evaluating correctly.
Rule expression debugging is not supported by the Analysis Rule Designer and is only possible when the rule is implemented as a project using Visual Studio.
See How To: Create Analysis Rule with Visual Studio topic for more information.