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.
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.
suppressmessage tag has two attributes,
Note: All text appearing in the
[VBScript] - Copy Code
''' <suppressmessage checkid="CA0105:UseOptionExplicit" />
[VBScript] - Copy Code
''' <suppressmessage checkid="CA0104:AvoidUnusedParameters" messageid="myParamName">This parameter is reserved for future use.</suppressmessage>
Tip: Use the inner text of the
suppressmessagetag 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
< 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
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.
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.