Skip to content

[clang-tidy] Improve alternate snake case warnings #71385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ bool IdentifierNamingCheck::matchesStyle(
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])?)*"),
llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
};

Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ Changes in existing checks
``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
has been enhanced, particularly within complex types like function pointers
and cases where style checks were omitted when functions started with macros.
Added support for C++20 ``concept`` declarations.
Added support for C++20 ``concept`` declarations. ``Camel_Snake_Case`` and
``camel_Snake_Case`` now detect more invalid identifier names.

- Improved :doc:`readability-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
// RUN: -config='{CheckOptions: { \
// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
// RUN: }}'

// clang-format off

//===----------------------------------------------------------------------===//
// Camel_Snake_Case tests
//===----------------------------------------------------------------------===//
class XML_Parser {};
class Xml_Parser {};
class XML_Parser_2 {};
// NO warnings or fixes expected as these identifiers are Camel_Snake_Case

class XmlParser {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'XmlParser'
// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}

class Xml_parser {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'Xml_parser'
// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}

class xml_parser {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'xml_parser'
// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}

class xml_Parser {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'xml_Parser'
// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}

class xml_Parser_2 {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'xml_Parser_2'
// CHECK-FIXES: {{^}}class Xml_Parser_2 {};{{$}}

class t {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 't'
// CHECK-FIXES: {{^}}class T {};{{$}}

//===----------------------------------------------------------------------===//
// camel_Snake_Back tests
//===----------------------------------------------------------------------===//
struct json_Parser {};
struct json_Parser_2 {};
struct u {};
// NO warnings or fixes expected as these identifiers are camel_Snake_Back

struct JsonParser {};
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'JsonParser'
// CHECK-FIXES: {{^}}struct json_Parser {};{{$}}

struct Json_parser {};
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'Json_parser'
// CHECK-FIXES: {{^}}struct json_Parser {};{{$}}

struct json_parser {};
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'json_parser'
// CHECK-FIXES: {{^}}struct json_Parser {};{{$}}

Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ class my_other_templated_class : my_templated_class< my_class>, private my_deri

template<typename t_t>
using mysuper_tpl_t = my_other_templated_class <:: FOO_NS ::my_class>;
// CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'mysuper_tpl_t'
// CHECK-FIXES: {{^}}using mysuper_Tpl_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}

const int global_Constant = 6;
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
Expand Down