[clang-tools-extra] r276110 - [clang-tidy] readability-identifier-naming - support for other case types

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 20 05:28:38 PDT 2016


Author: omtcyfz
Date: Wed Jul 20 07:28:38 2016
New Revision: 276110

URL: http://llvm.org/viewvc/llvm-project?rev=276110&view=rev
Log:
[clang-tidy] readability-identifier-naming - support for other case types

Added Camel_Snake_Case and camel_Snake_Back

class Camel_Snake_Case_Class_Name
{
  void private_Camel_Snake_Back_Method_Name();
}

Patch by James Reynolds!

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D21472


Modified:
    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

Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=276110&r1=276109&r2=276110&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Wed Jul 20 07:28:38 2016
@@ -163,6 +163,8 @@ IdentifierNamingCheck::IdentifierNamingC
         .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 @@ void IdentifierNamingCheck::storeOptions
       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 @@ static bool matchesStyle(StringRef Name,
       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 @@ static std::string fixupWithCase(StringR
       }
     }
     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;

Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h?rev=276110&r1=276109&r2=276110&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h Wed Jul 20 07:28:38 2016
@@ -48,6 +48,8 @@ public:
     CT_CamelBack,
     CT_UpperCase,
     CT_CamelCase,
+    CT_CamelSnakeCase,
+    CT_CamelSnakeBack
   };
 
   struct NamingStyle {

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp?rev=276110&r1=276109&r2=276110&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp Wed Jul 20 07:28:38 2016
@@ -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 @@ class abstract_class {
 // 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 @@ struct_type GlobalTypedefTestFunction(st
 
 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<typename t_t>
 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'




More information about the cfe-commits mailing list