Moving from MZ-Tools 3.0 to 8.0 Part 9: The Programming Rules Review

The Programming Rules Review is also new in MZ-Tools 8.0 and allows you to define custom rules such as:

  • If a ListView has the View property with the lvwReport value, it must have the FullRowSelect property with the True value.
  • The DAO reference is forbidden.
  • The Microsoft ActiveX Data Objects reference is mandatory for ActiveX Dll projects, and its version must be 2.6.
  • A method cannot have more than 10 parameters.
  • The BackColor property of forms must be &H8000000F&.
  • The Height property of the Command controls must be 3600.
  • Code files must contain the Option Explicit statement.
  • The code of a method cannot contain a “forbidden” statement such as GoTo.
  • A method cannot have more than 500 lines of code.
  • Etc.

You get the idea, don’t you? The Programming Rules Review is part of the Quality Review feature:

ProgrammingRulesReview

The programming rules are created, customized and enabled/disabled in the corresponding section of the “Options” window, “Team Options” tab, “Quality Review” > “Programming Rules Review” node:

You create a programming rule in this window:

ProgrammingRuleAs you can see, after an (optional) Id for the programming rule and a description, the first important thing is the item to review, which can be any object or a collection of objects, from the IDE to a parameter of a method:

ProgrammingRuleItemToReviewIf you select an item to review that is an object, then you can define a condition that must meet that object. The condition uses a property of that object, and operator, and a value or set of values:

ProgrammingRuleObjectIf you select an item to review that is a collection, then you can create two kinds of programming rules. The first kind is a condition about the number of items of the collection:

ProgrammingRuleCollectionCountThe second kind is about the existence of at least one item in the collection that must meet some conditions:

ProgrammingRuleCollectionItemConditionEach condition that must be met by some item of the collection is created in this editor:

ProgrammingRuleCollectionItemConditionEditorApart from the “What to review” tab, there are another two tabs. The second tab sets when to review the item. If you don’t set conditions, the item is always reviewed. But for example, you may want to review something only when its project is Standard Exe, but not when it is an ActiveX dll:

ProgrammingRuleWhenToReviewSo, you can define conditions that are combined, and each condition is composed of a property, and operator and a value or set of values:

ProgrammingRuleWhenConditionEditorThe third and last tab is to enter some explanation of the review, and how to fix it:

ProgrammingRuleExplanationWhen the Programming Rules Review finds violations of some programming rule, it shows them in the Results toolwindow:

ProgrammingRulesReviewResultsEach result has a context menu where you can locate the result, remove it from the list, or view the rule that has been violated:

ProgrammingRuleViewThe following window is shown with the Id, description and suggested fix (if entered when creating the rule). To view the full programming rule definition you can click the “View Rule” button:

ProgrammingRuleViolatedSo, the Programming Rules Review allows you to create rules for almost any validation that you want to perform, and it is a powerful tool to ensure that quality rules that are defined by a team lead are enforced. The setup installs some programming rules as samples to get started.