Style Check

What is it?

The Style Check contributed tool provides a mechanism for defining simple rules to describe a coding standard. The tool will then use these rules to verify that the source code for an application conforms to the defined standards. These rules are processed in order, and the first rule that fails will be recorded to the "Problem View" and the remaining rules will be skipped.

Configuration

Viewing the Rules

The operation of this tool is controlled through the use of simple rules that are stored in a simple text file. The rules can be viewed in the configuration screen for this tool (see image below - click to view a larger image).

Style Check configuration (Click to view larger image)

Order of Rules

The coding standard rules are processed in order, from first to last. The first rule that fails will be tagged against the line in the "Problem View" and all remaining rules will be skipped. As a result of this processing method, any program line that has multiple coding standard violations will be flagged with the first rule that fails rather than all rules that might apply.

Add a Rule

A new rule can be created by pressing the [Add] button on the screen that displays the list of rules.

Add a new rule (Click to view larger image)

The information associated with a rule is:

Rule Description
A short description for this rule that will be placed in the "Problem View" when there is a violation.
Search Value
The text value (20 characters) to locate within the program line.
Level of Severity
The severity to be assigned to a violation of this rule (E=Error, W=Warning)

Options:
Mandatory
This rule is mandatory and cannot be disabled by a user
Enabled
The current state of the rule when the user is allowed to enable/disable it
Ignore with *SC-OK*
A violation of this rule will be ignored if there is a comment on the same program line that contains the text " *SC-OK* "
Whole Word
The search value will be treated as a word for the search; this means that there must be a space before the search value and a space or ...
Check REM / Literals
Locate the text inside remarks or literal values; if not checked, the search will ignore any comments and string literals
Delete Search Value


Replacement Value:
String Expression
The replacement value can be either a simple text value (20 characters) or a string expression that will be evaluated at run-time. This check box determines the type of replacement value to be used for this rule.
Fixed Text
A simple text value (20 characters) to replace all occurrences of the search text on a program line
String Expression
A string expression to be evaluated to create the replacement text value


Edit a Rule

Any existing rule can be modified by pressing the [Edit] button on the screen that displays the list of rules.

Edit existing rule (Click to view larger image)

The string expression is validated for correctness; update of the rule cannot occur until the expression is valid.

Edit existing rule (Click to view larger image)

Delete a Rule

Any existing rule can be deleted by pressing the [Delete] button on the screen that displays the list of rules.

Execution of Style Check

During SAVE in Editor

The external tools must be enabled on the "Contributed Tools / Extensions" preference page. The Style Check can then be enabled as an observer and will be triggered when a file is saved in the editor. When the style check is executed as part of the save process, all rule violations will be updated to the "Problems View" but no modifications will be made to the source files.

As Contributed Tool

When the style check is executed from the 'Contributed Tools' menu, any rule that includes a replacement text value, or option to delete the search value will be applied to the source file. Any remaining rule violations will be updated to the "Problems View".

Developer-Defined Style Check Class

Developer - Style Check

A developer who wants to implement a style check (or coding style validation mechanism) as part of the standard application development process must create a simple class based on the generic style check class. The generic style check class has been provided as a simple example that uses a simple text file to define the rules describing the coding style. There is no additional code in the class - it is simply a clone of the standard class that is included with the plug-in. The documentation for this class can be accessed through the link.

The source code for the class can be viewed by clicking on the link.

Style Check

The plug-in includes a standard class that is loosely based on the "Prototype" design pattern. This class defines the characteristics of a style check capability that can be implemented by a developer. The standard capabilities of the style check feature are implemented in this standard class. A developer can extend these methods or add specialized logic to implement rules that cannot be easily described using search patterns.

The documentation for the standard class can be accessed through the online help for the plug-on or by clicking on the link.