Dialog 'Static Analysis Settings' - 'Naming Conventions'Permalink

Function: In the dialog, you define the prefixes for the data types and scopes of variables, as well as prefixes for POUs and user-defined data types (DUTs). Static analysis checks compliance with the naming conventions. When a convention is not observed, the static analysis reports an error message in the “Messages” view.

Call:

  • Menu bar: “Project  Project Settings”, “Static Analysis” category, “Open configuration dialog” link

  • Menu bar: “Build  Static analysis  Settings”

Requirement:

  • The CODESYS Static Analysis package is installed.

  • A project is open.

The error messages are displayed in the following format: sa_icon_message ‎NC <prefix convention number> :‎‎ <message text>‎. NC stands for "Naming Convention". For example, the error message "sa_icon_message“NC0102: Invalid name...”" means a violation of naming convention 102 for POUs of type ‎PROGRAM‎.

You can use the pragma ‎'naming'‎ to deactivate naming conventions for individual identifiers. The identifiers can begin with anything, not necessarily with the prefix.

“Filter”

Input field for strings to be searched for

Table with the naming conventions

“Names”

Nodes and elements for which a prefix can be defined.

The number in parentheses after each element (for example, “PROGRAM (102)”) is the prefix convention number that is reported in the case of noncompliance with a naming convention.

“Prefix”

Input field of the prefix

  • Multiple prefixes can be specified by means of comma separation.

    Example:

    “Prefix for POUs”, ‎PROGRAM (102)‎: ‎prog, PRG_‎

    “Prefix for POUs”, ‎FUNCTION (103)‎: ‎fun, FUN_‎

  • Regular expressions (RegEx) are also possible for prefixes. To do this, an ‎@‎ has to be prepended.

    Example:

    The name has to begin with ‎x‎ and may contain one character from the scope ‎a-dA-D‎: ‎@x[a-dA-D]‎.

  • For variables of type “Alias” and POUs of type “Property”, the prefix can be defined with the placeholder ‎{datatype}‎.

“Prefixes for variables”

Organizational node for all variables for which a prefix can be defined dependent on data type or scope.

“Prefixes for POUs”

Organizational node for all POU types and method scopes for which a prefix can be defined

“Prefixes for DUTs”

Organizational node for the DUT data types (structure, enumeration, alias, or union) for which a prefix can be defined

“Prefixes for custom types”

Organizational node for special custom types (particularly those from libraries)

You can extend the list with conventions: Click the blank space below it. In the “Input Assistant” dialog, specify the name of a custom type or select a custom type.

To delete a convention, select it and press the [Del] key.

Note: These conventions have priority over the prefixes which are defined with the attribute ‎{attribute 'nameprefix' := '<prefix>'}‎.

Options

“First character after prefix should be an upper case letter”

_cds_icon_option_activated: Static analysis reports an error for a variable when the first character of the variable name after the defined prefix is not an uppercase letter.

“Combine scope prefix with data type prefix”

_cds_icon_option_activated: As its namespace, a variable must have the defined prefix followed by the defined prefix for its data type.

Example: The following prefixes are defined: ‎g_‎ for “VAR_GLOBAL”, and ‎r‎ for the data type “REAL”. The code analysis reports errors for global REAL variables that do not have the prefix ‎g_r‎.

_cds_icon_option_deactivated: If conventions for the namespace are specified for a variable, then these conventions are taken into account. As a result, any data type conventions are ignored.

Example: The following prefixes are defined: ‎g_‎ for “VAR_GLOBAL”, and ‎r‎ for the data type “REAL”. The code analysis reports exclusively errors for global ‎REAL‎ variables that do not have the prefix ‎g_‎.

“Recursive prefixes for combinable data types”

_cds_icon_option_activated: Variables of combined data types have to have compound prefixes that follow the defined naming conventions.

Example:

‎ppiVariable : POINTER TO POINTER TO INT;‎

The prefix ‎p‎ was defined for variables of data type ‎POINTER‎, and the prefix ‎I‎ was defined for the data type ‎INT‎. Static analysis reports errors for all variables of type ‎POINTER TO POINTER TO INT‎ which do not have the prefix ‎ppi‎.

‎refaiVar : REFERENCE TO ARRAY[1..3] OF INT;‎

The prefix ‎ref‎ was defined for the data type ‎REFERENCE TO‎, the prefix ‎a‎ for an array, and the prefix ‎I‎ for the data type ‎INT‎. Static analysis reports errors for all variables of type ‎REFERENCE TO ARRAY[1..3] OF INT‎ which do not have the prefix ‎refai‎.

Example

The following naming convention corresponds for the most part to the recommendations described in the "Identifiers" chapter.

_san_prefixes_for_variables_types
_san_prefixes_for_variables_scopes
_san_prefixes_for_pous_and_duts

Example

The naming convention (1) refers to the standard POU ‎TON‎. As a result, declarations of the special library POU are checked for the prefix "ton_". Click the blank space (2) to insert more naming conventions.

_san_img_prefixes_for_user_defined_types