Index: clang-tidy/readability/IdentifierNamingCheck.h =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.h +++ clang-tidy/readability/IdentifierNamingCheck.h @@ -48,6 +48,8 @@ CT_CamelBack, CT_UpperCase, CT_CamelCase, + CT_CamelSnakeCase, + CT_CamelSnakeBack }; struct NamingStyle { Index: clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -163,6 +163,8 @@ .Case("UPPER_CASE", CT_UpperCase) .Case("camelBack", CT_CamelBack) .Case("CamelCase", CT_CamelCase) + .Case("Camel_Snake_Case", CT_CamelSnakeCase) + .Case("camel_Snake_Back", CT_CamelSnakeBack) .Default(CT_AnyCase); }; @@ -189,6 +191,10 @@ return "UPPER_CASE"; case CT_CamelCase: return "CamelCase"; + case CT_CamelSnakeCase: + return "Camel_Snake_Case"; + case CT_CamelSnakeBack: + return "camel_Snake_Back"; } llvm_unreachable("Unknown Case Type"); @@ -230,6 +236,8 @@ llvm::Regex("^[a-z][a-zA-Z0-9]*$"), llvm::Regex("^[A-Z][A-Z0-9_]*$"), llvm::Regex("^[A-Z][a-zA-Z0-9]*$"), + llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"), + llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"), }; bool Matches = true; @@ -319,6 +327,27 @@ } } break; + + case IdentifierNamingCheck::CT_CamelSnakeCase: + for (auto const &Word : Words) { + if (&Word != &Words.front()) + Fixup += "_"; + Fixup += Word.substr(0, 1).upper(); + Fixup += Word.substr(1).lower(); + } + break; + + case IdentifierNamingCheck::CT_CamelSnakeBack: + for (auto const &Word : Words) { + if (&Word != &Words.front()) { + Fixup += "_"; + Fixup += Word.substr(0, 1).upper(); + } else { + Fixup += Word.substr(0, 1).lower(); + } + Fixup += Word.substr(1).lower(); + } + break; } return Fixup; Index: test/clang-tidy/readability-identifier-naming.cpp =================================================================== --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -59,10 +59,10 @@ // RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \ // RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \ // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \ -// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \ +// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: Camel_Snake_Case}, \ // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \ // RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \ -// RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \ +// RUN: {key: readability-identifier-naming.TypeAliasCase, value: camel_Snake_Back}, \ // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \ // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \ // RUN: ]}' -- -std=c++11 -fno-delayed-template-parsing \ @@ -261,7 +261,7 @@ // CHECK-FIXES: {{^}} virtual ~AAbstractClass() = 0;{{$}} virtual void VIRTUAL_METHOD(); // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD' -// CHECK-FIXES: {{^}} virtual void v_VIRTUAL_METHOD();{{$}} +// CHECK-FIXES: {{^}} virtual void v_Virtual_Method();{{$}} void non_Virtual_METHOD() {} // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD' // CHECK-FIXES: {{^}} void __non_Virtual_METHOD() {}{{$}} @@ -316,12 +316,12 @@ using my_struct_type = THIS___Structure; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type' -// CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}} +// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}} template using SomeOtherTemplate = my_other_templated_class <:: FOO_NS ::my_class>; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate' -// CHECK-FIXES: {{^}}using some_other_template_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}} +// CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}} static void static_Function() { // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'