The rule to check do for statements in the code contains or not some
expressions. Checked things:
- Empty statements.
Forstatements, which contains onlydiscardstatement. - Do
forstatements explicitly calls iteratorspairsoritems.
The syntax in a configuration file is:
[ruleType] ?not? forStatements [checkType]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a
forstatement which violates the check. Search type will list all statements which violates the check or raise an error if nothing found. Count type will simply list the amount of the statements which violates the check. Fix type will try to fix the code which violates check. The negation of fix type doesn't work with checkType set to "empty". - optional word not means negation for the rule. Adding word not will
change to inform only about the
forstatements which not violates the rule's check. - forStatements is the name of the rule. It is case-insensitive, thus it can be set as forstatements, forStatements or fOrStAtEmEnTs.
- checkType is the type of checks to perform on the
forstatements. Proper values are: all, iterators, empty. Setting it to all will perform all rule's checks on statements. Iterators value will check only if theforstatements usepairsanditemsiterators. Empty value will check if theforstatements doesn't contain only adiscardstatement.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "forStatements" in the code before it. For example, if the rule should be disabled for the selected statement, the full declaration of it should be:
{.ruleOff: "forStatements".}
for i in 1 .. 5:
echo i
To enable the rule again, the pragma ruleOn: "forStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:
{.ruleOn: "forStatements".}
for i in 1 .. 5:
echo i
Examples
Check if all
forstatements have direct calls for iterators::check forStatements iteratorsRemove all empty
forstatements::fix not forStatements empty