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.

A simple rules-based style check (simpleStyleCheck) is included with the plug-in.

Configuration

Viewing the Rules

The operation of this tool is controlled through the use of simple rules that are stored in a text file located in the same folder as the primary class used to implement the style check.

info A secondary rule file can be created in the folder specified by the preference 'Contributed Extensions / Tools: Directory for user-defined observers' with the same name as the primary class for the style check. When this file exists, any new or modified rules will be saved to this file; the rules in this file will be added to the list of existing (standard) rules for the style check.

The name of the style check class will be displayed in parenthesis after the description of the plug-in on the 'Contributed Extensions / Tools' preference page once the plug-in has started.

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 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 rule violations will be flagged with the first rule that fails rather than all rules that might apply. The position of a rule in the list can be adjusted by pressing move up to move the rule up, or move down to move the rule down.
Automatically update source code for the rules that contain replacement or delete values
When the Style Check is executed from the "Contributed Tool" menu, this option will control whether the replacement and delete values are updated to each source file as it is processed.
Escalate a 'warning' to an 'error' when rule includes a replacement or delete value
When the Style Check is executed from the "Contributed Tool" menu and the automatic update is not enabled, this option will control whether a rule that is defined as a "Warning" and includes a replacement or delete value will get reported as an "Error".

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
The options control how and when a rule will be applied.
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 Remarks
Locate the text inside remarks; if not checked, the search will ignore comments
Delete Search Value
The search value will be deleted when the Style Check is executed as a contributed tool and the "Automatic update" option is set
ProvideX Class Only
The rule will be applied to the source files for ProvideX classes only (files with ".pvc" extensions)
Check Literals
Locate the text inside literal values; if not checked, the search will ignore string literals
Search First 10 Lines
Rule is restricted to the first 10 lines of the source file.
Log Text After Tag
Locate the search text and using the remainder of the program line as the description of the warning/error to be logged.
Check Keywords
Locate search text in list of keywords for the line; if search value contains multiple words, will check any order of the words
Replacement Value
The replacement value can be either a simple text value (20 characters) or a string expression that will be evaluated at run-time.
String Expression
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 class based on the simple style check class. This class has been provided as an example that uses a text file to define the rules describing the coding style.

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.