C and C++


LANG.ID.STYLE : 命名規則違反

要旨

識別子がプロジェクトに適用された IDENTIFIER_NAMING_* ルールによって表現されたスタイルガイド・命名規則に準拠していません。

本ワーニングクラスでは、ユーザーは独自のルールを指定することも可能であり、または barr_naming preset を使用して Barr Group Embedded C Coding Standard の命名規則に対応する一連のルールを適用することも可能です。

デフォルト設定で適用されているルールはありません(つまり、 IDENTIFIER_NAMING_* パラメータの出荷時設定はなく、そして CodeSonar の出荷時状態から用意されている default presets 内でも IDENTIFIER_NAMING_* のルールは設定されていません。)。 これが意味することとして、独自のルールを指定しない、または適切なプリセットを有効化せずにこのワーニングクラスを有効にしても、警告(ワーニング)は表示されません。

プロパティ

クラス名 Naming Style Violation
日本語クラス名 命名規則違反
クラス分類 スタイル (style)
ニーモニック LANG.ID.STYLE
カテゴリー
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.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Naming Style Violation"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

すべてのクラス名はキャメルケースでなければならないという組織全体のスタイルルール・命名規則があることを仮定します。 たとえば、クラスの名前を MyClass にすることはできますが、myClassmyclass にすることはできません。.

全てのクラス名がこの規則に準拠していることを確認するには、次の IDENTIFIER_NAMING_CLASS_CASE エントリを適切な configuration file に追加して下さい。 組織内の横断的な規則の場合には、全てのプロジェクトで常に規則準拠の確認ができるよう、 general template configuration file に追加する、 若しくは組織レベルでチェックされるべき全ての規則を含んだ custom presetdefault preset を作成します。

IDENTIFIER_NAMING_CLASS_CASE = CamelCase

Naming Style Violation の検出が有効となっていて、IDENTIFIER_NAMING_CLASS_CASE ルールが指定されている場合、 CodeSonar は次の警告(ワーニング)を発行します。

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;

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。