The rule check if the selected type of entries follow the selected naming convention. It can check variables, procedures and enumerations' values. The syntax in a configuration file is:
[ruleType] ?not? namingConv [entityType] [nameExpression]
- 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 selected entity type which doesn't follow the selected naming convention. Search type will list all entities of the selected type which follows the selected naming convention. Count type will simply list the amount of the selected type of entities, which follows the naming convention. 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 selected type of entities, which doesn't follow the selected naming convention for search and count types of rules and raise error if the entity follows the naming convention for check type of the rule.
- namingConv is the name of the rule. It is case-insensitive, thus it can be set as namingconv, namingConv or nAmInGcOnV.
- entityType is the type of code's entities to check. Possible values are: variables - check the declarations of variables, enumerations - check the names of enumerations values and procedures - check the names of the declarations of procedures.
- nameExpression - the regular expression which the names of the selected entities should follow. Any expression supported by PCRE is allowed.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "namingConv" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for procedure proc main()
, the full declaration of it should
be:
proc main () {.ruleOff: "namingConv".}
To enable the rule again, the pragma ruleOn: "namingConv" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "namingConv".} = 1
Examples
- Check if names of variables follow standard Nim convention:
check namingConv variables [a-z][A-Z0-9_]*
- Find procedures which names ends with proc:
search namingConv procedures proc$
- Count enumerations which values are not start with enum:
count not namingConv enumerations ^enum