Main Content

Check custom rules (-custom-rules)

(Removed) Follow naming conventions for identifiers

Using Code Prover to follow naming conventions is no longer supported. Use Check custom rules (-custom-rules) in Bug Finder instead. For more information, see Version History.

Description

Define naming conventions for identifiers and check your code against them.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Coding Standards & Code Metrics node.

Command line and options file: Use the option -custom-rules. See Command-Line Information.

Why Use This Option

Use this option to impose naming conventions on identifiers. Using a naming convention allows you to easily determine the nature of an identifier from its name. For instance, if you define a naming convention for structures, you can easily tell whether an identifier represents a structured variable or not.

After analysis, the Results List pane lists violations of the naming conventions. On the Source pane, for every violation, Polyspace® assigns a symbol to the keyword or identifier relevant to the violation.

For the full list of types on which you can apply naming conventions, see Custom Coding Rules.

Settings

On

Polyspace matches identifiers in your code against text patterns you define. Define the text patterns in a custom coding rules file. To create a coding rules file,

  • Use the custom rules wizard:

    1. Click . A Checkers selection window opens.

    2. The Custom node in the left pane is highlighted. Expand the nodes in the right pane to select custom rule you want to check.

    3. For every custom rule you want to check:

      1. Select On .

      2. In the Convention column, enter the error message you want to display if the rule is violated.

        For example, for rule 4.3, All struct fields must follow the specified pattern, you can enter All struct fields must begin with s_. This message appears on the Result Details pane if:

        • You specify the Pattern as s_[A-Za-z0-9_]+.

        • A structure field in your code does not begin with s_.

      3. In the Pattern column, enter the text pattern.

        For example, for rule 4.3, All struct fields must follow the specified pattern, you can enter s_[A-Za-z0-9_]+. Polyspace reports violation of rule 4.3 if a structure field does not begin with s_.

        You can use Perl regular expressions to define patterns. For instance, you can use the following expressions.

        ExpressionMeaning
        .Matches any single character except newline
        [a-z0-9]         Matches any single letter in the set a-z, or digit in the set 0-9
        [^a-e]Matches any single letter not in the set a-e
        \dMatches any single digit
        \wMatches any single alphanumeric character or _
        x?Matches 0 or 1 occurrence of x
        x*Matches 0 or more occurrences of x
        x+Matches 1 or more occurrences of x

        For frequent patterns, you can use the following regular expressions:

        • (?!__)[a-z0-9_]+(?!__), matches a text pattern that does not start and end with two underscores.

          int __text; //Does not match
          int _text_; //Matches

        • [a-z0-9_]+_(u8|u16|u32|s8|s16|s32) , matches a text pattern that ends with a specific suffix.

          int _text_; //Does not match
          int _text_s16; //Matches
          int _text_s33; // Does not match

        • [a-z0-9_]+_(u8|u16|u32|s8|s16|s32)(_b3|_b8)? , matches a text pattern that ends with a specific suffix and an optional second suffix.

          int _text_s16; //Matches
          int _text_s16_b8; //Matches

        For a complete list of regular expressions, see Perl documentation.

To use or update an existing coding rules file, click to open the Checkers selection window then do one of the following:

  • Enter the full path to the file in the field provided

  • Click Browse and navigate to the file location.

Off (default)

Polyspace does not check your code against custom naming conventions.

Command-Line Information

Parameter: -custom-rules
Value: from-file, specify the file using Set checkers by file (-checkers-selection-file)
Default: Off
Example (Bug Finder): polyspace-bug-finder -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"
Example (Code Prover): polyspace-code-prover -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"
Example (Bug Finder Server): polyspace-bug-finder-server -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"
Example (Code Prover Server): polyspace-code-prover-server -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"

Version History

expand all

R2024a: Removed from Code Prover

If you use the option -custom-rules in a Code Prover analysis, Polyspace issues a warning and the analysis ignores the option. The workflow for checking compliance with naming conventions has been removed from Code Prover. To check for compliance with naming conventions, use Bug Finder. For instance, at the command line, replace this command:

polyspace-code-prover -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"
with this command:
polyspace-bug-finder -sources file_name -custom-rules from-file -checkers-selection-file "C:\Standards\custom_config.xml"
See Migrate Code Prover Workflows for Checking Coding Standards and Code Metrics to Bug Finder.