Test Design StudioGo to Previous Topic: User-Specific RulesGo to Next Topic: Code Metrics

Suppressing Rules

Summary

The static language analysis process can generate several errors or warnings based on the available rules. When a potential issue is brought to your attention, it is up to you to determine if the issue is valid or can safely be ignored.

Suppressing a Rule with XML Comments

Instead of globally suppressing a rule, you should try to address individual instances instead. In the event your code has generated a warning, it is best to suppress the individual instance and document your reasoning. This provides clarity to others consumers of your code about why a particular issue does not apply or can be ignored. Individual suppressions also indicate that you have made a deliberate effort to analyze the issue and have confirmed that it does not apply.

Code analysis rules can be suppressed using XML comments. A special tag called suppressmessage can be applied to a function, sub, property, class, or file-level block of comments. You will enter the tag on the item that most closely matches the location of the warning. For instances, XML comments to suppress warnings about a function parameter will be placed directly on the function's block of comments. Warnings about the use of a variable will be placed on the closest container for that variable. For example, variables in a function are suppressed within the function comments, member variables in a class declaration are suppressed in the class's comments, and script-level warnings are suppressed in the file-level comments.

The suppressmessage tag has two attributes, checkid and messageid.
AttributeDescription
checkid The checkid attribute specifies the ID of the rule being suppressed. This is typically two letters followed by four numbers (i.e. checkid="CA0100", checkid="CA0101" , etc.). Optionally, you may follow the rule ID by a colon and a short description of the rule. This makes the rule easier to understand when viewed by users (i.e. checkid="CA0105:UseOptionExplicit").
Note:   All text appearing in the checkid after the colon (:) is ignored.
[VBScript] - Copy Code
''' <suppressmessage checkid="CA0105:UseOptionExplicit" />
memberid The memberid attribute is only used on certain messages that refer to a specific instance of an item. This is typically used when referring to a named parameter, variable, or member of a class. For instance, to suppress rule CA0104 about a function parameter not being used, you would specify the name of the parameter for the messageid as shown below.
[VBScript] - Copy Code
''' <suppressmessage checkid="CA0104:AvoidUnusedParameters" messageid="myParamName">This parameter is reserved for future use.</suppressmessage>

Tip:   Use the inner text of the suppressmessage tag to document why the particular message is being suppressed.

Hand-typing the various XML suppression tags is possible, but is not necessary with the IntelliSense that is provided when you enter XML comments. After typing the opening < character of an XML comment tag, you are presented with a list of typical entries based on the current context of the editor. If the element for which you are supplying XML comments has any currently reported errors or warnings, a pre-defined entry will be available in the member list that will populate the proper suppressmessage tag for you.

In the member list pictured above, you can see where a pre-defined entry has been provided for rule CA0105. Simply select this entry from the list and the editor will insert the proper XML comment tag and position the caret for you to begin describing the reason for the suppression.

Global Rule Suppression

All rules can be globally turned on or off. This should only be used if you are confident that a particular rule will never impact you. For instance, rule CA0110 is only valid on versions of Unified Functional Testing prior to v10.0, so it is safe to turn this rule off if you are using v10.0 or higher.

Warning:   By ignoring all instances of a rule, you may miss out on valid issues that will impact your automation effort. Try to suppress individual warnings instead by using the XML comment technique described above.

Rules are currently only supported for VBScript and are located under the VBScript options. Display the Options dialog by selecting Tools -> Options from the main menu. Expand Text Editor -> VBScript and then select Code Analysis.

Rules which are checked will be enabled, those that are not checked are disabled.