The rule to check if the selected module has the selected entities, like procedures, constants, etc. with the selected names. The syntax in a configuration file is
[ruleType] ?not? hasentity [entityType] [entityName] ?parentEntity? ?childIndex?
- 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 the selected type of entity with the selected name was not found in the module. Search type will list all entities of the selected type with the selected name and raise error if nothing was found. Count type will simply list the amount of the selected entities. Fix type will execute the default shell command set by the program's setting, fixCommand.
- optional word not means negation for the rule. For example, if rule is set to check for procedures named myProc, adding word not will change to inform only about modules without the procedure with that name.
- hasentity is the name of the rule. It is case-insensitive, thus it can be set as hasentity, hasEntity or hAsEnTiTy.
- entityType is the type of entity which will be looking for. Proper values are types used by Nim compiler, defined in file compiler/ast.nim in enumeration TNodeKind. Examples: nkType, nkCall.
- entityName is the name of entity which will be looking for. The rule search for the selected entity type, which name starts with entityName. For example, if entityType is set to nkProcDef and entityName is set to myProc the rule will find procedures named myProc, but also myProcedure.
- if optional parameter parentEntity is set then the entity will be searched only as a child of the selected type of entities. For example setting entityType to nkProcDef, entityName to myProc and parentEntity to nkStmtList will find all nested procedures with name myProc or myProcedure.
- if optional parameter childIndex is set, then the entity will be searched
only as the selected child of the selected parent. In order for
*childIndex
parameter to work, the parameter parentEntity must be set too. If the value of the childIndex is a natural number, it is the index of the child counted from the beginning of the list of children. If the value is negative, it is the index of the child counted from the end of the list of children.
To look only for global entities, add *
to the end of the entityName
parameter. Setting it to MyProc* will look only for global entities
which full name is MyProc.
Note
hasEntity rule is considered as a low level rule. It requires a knowledge about Nim compiler, especially names of the Nim code nodes and the generated source code tree to use. It is recommended to use other rules instead of this one.
Disabling the rule
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "hasEntity" before the code's fragment which shouldn't be checked.
To enable the rule again, the pragma ruleOn: "hasEntity" should be added before the code which should be checked.
Examples
Check if module has declared global procedure with name myProc:
check hasEntity nkProcDef myProc*
Search for all defined global constants:
search hasEntity nkConstSection *
Count the amount of global enumerations:
count hasEntiry nkEnumTy *
Check if there are no declarations of global range types:
check not hasEntity nkRange *