Login
hasPragma rule
Login

The rule to check if the selected procedure has the selected pragma. The syntax in a configuration file is:

[ruleType] ?not? haspragma [listOfPragmas]

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:

  1. Each pragma name must be separated with whitespace: myPragma otherPragma
  2. If the search string contains whitespace, it must be enclosed in quotes or escaped, like in the console line arguments: "mypragma: [" otherPragma
  3. 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

  1. Check if all procedures have declared pragma raises. It can be empty or contains names of raised exception:

    check hasPragma procedures "raises: [*"

  2. Find all declarations with have sideEffect pragma declared:

    search hasPragma all sideEffect

  3. Count amount of procedures which don't have declared pragma gcSafe:

    count not hasPragma procedures gcSafe

  4. 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: *"