Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
This revision was automatically updated to reflect the committed changes. Closed by commit rL276110: [clang-tidy] readability-identifier-naming - support for other case types (authored by omtcyfz). Changed prior to commit: https://reviews.llvm.org/D21472?vs=63462=64671#toc Repository: rL LLVM https://reviews.llvm.org/D21472 Files: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp Index: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp === --- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp +++ clang-tools-extra/trunk/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' Index: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h === --- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h +++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h @@ -48,6 +48,8 @@ CT_CamelBack, CT_UpperCase, CT_CamelCase, +CT_CamelSnakeCase, +CT_CamelSnakeBack }; struct NamingStyle { Index: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tools-extra/trunk/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
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
JamesReynolds added a comment. Thank you! Can you land this for me please? This is me done for the time being, but once our implementation gets into the swing of things I'll try and start picking up some bugs / enhancements. https://reviews.llvm.org/D21472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. LG https://reviews.llvm.org/D21472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
JamesReynolds updated the summary for this revision. JamesReynolds updated this revision to Diff 63462. JamesReynolds added a comment. > You mean Upper_Separated and upper_Separated_Back? ;) Actually, these names > are not particularly clear. I've managed to find "Camel_Snake_Case" > used for exactly this naming convention (in the > https://github.com/t6/camel_snake_kebab library). Maybe "camel_Snake_Back" as > well? Thank you, a very good find! I've changed the patch accordingly. http://reviews.llvm.org/D21472 Files: clang-tidy/readability/IdentifierNamingCheck.cpp clang-tidy/readability/IdentifierNamingCheck.h test/clang-tidy/readability-identifier-naming.cpp 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' 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 : Words) { + if ( != ()) +Fixup += "_"; +
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
alexfh added a comment. In http://reviews.llvm.org/D21472#473813, @JamesReynolds wrote: > Ah, I took this from a single example in the CPP core guidelines - that PDF > is indeed a very different style. An idea we toyed with was "UpperSeparated" > and "UpperSeparatedBack"? Would that work? You mean Upper_Separated and upper_Separated_Back? ;) Actually, these names are not particularly clear. I've managed to find "Camel_Snake_Case" used for exactly this naming convention (in the https://github.com/t6/camel_snake_kebab library). Maybe "camel_Snake_Back" as well? > This comes from ... I just wanted to hear that this is actually going to be used. No objections. http://reviews.llvm.org/D21472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
JamesReynolds added a comment. Ah, I took this from a single example in the CPP core guidelines - that PDF is indeed a very different style. An idea we toyed with was "UpperSeparated" and "UpperSeparatedBack"? Would that work? This comes from a concession to Window developers in a large commercial codebase with a Windows origin. I'll admit it isn't my favourite style but for class names and functions it eventually grows on you. At least I got them to let go of the SHOUTING_TYPEDEFS..! http://reviews.llvm.org/D21472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
JamesReynolds added a comment. I'm not 100% sure that my regexes are the best balance between readability and terseness - or that I've named the case types particularly well. If there are better ideas for either of those things I'm very happy to accept criticism! http://reviews.llvm.org/D21472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types
JamesReynolds created this revision. JamesReynolds added a reviewer: alexfh. JamesReynolds added a subscriber: cfe-commits. Added Stroustrup_Case and stroustrup_Back (http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-naming) ``` class Stroustrup_Case_Class_Name { void private_Stroustrup_Back_Method_Name(); } ``` http://reviews.llvm.org/D21472 Files: clang-tidy/readability/IdentifierNamingCheck.cpp clang-tidy/readability/IdentifierNamingCheck.h test/clang-tidy/readability-identifier-naming.cpp 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: Stroustrup_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: stroustrup_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' 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_StroustrupCase, +CT_StroustrupBack }; 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("Stroustrup_Case", CT_StroustrupCase) +.Case("stroustrup_Back", CT_StroustrupBack) .Default(CT_AnyCase); }; @@ -189,6 +191,10 @@ return "UPPER_CASE"; case CT_CamelCase: return "CamelCase"; +case CT_StroustrupCase: + return "Stroustrup_Case"; +case CT_StroustrupBack: + return "stroustrup_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_StroustrupCase: +for (auto const : Words) { + if ( != ()) +Fixup += "_"; + Fixup += Word.substr(0, 1).upper(); + Fixup += Word.substr(1).lower(); +} +break; + + case IdentifierNamingCheck::CT_StroustrupBack: +for (auto const :