The rule to check do case statements in the code don't contain some
expressions. Checked things:
- The maximum and minimum amount of
casestatements' branches.
The syntax in a configuration file is:
[ruleType] ?not? caseStatements [checkType] [amount]
- 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
casestatement which violates any of the checks. Search type will list all statements which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the statements which violates the checks. Fix type will execute the default shell command set by the program's setting fixCommand. - optional word not means negation for the rule. Adding word not will
change to inform only about the
casestatements which not violate the checks. Probably useable only with search and count type of rule. - caseStatements is the name of the rule. It is case-insensitive, thus it can be set as casestatements, caseStatements or cAsEsTaTeMeNtS.
- checkType is the type of checks to perform on the
casestatements. Proper values are: min and max. Setting it min will check if allcasestatements have at least the selected amount of branches. Max value will check if thecasestatements have maximum the selected amount of branches. - amount parameter is required for both types of checks. It is desired amount
of branches for the
casestatements, minimal or maximum, depends on check's type.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "caseStatements" in the code before it. For example, if the rule should be disabled for the statement, the full declaration of it should be::
{.ruleOff: "caseStatements".}
case a
of 1:
echo a
To enable the rule again, the pragma ruleOn: "caseStatements" 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: "caseStatements".}
case a
of 1:
echo a
Examples
Check if all
casestatements have at least 4 branches:check caseStatements min 4