In this section:

What is a Rule?

In RuleWizard, a rule is a graphical representation of a pattern that you want to identify—typically a pattern that signifies an error, an error-prone coding construct, or a coding construct that you want to identify automatically and review manually. Custom rules can verify unique project and organizational requirements as well as prevent the team's most common errors from recurring.

When you create a rule, your goal is to graphically express the pattern that you want to search for and identify. When Parasoft static analysis checks a rule, it searches for instances where the specified pattern occurs, then flags any violations that it finds. 

RuleWizard rules are generally comprised of the following elements:

NodesThe basic building blocks of rules. They can be expressions, variables, constants, functions, or statements. The nodes available for rule construction are displayed in the dictionary tabs, which open in the left side of the GUI.
CommandsProgramming elements or concepts about the node, and/or conditions between nodes. Right-clicking on a node in the right panel opens a shortcut menu that displays the commands available for that particular node. Commands can also consist of collectors and set operators between sets of nodes, and commands can be used to add scripting for additional customization.
OutputThe message that is reported each time a violation occurs. When constructing the rule, output is represented in the right panel with a short arrow pointing down. Outputs can use scripting for additional customization.
PropertiesThe properties of the rule, including the author, Header, Rule ID, and description.

A basic rule consists of only a parent node, output, and properties. More complex rules consist of a parent node, nodes with commands or sets of conditions between those nodes, output, and properties. Rules can be as simple as looking for an assignment (=) within an IF statement when it should be equals (==), or as complex as eliminating unused private member variables.

Nodes

In general, there are two types of nodes:

  • Parent nodes. The parent node is the main node for a rule, or its subject. Parent nodes can expressions, variables, constants, functions, or statements.
  • Child nodes. These nodes pertain to programming elements and concepts and are used to define and add conditions to the rule. Child nodes are referred to in this manual as Node Properties.

Parent nodes appear in the New File panel and in the left-side of the RuleWizard GUI. Available nodes depend on which node dictionary is in use. 

Each node has commands associated with it. Available commands vary by node.You can access the commands for a particular node by right-clicking that node.

Commands

Commands define the conditions of nodes and the relationships between nodes. They are based on programming elements or concepts. To view the commands available for a given node, right-click the node in the right panel of the RuleWizard GUI. A shortcut menu opens that displays the commands available for that particular node. RuleWizard commands are displayed at the top of the shortcut menu; node properties (child nodes) that pertain to programming elements and concepts are displayed beneath the commands.

Commands can also consist of collectors and set operators between sets of nodes. Collectors and set operators are elaborate conditions that use counters. Counters count the number of instances a particular pattern occurs within the code. Collectors let you restrict a node or node set’s quantity by counting the number of occurrences in the code. Set operators let you specify a relationship between two or more set components using logic rules such as UNION, INTERSECTION, DIFFERENCE, and XOR.

Commands can also be used to add scripting for additional rule customization.

Output

The rule output is what appears in results and reports when a violation of this rule is detected. Output can be a simple message that a certain condition was found. Or it can specifically refer to a variable or report the count. When constructing the rule, output is represented in the right panel with a short arrow pointing down.

Outputs can use scripting for additional customization.

Properties

The properties of the rule indicate such information as the rule ID, header (name), author, severity, and description. All of these fields except Header are optional. A rule cannot be saved unless a Header and Rule ID have been properly defined.

Do not confuse rule properties with node properties (child nodes)

Rule properties help to categorize a rule (author, ID, severity, and so on), while node properties are the set of commands or conditions within the rule itself.

A very basic rule consists of only a parent node, output, and rule properties. More complex rules consist of a parent node, nodes with commands or sets of conditions between those nodes, output, and rule properties. Rules can be as simple as looking for an assignment (=) within an IF statement when it should be equals (==), or as complex as eliminating unused private member variables.

  • No labels