The rule to check if the selected procedure has the selected pragma. The syntax in a configuration file is:
[ruleType] ?not? haspragma [listOfPragmas]
- 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 rule will looking for procedures with declaration of the selected list of pragmas and list all of them which doesn't have them, raising error either. Search rule will look for the procedures with the selected pragmas and list all of them which have the selected pragmas, raising error if nothing is found. Count type will simply list the amount of the procedures with the selected pragmas. Fix type will try to append or remove the pragmas from the list to procedures. Please read general information about the fix type of rules about potential issues.
- optional word not means negation for the rule. For example, if rule is set to check for pragma SideEffect, adding word not will change to inform only about procedures with that pragma.
- haspragma is the name of the rule. It is case-insensitive, thus it can be set as haspragma, hasPragma or hAsPrAgMa.
- entityType is the type of code's entity which will be checked for the
selected pragmas. Possible values:
procedures
: check all procedures, functions and methods.templates
: check templates only.all
: check all routines declarations (procedures, functions, templates, macros, etc.).unborrowed
: check all procedures, functions and methods which are not borrowed from other modules. listOfPragmas is the list of pragmas for which the rule will be looking for. Each pragma must be separated with whitespace, like:
SideEffect gcSafe
It is possible to use shell's like globing in setting the names of the
pragmas. If the sign *
is at the start of the pragma name, it means to
look for procedures which have pragmas ending with that string. For example,
*Effect
will find procedures with pragma SideEffect but not
sideeffect or effectPragma. If sign *
is at the end of the pragma
name, it means to look for procedures which have pragmas starting
with that string. For example, raises: [*
will find procedures with
pragma raises: [] or raises: [Exception] but not myCustomraises: [custom]
.
If the name of the pragma starts and ends with sign *
, it means to look
for procedures which have pragmas containing the string. For example, *Exception*
will find raises: [MyException]
or myCustomExceptionRaise
.
The list of pragmas must be in the form of console line arguments:
- Each pragma name must be separated with whitespace:
myPragma otherPragma
- If the search string contains whitespace, it must be enclosed in quotes
or escaped, like in the console line arguments:
"mypragma: [" otherPragma
- All other special characters must be escaped as in a console line
arguments:
stringWith\"QuoteSign
Disabling the rule
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "hasPragma" in the element from which the rule
should be disabled. For example, if the rule should be disabled for procedure
main()
, the full declaration of it should be:
proc main() {.ruleOff: "hasPragma".}
To enable the rule again, the pragma ruleOn: "hasPragma" should be added in
the element which should be checked. For example, if the rule should be
re-enabled for const a = 1
, the full declaration should be:
const a = 1 {.ruleOn: "hasPragma".}
Examples
Check if all procedures have declared pragma raises. It can be empty or contains names of raised exception:
check hasPragma procedures "raises: [*"
Find all declarations with have sideEffect pragma declared:
search hasPragma all sideEffect
Count amount of procedures which don't have declared pragma gcSafe:
count not hasPragma procedures gcSafe
Check if all procedures have declared pragmas contractual and lock. The lock pragma must have entered the level of the lock:
check hasPragma procedures contractual "lock: *"