readability-identifier-naming
Checks for identifiers naming style mismatch.
This check will try to enforce coding guidelines on the identifiers naming. It supports one of the following casing types and tries to convert from one to another if a mismatch is detected
Casing types include:
lower_case
,UPPER_CASE
,camelBack
,CamelCase
,camel_Snake_Back
,Camel_Snake_Case
,aNy_CasE
.
It also supports a fixed prefix and suffix that will be prepended or appended to the identifiers, regardless of the casing.
Many configuration options are available, in order to be able to create different rules for different kinds of identifiers. In general, the rules are falling back to a more generic rule if the specific case is not configured.
The naming of virtual methods is reported where they occur in the base class, but not where they are overridden, as it can't be fixed locally there. This also applies for pseudo-override patterns like CRTP.
Options
The following options are describe below:
- :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`
- :option:`AggressiveDependentMemberLookup`
- :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`
- :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`
- :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`
- :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`
- :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`
- :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`
- :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`
- :option:`ConstantPointerParameterCase`, :option:`ConstantPointerParameterPrefix`, :option:`ConstantPointerParameterSuffix`
- :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`, :option:`ConstexprFunctionSuffix`
- :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`, :option:`ConstexprMethodSuffix`
- :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, :option:`ConstexprVariableSuffix`
- :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`
- :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`
- :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`
- :option:`GetConfigPerFile`
- :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`
- :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`
- :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`
- :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`
- :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`
- :option:`IgnoreMainLikeFunctions`
- :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix`
- :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`
- :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`
- :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`
- :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix`
- :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, :option:`MacroDefinitionSuffix`
- :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`
- :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`
- :option:`NamespaceCase`, :option:`NamespacePrefix`, :option:`NamespaceSuffix`
- :option:`ParameterCase`, :option:`ParameterPrefix`, :option:`ParameterSuffix`
- :option:`ParameterPackCase`, :option:`ParameterPackPrefix`, :option:`ParameterPackSuffix`
- :option:`PointerParameterCase`, :option:`PointerParameterPrefix`, :option:`PointerParameterSuffix`
- :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`, :option:`PrivateMemberSuffix`
- :option:`PrivateMethodCase`, :option:`PrivateMethodPrefix`, :option:`PrivateMethodSuffix`
- :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`, :option:`ProtectedMemberSuffix`
- :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`, :option:`ProtectedMethodSuffix`
- :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`
- :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`
- :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`
- :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`
- :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`
- :option:`TemplateParameterCase`, :option:`TemplateParameterPrefix`, :option:`TemplateParameterSuffix`
- :option:`TemplateTemplateParameterCase`, :option:`TemplateTemplateParameterPrefix`, :option:`TemplateTemplateParameterSuffix`
- :option:`TypeAliasCase`, :option:`TypeAliasPrefix`, :option:`TypeAliasSuffix`
- :option:`TypedefCase`, :option:`TypedefPrefix`, :option:`TypedefSuffix`
- :option:`TypeTemplateParameterCase`, :option:`TypeTemplateParameterPrefix`, :option:`TypeTemplateParameterSuffix`
- :option:`UnionCase`, :option:`UnionPrefix`, :option:`UnionSuffix`
- :option:`ValueTemplateParameterCase`, :option:`ValueTemplateParameterPrefix`, :option:`ValueTemplateParameterSuffix`
- :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix`
- :option:`VirtualMethodCase`, :option:`VirtualMethodPrefix`, :option:`VirtualMethodSuffix`
For example using values of:
- AbstractClassCase of
lower_case
- AbstractClassPrefix of
pre_
- AbstractClassSuffix of
_post
Identifies and/or transforms abstract class names as follows:
Before:
class ABSTRACT_CLASS {
public:
ABSTRACT_CLASS();
};
After:
class pre_abstract_class_post {
public:
pre_abstract_class_post();
};
For example using values of:
- ClassMemberCase of
lower_case
Before:
template <typename T>
struct Base {
T BadNamedMember;
};
template <typename T>
struct Derived : Base<T> {
void reset() {
this->BadNamedMember = 0;
}
};
After if AggressiveDependentMemberLookup is 0
:
template <typename T>
struct Base {
T bad_named_member;
};
template <typename T>
struct Derived : Base<T> {
void reset() {
this->BadNamedMember = 0;
}
};
After if AggressiveDependentMemberLookup is 1
:
template <typename T>
struct Base {
T bad_named_member;
};
template <typename T>
struct Derived : Base<T> {
void reset() {
this->bad_named_member = 0;
}
};
For example using values of:
- ClassCase of
lower_case
- ClassPrefix of
pre_
- ClassSuffix of
_post
Identifies and/or transforms class names as follows:
Before:
class FOO {
public:
FOO();
~FOO();
};
After:
class pre_foo_post {
public:
pre_foo_post();
~pre_foo_post();
};
For example using values of:
- ClassConstantCase of
lower_case
- ClassConstantPrefix of
pre_
- ClassConstantSuffix of
_post
Identifies and/or transforms class constant names as follows:
Before:
class FOO {
public:
static const int CLASS_CONSTANT;
};
After:
class FOO {
public:
static const int pre_class_constant_post;
};
For example using values of:
- ClassMemberCase of
lower_case
- ClassMemberPrefix of
pre_
- ClassMemberSuffix of
_post
Identifies and/or transforms class member names as follows:
Before:
class FOO {
public:
static int CLASS_CONSTANT;
};
After:
class FOO {
public:
static int pre_class_constant_post;
};
For example using values of:
- ClassMethodCase of
lower_case
- ClassMethodPrefix of
pre_
- ClassMethodSuffix of
_post
Identifies and/or transforms class method names as follows:
Before:
class FOO {
public:
int CLASS_MEMBER();
};
After:
class FOO {
public:
int pre_class_member_post();
};
For example using values of:
- ConstantCase of
lower_case
- ConstantPrefix of
pre_
- ConstantSuffix of
_post
Identifies and/or transforms constant names as follows:
Before:
void function() { unsigned const MyConst_array[] = {1, 2, 3}; }
After:
void function() { unsigned const pre_myconst_array_post[] = {1, 2, 3}; }
For example using values of:
- ConstantMemberCase of
lower_case
- ConstantMemberPrefix of
pre_
- ConstantMemberSuffix of
_post
Identifies and/or transforms constant member names as follows:
Before:
class Foo {
char const MY_ConstMember_string[4] = "123";
}
After:
class Foo {
char const pre_my_constmember_string_post[4] = "123";
}
For example using values of:
- ConstantParameterCase of
lower_case
- ConstantParameterPrefix of
pre_
- ConstantParameterSuffix of
_post
Identifies and/or transforms constant parameter names as follows:
Before:
void GLOBAL_FUNCTION(int PARAMETER_1, int const CONST_parameter);
After:
void GLOBAL_FUNCTION(int PARAMETER_1, int const pre_const_parameter_post);
For example using values of:
- ConstantPointerParameterCase of
lower_case
- ConstantPointerParameterPrefix of
pre_
- ConstantPointerParameterSuffix of
_post
Identifies and/or transforms constant pointer parameter names as follows:
Before:
void GLOBAL_FUNCTION(int const *CONST_parameter);
After:
void GLOBAL_FUNCTION(int const *pre_const_parameter_post);
For example using values of:
- ConstexprFunctionCase of
lower_case
- ConstexprFunctionPrefix of
pre_
- ConstexprFunctionSuffix of
_post
Identifies and/or transforms constexpr function names as follows:
Before:
constexpr int CE_function() { return 3; }
After:
constexpr int pre_ce_function_post() { return 3; }
For example using values of:
- ConstexprMethodCase of
lower_case
- ConstexprMethodPrefix of
pre_
- ConstexprMethodSuffix of
_post
Identifies and/or transforms constexpr method names as follows:
Before:
class Foo {
public:
constexpr int CST_expr_Method() { return 2; }
}
After:
class Foo {
public:
constexpr int pre_cst_expr_method_post() { return 2; }
}
For example using values of:
- ConstexprVariableCase of
lower_case
- ConstexprVariablePrefix of
pre_
- ConstexprVariableSuffix of
_post
Identifies and/or transforms constexpr variable names as follows:
Before:
constexpr int ConstExpr_variable = MyConstant;
After:
constexpr int pre_constexpr_variable_post = MyConstant;
For example using values of:
- EnumCase of
lower_case
- EnumPrefix of
pre_
- EnumSuffix of
_post
Identifies and/or transforms enumeration names as follows:
Before:
enum FOO { One, Two, Three };
After:
enum pre_foo_post { One, Two, Three };
For example using values of:
- EnumConstantCase of
lower_case
- EnumConstantPrefix of
pre_
- EnumConstantSuffix of
_post
Identifies and/or transforms enumeration constant names as follows:
Before:
enum FOO { One, Two, Three };
After:
enum FOO { pre_One_post, pre_Two_post, pre_Three_post };
For example using values of:
- FunctionCase of
lower_case
- FunctionPrefix of
pre_
- FunctionSuffix of
_post
Identifies and/or transforms function names as follows:
Before:
char MY_Function_string();
After:
char pre_my_function_string_post();
For example using values of:
- GlobalConstantCase of
lower_case
- GlobalConstantPrefix of
pre_
- GlobalConstantSuffix of
_post
Identifies and/or transforms global constant names as follows:
Before:
unsigned const MyConstGlobal_array[] = {1, 2, 3};
After:
unsigned const pre_myconstglobal_array_post[] = {1, 2, 3};
For example using values of:
- GlobalConstantPointerCase of
lower_case
- GlobalConstantPointerPrefix of
pre_
- GlobalConstantPointerSuffix of
_post
Identifies and/or transforms global constant pointer names as follows:
Before:
int *const MyConstantGlobalPointer = nullptr;
After:
int *const pre_myconstantglobalpointer_post = nullptr;
For example using values of:
- GlobalFunctionCase of
lower_case
- GlobalFunctionPrefix of
pre_
- GlobalFunctionSuffix of
_post
Identifies and/or transforms global function names as follows:
Before:
void GLOBAL_FUNCTION(int PARAMETER_1, int const CONST_parameter);
After:
void pre_global_function_post(int PARAMETER_1, int const CONST_parameter);
For example using values of:
- GlobalPointerCase of
lower_case
- GlobalPointerPrefix of
pre_
- GlobalPointerSuffix of
_post
Identifies and/or transforms global pointer names as follows:
Before:
int *GLOBAL3;
After:
int *pre_global3_post;
For example using values of:
- GlobalVariableCase of
lower_case
- GlobalVariablePrefix of
pre_
- GlobalVariableSuffix of
_post
Identifies and/or transforms global variable names as follows:
Before:
int GLOBAL3;
After:
int pre_global3_post;
For example using values of:
- InlineNamespaceCase of
lower_case
- InlineNamespacePrefix of
pre_
- InlineNamespaceSuffix of
_post
Identifies and/or transforms inline namespaces names as follows:
Before:
namespace FOO_NS {
inline namespace InlineNamespace {
...
}
} // namespace FOO_NS
After:
namespace FOO_NS {
inline namespace pre_inlinenamespace_post {
...
}
} // namespace FOO_NS
For example using values of:
- LocalConstantCase of
lower_case
- LocalConstantPrefix of
pre_
- LocalConstantSuffix of
_post
Identifies and/or transforms local constant names as follows:
Before:
void foo() { int const local_Constant = 3; }
After:
void foo() { int const pre_local_constant_post = 3; }
For example using values of:
- LocalConstantPointerCase of
lower_case
- LocalConstantPointerPrefix of
pre_
- LocalConstantPointerSuffix of
_post
Identifies and/or transforms local constant pointer names as follows:
Before:
void foo() { int const *local_Constant = 3; }
After:
void foo() { int const *pre_local_constant_post = 3; }
For example using values of:
- LocalPointerCase of
lower_case
- LocalPointerPrefix of
pre_
- LocalPointerSuffix of
_post
Identifies and/or transforms local pointer names as follows:
Before:
void foo() { int *local_Constant; }
After:
void foo() { int *pre_local_constant_post; }
For example using values of:
- LocalVariableCase of
lower_case
- LocalVariablePrefix of
pre_
- LocalVariableSuffix of
_post
Identifies and/or transforms local variable names as follows:
Before:
void foo() { int local_Constant; }
After:
void foo() { int pre_local_constant_post; }
For example using values of:
- MacroDefinitionCase of
lower_case
- MacroDefinitionPrefix of
pre_
- MacroDefinitionSuffix of
_post
Identifies and/or transforms macro definitions as follows:
Before:
#define MY_MacroDefinition
After:
#define pre_my_macro_definition_post
Note: This will not warn on builtin macros or macros defined on the command line
using the -D
flag.
For example using values of:
- MemberCase of
lower_case
- MemberPrefix of
pre_
- MemberSuffix of
_post
Identifies and/or transforms member names as follows:
Before:
class Foo {
char MY_ConstMember_string[4];
}
After:
class Foo {
char pre_my_constmember_string_post[4];
}
For example using values of:
- MethodCase of
lower_case
- MethodPrefix of
pre_
- MethodSuffix of
_post
Identifies and/or transforms method names as follows:
Before:
class Foo {
char MY_Method_string();
}
After:
class Foo {
char pre_my_method_string_post();
}
For example using values of:
- NamespaceCase of
lower_case
- NamespacePrefix of
pre_
- NamespaceSuffix of
_post
Identifies and/or transforms namespace names as follows:
Before:
namespace FOO_NS {
...
}
After:
namespace pre_foo_ns_post {
...
}
For example using values of:
- ParameterCase of
lower_case
- ParameterPrefix of
pre_
- ParameterSuffix of
_post
Identifies and/or transforms parameter names as follows:
Before:
void GLOBAL_FUNCTION(int PARAMETER_1, int const CONST_parameter);
After:
void GLOBAL_FUNCTION(int pre_parameter_post, int const CONST_parameter);
For example using values of:
- ParameterPackCase of
lower_case
- ParameterPackPrefix of
pre_
- ParameterPackSuffix of
_post
Identifies and/or transforms parameter pack names as follows:
Before:
template <typename... TYPE_parameters> {
void FUNCTION(int... TYPE_parameters);
}
After:
template <typename... TYPE_parameters> {
void FUNCTION(int... pre_type_parameters_post);
}
For example using values of:
- PointerParameterCase of
lower_case
- PointerParameterPrefix of
pre_
- PointerParameterSuffix of
_post
Identifies and/or transforms pointer parameter names as follows:
Before:
void FUNCTION(int *PARAMETER);
After:
void FUNCTION(int *pre_parameter_post);
For example using values of:
- PrivateMemberCase of
lower_case
- PrivateMemberPrefix of
pre_
- PrivateMemberSuffix of
_post
Identifies and/or transforms private member names as follows:
Before:
class Foo {
private:
int Member_Variable;
}
After:
class Foo {
private:
int pre_member_variable_post;
}
For example using values of:
- PrivateMethodCase of
lower_case
- PrivateMethodPrefix of
pre_
- PrivateMethodSuffix of
_post
Identifies and/or transforms private method names as follows:
Before:
class Foo {
private:
int Member_Method();
}
After:
class Foo {
private:
int pre_member_method_post();
}
For example using values of:
- ProtectedMemberCase of
lower_case
- ProtectedMemberPrefix of
pre_
- ProtectedMemberSuffix of
_post
Identifies and/or transforms protected member names as follows:
Before:
class Foo {
protected:
int Member_Variable;
}
After:
class Foo {
protected:
int pre_member_variable_post;
}
For example using values of:
- ProtectedMethodCase of
lower_case
- ProtectedMethodPrefix of
pre_
- ProtectedMethodSuffix of
_post
Identifies and/or transforms protect method names as follows:
Before:
class Foo {
protected:
int Member_Method();
}
After:
class Foo {
protected:
int pre_member_method_post();
}
For example using values of:
- PublicMemberCase of
lower_case
- PublicMemberPrefix of
pre_
- PublicMemberSuffix of
_post
Identifies and/or transforms public member names as follows:
Before:
class Foo {
public:
int Member_Variable;
}
After:
class Foo {
public:
int pre_member_variable_post;
}
For example using values of:
- PublicMethodCase of
lower_case
- PublicMethodPrefix of
pre_
- PublicMethodSuffix of
_post
Identifies and/or transforms public method names as follows:
Before:
class Foo {
public:
int Member_Method();
}
After:
class Foo {
public:
int pre_member_method_post();
}
For example using values of:
- StaticConstantCase of
lower_case
- StaticConstantPrefix of
pre_
- StaticConstantSuffix of
_post
Identifies and/or transforms static constant names as follows:
Before:
static unsigned const MyConstStatic_array[] = {1, 2, 3};
After:
static unsigned const pre_myconststatic_array_post[] = {1, 2, 3};
For example using values of:
- StaticVariableCase of
lower_case
- StaticVariablePrefix of
pre_
- StaticVariableSuffix of
_post
Identifies and/or transforms static variable names as follows:
Before:
static unsigned MyStatic_array[] = {1, 2, 3};
After:
static unsigned pre_mystatic_array_post[] = {1, 2, 3};
For example using values of:
- StructCase of
lower_case
- StructPrefix of
pre_
- StructSuffix of
_post
Identifies and/or transforms struct names as follows:
Before:
struct FOO {
FOO();
~FOO();
};
After:
struct pre_foo_post {
pre_foo_post();
~pre_foo_post();
};
For example using values of:
- TemplateParameterCase of
lower_case
- TemplateParameterPrefix of
pre_
- TemplateParameterSuffix of
_post
Identifies and/or transforms template parameter names as follows:
Before:
template <typename T> class Foo {};
After:
template <typename pre_t_post> class Foo {};
For example using values of:
- TemplateTemplateParameterCase of
lower_case
- TemplateTemplateParameterPrefix of
pre_
- TemplateTemplateParameterSuffix of
_post
Identifies and/or transforms template template parameter names as follows:
Before:
template <template <typename> class TPL_parameter, int COUNT_params,
typename... TYPE_parameters>
After:
template <template <typename> class pre_tpl_parameter_post, int COUNT_params,
typename... TYPE_parameters>
For example using values of:
- TypeAliasCase of
lower_case
- TypeAliasPrefix of
pre_
- TypeAliasSuffix of
_post
Identifies and/or transforms type alias names as follows:
Before:
using MY_STRUCT_TYPE = my_structure;
After:
using pre_my_struct_type_post = my_structure;
For example using values of:
- TypedefCase of
lower_case
- TypedefPrefix of
pre_
- TypedefSuffix of
_post
Identifies and/or transforms typedef names as follows:
Before:
typedef int MYINT;
After:
typedef int pre_myint_post;
For example using values of:
- TypeTemplateParameterCase of
lower_case
- TypeTemplateParameterPrefix of
pre_
- TypeTemplateParameterSuffix of
_post
Identifies and/or transforms type template parameter names as follows:
Before:
template <template <typename> class TPL_parameter, int COUNT_params,
typename... TYPE_parameters>
After:
template <template <typename> class TPL_parameter, int COUNT_params,
typename... pre_type_parameters_post>
For example using values of:
- UnionCase of
lower_case
- UnionPrefix of
pre_
- UnionSuffix of
_post
Identifies and/or transforms union names as follows:
Before:
union FOO {
int a;
char b;
};
After:
union pre_foo_post {
int a;
char b;
};
For example using values of:
- ValueTemplateParameterCase of
lower_case
- ValueTemplateParameterPrefix of
pre_
- ValueTemplateParameterSuffix of
_post
Identifies and/or transforms value template parameter names as follows:
Before:
template <template <typename> class TPL_parameter, int COUNT_params,
typename... TYPE_parameters>
After:
template <template <typename> class TPL_parameter, int pre_count_params_post,
typename... TYPE_parameters>
For example using values of:
- VariableCase of
lower_case
- VariablePrefix of
pre_
- VariableSuffix of
_post
Identifies and/or transforms variable names as follows:
Before:
unsigned MyVariable;
After:
unsigned pre_myvariable_post;
For example using values of:
- VirtualMethodCase of
lower_case
- VirtualMethodPrefix of
pre_
- VirtualMethodSuffix of
_post
Identifies and/or transforms virtual method names as follows:
Before:
class Foo {
public:
virtual int MemberFunction();
}
After:
class Foo {
public:
virtual int pre_member_function_post();
}