The naming check can be used to check the naming convention of variables.
e.g.: Hungarian notation [{prefix}] {datatype} {identifier}
float fRadius; bool bDoor; global int g_iThreadId; const int ICOUNT;
By default, the rules provided by the add-on are used.
But it's also possible change this rules or to create your own rules for this check. See "Create your own rule file".
A rule file consists of several rule tags. Each rule consists of a pattern and a message with id and summary.
<rule version="1">
<pattern>^[A-Z0-9_]+$</pattern>
<message>
<id>const</id>
<summary>The varibale name can not consist of lowercase letters.</summary>
</message>
</rule>
Defines a regular expression which will be applied to the variable name. If the expression does not match, an error is returned.
Example regular expression
<pattern>^[A-Z0-9_]+$</pattern>
Explanation
Example regular expression (Source https://regexr.com/)
^
Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m
) is enabled.[
Character set. Match any character in the set.
A-Z
Range. Matches a character in the range "A" to "Z" (char code 65 to 90). Case sensitive.0-9
Range. Matches a character in the range "0" to "9" (char code 48 to 57). Case sensitive._
Character. Matches a "_" character (char code 95). ]
+
Quantifier. Match 1 or more of the preceding token.$
End. Matches the end of the string, or the end of a line if the multiline flag (m
) is enabled.Result
Pattern | Variable Type and Name | Check |
---|---|---|
^[A-Z0-9_]+$ | const I_VAR | OK |
^[A-Z0-9_]+$ | const i_VAR | NOK |
^[A-Z0-9_]+$ | const I_Va | NOK |
Special regular expression pattern
With these special patterns you can check if special information are included in the variable name. More of them will come... Pattern | Example --------|--------------- %fileName% | b_aesAutoRestart %fileName_allUpper% | b_AESAutoRestart %fileName_allLower% | b_aesAutoRestart
Defines the message that will be used when the regualr expression does not apply.
The id indicates to which variables the regular expression should be applied. Each variable has a type and is available to a specific scope. In addition, it can be modified by specific keywords like const.
For the check process the categories of each variable will be automatically defined by the tool.
The id is structured in following categories:
<modifier (const | nonconst)> <type (see list below)> <scope (local | argument | global)>
e.g. <id>const int argument</id>
Special keyword for detailed analytics
See list of supportes types in the document below
Scope where variable is in use
For type and *scope only one value can be defined.
Either all three categories of values must be defined or only for one.
Example for an const int variable in an global scope if a specific rule is available:
const global int g_IAES_VAR
<rule version="1">
<pattern> ... </pattern>
<message>
<id>const int global</id>
<summary> ... </summary>
</message>
</rule>
This rule will be checked because all 3 categories are matching.
Examples for an const int variable in an global scope if no specific rule is available:
const global int g_IAES_VAR
<rule version="1">
<pattern> ... </pattern>
<message>
<id>const</id>
<summary> ... </summary>
</message>
</rule>
<rule version="1">
<pattern> ... </pattern>
<message>
<id>int</id>
<summary> ... </summary>
</message>
</rule>
<!-- A rule for "global" couldn't be found. -->
The two existing rules are applied.
Attention
Due to this logic, it is necessary that the single category rules can be combined with each other. Otherwise it would always come with certain combination errors.
Some examples:
ID | Pattern | const int local | const int local | (nonconst) int global | (nonconst) int global |
---|---|---|---|---|---|
Variable Name | IAES_VAR | iAES_VAR | g_i_CountFlags | i_CountFlags | |
const | ^[A-Z0-9_]+$ | OK | NOK | ignored | ignored |
int | ^[iI].* | OK | OK | OK | OK |
float | ^[fF].* | ignored | ignored | ignored | ignored |
local | "(.)(%fileName%_)(.)" | OK | OK | ignored | ignored |
global | ^[gG].* | ignored | ignored | OK | NOK |
Total | OK | NOK | OK | NOK |
If a separate rule file is required, this can be specified with the command line option "--naming-rule-file =".
The following values are currently available for the type category:
Types:
dyn variables
dyn_dyn variables