The rule to check do for
statements in the code contains or not some
expressions. Checked things:
- Empty statements.
For
statements, which contains onlydiscard
statement. - Do
for
statements explicitly calls iteratorspairs
oritems
.
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
for
statement 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
for
statements 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
for
statements. Proper values are: all, iterators, empty. Setting it to all will perform all rule's checks on statements. Iterators value will check only if thefor
statements usepairs
anditems
iterators. Empty value will check if thefor
statements doesn't contain only adiscard
statement.
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
for
statements have direct calls for iterators::check forStatements iterators
Remove all empty
for
statements::fix not forStatements empty