Quickfix of Rule Violations in ST Code
In the Static Analysis Settings dialog, on the Rules tab, you can enable rules for ST code. The compliance of these rules is checked based on precompile information. No explicit call of the static analysis is necessary for detecting any such rule violations. Compliance with the rules is checked in the active ST editor during precompile and after a successful compile. When a rule violation occurs, it is displayed immediately in the ST editor by a wavy underline. Moreover, in the message view, error messages or warnings are listed in the Precompile view.
For instructions, see: Checking for compliance to defined naming conventions
You can find the Quickfix either in the ST editor by clicking the code with the wavy underline and then clicking the light bulb symbol , or in the message view by means of the
button in the error message line. In each case, you are provided with the corresponding commands for handling the rule violation.
For the Quickfix, the following commands are provided, each depending on the error:
Ignore error/warning
The command is used to automatically insert pragmas or attributes into the code, which exclude a check of the corresponding rule for this line of code.
Ignore error/warning globally for <programming object name>
The command is used to automatically insert an attribute at the beginning of the declaration part of the programming object. Then a check of the corresponding rule for this programming object is excluded.
Command with a suggestion on how to change the ST code to avoid the rule violation (Quickfix). Example: SA0168: Remove assignment 'enum1 := 5'
Switch off check
The command is used to disable the check of the corresponding rule in the settings.
Tip
You can undo the effects of calling any of the commands. To do this, first click in the Devices view (or POUs view). Then the Undo command is enabled.
Enabling of rules
Click Rules tab.
. Switch to theA list is displayed containing all possible rule checks. They are organized in a tree structure by topical category. The "rule number" is added in brackets. You can filter the rules, sort them by options, or display them in a list.
Click the Structured display filter (
symbol), and then select the Structured by Moment of Execution option.
The rules that can also be checked during the precompile are listed below the Executed during precompile and after a successful compile node. These are the rules that are identified by a check mark in the Precompile column. In the column on the left, you can now enable the rule for the check.
Click the check box in the line of rule (168) so that the state changes from "red check mark" to "yellow check mark" to "no check mark".
A red check mark means that the rule violation is issued as an error message. A yellow check mark means that the rule violation is issued as a warning. No check mark means that the rule is not checked.
The enabled rules are now checked. In the case of violation, they are marked in the code and displayed in the message view.
Displaying rule violations in the message view
Click
.The message view opens.
In the message view, in the list box, select the Precompile category.
In this category, only the rule violations are displayed, which have been detected during precompile and after a successful compile, and which you can resolve with Quickfix. The
button provides the respective commands for this.
Performing a Quickfix
In the settings, Rule 168 is enabled and a rule violation is displayed in the ST editor.
Requirement: At least one line has a wavy underline in the ST code, and the respective SA number is displayed in the message view.
Click the line of code with the wavy underline.
The
symbol is displayed.
Click the light bulb symbol.
A window with menu commands for error handling opens.
You want to fix the error. Therefore you click the command Assignment 'enum1 := GVL.CONST'.
Now the line of code is changed automatically, as displayed in the command. The error is fixed.
The third command includes a suggestion on how to fix the error by changing the code, depending on the rule violation.
The same error handling is possible by clicking the button in the error message line of the message view.
Disabling the rule check for one line of code
In the settings, Rule 168 is enabled and a rule violation is displayed in the ST editor.
Requirement: At least one line has a wavy underline in the ST code, and the respective SA number is displayed in the message view.
Click the line of code with the wavy underline.
The
symbol is displayed.
Click the light bulb symbol.
A window with menu commands for error handling opens.
You do not want to fix the error. Therefore you click the command Ignore error/warning.
Now the line of code is automatically provided with pragmas. The pragmas are used to prevent the line for the affected rule from being checked. An error message or warning is not issued.
The command to disable the rule check for the affected line of code is also available by means of the button in the error message line in the message view.
Disabling the rule check for one programming object
In the settings, Rule 168 is enabled and a rule violation is displayed in the ST editor.
Requirement: At least one line has a wavy underline in the ST code, and the respective SA number is displayed in the message view.
Click the line of code with the wavy underline.
The
symbol is displayed.
Click the light bulb symbol.
A window with menu commands for error handling opens.
You do not want the programming object to be checked with the specified rule. Therefore you click the second command Ignore error/warning globally for PLC_PRG.
The declaration of the object is now automatically provided with an attribute. The attribute is used to prevent the affected rule from being checked for the object. An error message or warning is not issued.
The command to ignore the message is also available by means of the button in the error message line in the message view.
Disabling the rule check in general
In the settings, Rule 168 is enabled and a rule violation is displayed in the ST editor.
Requirement: At least one line has a wavy underline in the ST code, and the respective SA number is displayed in the message view.
Click the line of code with the wavy underline.
The
symbol is displayed.
Click the light bulb symbol.
A window with menu commands for error handling opens.
You do not want the displayed rule to be checked anymore. Therefore you click the fourth command Switch off check.
The rule is disabled in the Static Analysis Settings.
Click Rules tab.
. Switch to theRule 168 is disabled.
The command to globally disable the check is also available by means of the button in the error message line in the message view.