C and C++


LANG.ID.STYLE : Naming Style Violation

Summary

An identifier does not conform to the style requirements that have been expressed through IDENTIFIER_NAMING_* rules applied to the project.

You can specify your own rules, or use the barr_naming preset to apply a set of rules corresponding to the naming rules in the Barr Group Embedded C Coding Standard.

There are no rules applied by default (that is, there are no factory settings for the IDENTIFIER_NAMING_* parameters, and no IDENTIFIER_NAMING_* rules in any of the default presets shipped with CodeSonar). This means that if you enable this warning class without specifying your own rules or including a suitable preset, you will not get any warnings.

Properties

Class Name Naming Style Violation
Significance style
Mnemonic LANG.ID.STYLE
Categories
JSF++ JSF++:47 Identifiers will not begin with the underscore character '_'.
  JSF++:50 The first word of the name of a class, structure, namespace, enumeration, or type created with typedef will begin with an uppercase letter. All others letters will be lowercase.
  JSF++:51 All letters contained in function and variable names will be composed entirely of lowercase letters.
  JSF++:52 Identifiers for constant and enumerator values shall be lowercase.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Naming Style Violation"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

Suppose there is an organization-wide style rule that all class names must be in camel case. For example, a class can be named MyClass but not myClass or myclass.

To check that all class names conform to this rule, add the following IDENTIFIER_NAMING_CLASS_CASE entry to a suitable configuration file. For an organization-wide rule, you might decide to add the rule to the general template configuration file so that it is always available to all projects, or to create a custom preset or default preset containing all the organization style rules.

IDENTIFIER_NAMING_CLASS_CASE = CamelCase

When the Naming Style Violation warning class is enabled and this IDENTIFIER_NAMING_CLASS_CASE rule is specified, CodeSonar will issue the following warnings.

class A {                         // ok: camel case according to definition ^[A-Z][a-zA-Z0-9]*
   // ...
  };

  class Capitalized {              // ok: camel case according to definition ^[A-Z][a-zA-Z0-9]*
   // ...
  };

  class Capitalizedmultiword {     // ok: a human reader might object to the interior words not being 
                                   // individually capitalized, but the warning class check is syntactic only
   // ...
  };

  class CamelCase {                // ok: classic camel case
   // ...
  };

  class UPPERCASE {                // ok: camel case according to definition ^[A-Z][a-zA-Z0-9]*
   // ...
  };

  class lowercase {       // 'Naming Style Violation' warning issued here 
   // ...
  };

  class camelBack {       // 'Naming Style Violation' warning issued here 
   // ...
  };

  class Camel_Snake {     // 'Naming Style Violation' warning issued here 
   // ...
  };

  class camel_Snakeback { // 'Naming Style Violation' warning issued here 
   // ...
  };

  class mIxEd_cAse {      // 'Naming Style Violation' warning issued here 
   // ...
  };

  int foo;

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.