[clang-tools-extra] 9c4df9e - [clang-tidy] Support IgnoredRegexp configuration to selectively suppress identifier naming checks

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 17:19:00 PST 2020


Author: smhc
Date: 2020-11-25T01:18:44Z
New Revision: 9c4df9eecb6ca6b53d919cec9b460de46dd40302

URL: https://github.com/llvm/llvm-project/commit/9c4df9eecb6ca6b53d919cec9b460de46dd40302
DIFF: https://github.com/llvm/llvm-project/commit/9c4df9eecb6ca6b53d919cec9b460de46dd40302.diff

LOG: [clang-tidy] Support IgnoredRegexp configuration to selectively suppress identifier naming checks

The idea of suppressing naming checks for variables is to support code bases that allow short variables named e.g 'x' and 'i' without prefix/suffixes or casing styles. This was originally proposed as a 'ShortSizeThreshold' however has been made more generic with a regex to suppress identifier naming checks for those that match.

Reviewed By: njames93, aaron.ballman

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

Added: 
    clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp

Modified: 
    clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
    clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
    clang-tools-extra/docs/ReleaseNotes.rst
    clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index d7160d52750f..efc683c6c05d 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -122,14 +122,32 @@ static StringRef const StyleNames[] = {
 #undef NAMING_KEYS
 // clang-format on
 
+IdentifierNamingCheck::NamingStyle::NamingStyle(
+    llvm::Optional<IdentifierNamingCheck::CaseType> Case,
+    const std::string &Prefix, const std::string &Suffix,
+    const std::string &IgnoredRegexpStr)
+    : Case(Case), Prefix(Prefix), Suffix(Suffix),
+      IgnoredRegexpStr(IgnoredRegexpStr) {
+  if (!IgnoredRegexpStr.empty()) {
+    IgnoredRegexp =
+        llvm::Regex(llvm::SmallString<128>({"^", IgnoredRegexpStr, "$"}));
+    if (!IgnoredRegexp.isValid())
+      llvm::errs() << "Invalid IgnoredRegexp regular expression: "
+                   << IgnoredRegexpStr;
+  }
+}
+
 static IdentifierNamingCheck::FileStyle
 getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
-  SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles(
-      SK_Count);
+  SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles;
+  Styles.resize(SK_Count);
   SmallString<64> StyleString;
   for (unsigned I = 0; I < SK_Count; ++I) {
     StyleString = StyleNames[I];
     size_t StyleSize = StyleString.size();
+    StyleString.append("IgnoredRegexp");
+    std::string IgnoredRegexpStr = Options.get(StyleString, "");
+    StyleString.resize(StyleSize);
     StyleString.append("Prefix");
     std::string Prefix(Options.get(StyleString, ""));
     // Fast replacement of [Pre]fix -> [Suf]fix.
@@ -141,9 +159,10 @@ getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
     auto CaseOptional =
         Options.getOptional<IdentifierNamingCheck::CaseType>(StyleString);
 
-    if (CaseOptional || !Prefix.empty() || !Postfix.empty())
+    if (CaseOptional || !Prefix.empty() || !Postfix.empty() ||
+        !IgnoredRegexpStr.empty())
       Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
-                        std::move(Postfix));
+                        std::move(Postfix), std::move(IgnoredRegexpStr));
   }
   bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
   return {std::move(Styles), IgnoreMainLike};
@@ -175,6 +194,9 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
       continue;
     StyleString = StyleNames[I];
     size_t StyleSize = StyleString.size();
+    StyleString.append("IgnoredRegexp");
+    Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr);
+    StyleString.resize(StyleSize);
     StyleString.append("Prefix");
     Options.store(Opts, StyleString, Styles[I]->Prefix);
     // Fast replacement of [Pre]fix -> [Suf]fix.
@@ -194,7 +216,7 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 static bool matchesStyle(StringRef Name,
-                         IdentifierNamingCheck::NamingStyle Style) {
+                         const IdentifierNamingCheck::NamingStyle &Style) {
   static llvm::Regex Matchers[] = {
       llvm::Regex("^.*$"),
       llvm::Regex("^[a-z][a-z0-9_]*$"),
@@ -681,6 +703,9 @@ static llvm::Optional<RenamerClangTidyCheck::FailureInfo> getFailureInfo(
     return None;
 
   const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
+  if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
+    return None;
+
   if (matchesStyle(Name, Style))
     return None;
 

diff  --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
index 77c03f77d91d..565eb9d11474 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -52,12 +52,18 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
     NamingStyle() = default;
 
     NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix,
-                const std::string &Suffix)
-        : Case(Case), Prefix(Prefix), Suffix(Suffix) {}
+                const std::string &Suffix, const std::string &IgnoredRegexpStr);
+    NamingStyle(const NamingStyle &O) = delete;
+    NamingStyle &operator=(NamingStyle &&O) = default;
+    NamingStyle(NamingStyle &&O) = default;
 
     llvm::Optional<CaseType> Case;
     std::string Prefix;
     std::string Suffix;
+    // Store both compiled and non-compiled forms so original value can be
+    // serialized
+    llvm::Regex IgnoredRegexp;
+    std::string IgnoredRegexpStr;
   };
 
   struct FileStyle {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index c99a589b1212..46bb36c271d3 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Changes in existing checks
   Added support for specifying the style of scoped ``enum`` constants. If 
   unspecified, will fall back to the style for regular ``enum`` constants.
 
+  Added an option `IgnoredRegexp` per identifier type to suppress identifier
+  naming checks for names matching a regular expression.
+
 - Removed `google-runtime-references` check because the rule it checks does
   not exist in the Google Style Guide anymore.
 

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
index 036103e7e80e..b744d21b6ff8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -35,60 +35,60 @@ Options
 
 The following options are describe below:
 
- - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`
+ - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`, :option:`AbstractClassIgnoredRegexp`
  - :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:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`, :option:`ClassIgnoredRegexp`
+ - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`
+ - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`
+ - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
+ - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, :option:`ConstantIgnoredRegexp`
+ - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`
+ - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`
+ - :option:`ConstantPointerParameterCase`, :option:`ConstantPointerParameterPrefix`, :option:`ConstantPointerParameterSuffix`, :option:`ConstantPointerParameterIgnoredRegexp`
+ - :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`, :option:`ConstexprFunctionSuffix`, :option:`ConstexprFunctionIgnoredRegexp`
+ - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`, :option:`ConstexprMethodSuffix`, :option:`ConstexprMethodIgnoredRegexp`
+ - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, :option:`ConstexprVariableSuffix`, :option:`ConstexprVariableIgnoredRegexp`
+ - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`, :option:`EnumIgnoredRegexp`
+ - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`, :option:`EnumConstantIgnoredRegexp`
+ - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`, :option:`FunctionIgnoredRegexp`
  - :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:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`, :option:`GlobalConstantIgnoredRegexp`
+ - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`, :option:`GlobalConstantPointerIgnoredRegexp`
+ - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`, :option:`GlobalFunctionIgnoredRegexp`
+ - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`, :option:`GlobalPointerIgnoredRegexp`
+ - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`, :option:`GlobalVariableIgnoredRegexp`
  - :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:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`
- - :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`
+ - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix`, :option:`InlineNamespaceIgnoredRegexp`
+ - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`, :option:`LocalConstantIgnoredRegexp`
+ - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`, :option:`LocalConstantPointerIgnoredRegexp`
+ - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`, :option:`LocalPointerIgnoredRegexp`
+ - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix`, :option:`LocalVariableIgnoredRegexp`
+ - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, :option:`MacroDefinitionSuffix`, :option:`MacroDefinitionIgnoredRegexp`
+ - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`, :option:`MemberIgnoredRegexp`
+ - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`, :option:`MethodIgnoredRegexp`
+ - :option:`NamespaceCase`, :option:`NamespacePrefix`, :option:`NamespaceSuffix`, :option:`NamespaceIgnoredRegexp`
+ - :option:`ParameterCase`, :option:`ParameterPrefix`, :option:`ParameterSuffix`, :option:`ParameterIgnoredRegexp`
+ - :option:`ParameterPackCase`, :option:`ParameterPackPrefix`, :option:`ParameterPackSuffix`, :option:`ParameterPackIgnoredRegexp`
+ - :option:`PointerParameterCase`, :option:`PointerParameterPrefix`, :option:`PointerParameterSuffix`, :option:`PointerParameterIgnoredRegexp`
+ - :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`, :option:`PrivateMemberSuffix`, :option:`PrivateMemberIgnoredRegexp`
+ - :option:`PrivateMethodCase`, :option:`PrivateMethodPrefix`, :option:`PrivateMethodSuffix`, :option:`PrivateMethodIgnoredRegexp`
+ - :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`, :option:`ProtectedMemberSuffix`, :option:`ProtectedMemberIgnoredRegexp`
+ - :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`, :option:`ProtectedMethodSuffix`, :option:`ProtectedMethodIgnoredRegexp`
+ - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`, :option:`PublicMemberIgnoredRegexp`
+ - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`, :option:`PublicMethodIgnoredRegexp`
+ - :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`, :option:`ScopedEnumConstantIgnoredRegexp`
+ - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`, :option:`StaticConstantIgnoredRegexp`
+ - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`, :option:`StaticVariableIgnoredRegexp`
+ - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`, :option:`StructIgnoredRegexp`
+ - :option:`TemplateParameterCase`, :option:`TemplateParameterPrefix`, :option:`TemplateParameterSuffix`, :option:`TemplateParameterIgnoredRegexp`
+ - :option:`TemplateTemplateParameterCase`, :option:`TemplateTemplateParameterPrefix`, :option:`TemplateTemplateParameterSuffix`, :option:`TemplateTemplateParameterIgnoredRegexp`
+ - :option:`TypeAliasCase`, :option:`TypeAliasPrefix`, :option:`TypeAliasSuffix`, :option:`TypeAliasIgnoredRegexp`
+ - :option:`TypedefCase`, :option:`TypedefPrefix`, :option:`TypedefSuffix`, :option:`TypedefIgnoredRegexp`
+ - :option:`TypeTemplateParameterCase`, :option:`TypeTemplateParameterPrefix`, :option:`TypeTemplateParameterSuffix`, :option:`TypeTemplateParameterIgnoredRegexp`
+ - :option:`UnionCase`, :option:`UnionPrefix`, :option:`UnionSuffix`, :option:`UnionIgnoredRegexp`
+ - :option:`ValueTemplateParameterCase`, :option:`ValueTemplateParameterPrefix`, :option:`ValueTemplateParameterSuffix`, :option:`ValueTemplateParameterIgnoredRegexp`
+ - :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix`, :option:`VariableIgnoredRegexp`
+ - :option:`VirtualMethodCase`, :option:`VirtualMethodPrefix`, :option:`VirtualMethodSuffix`, :option:`VirtualMethodIgnoredRegexp`
 
 .. option:: AbstractClassCase
 
@@ -100,6 +100,11 @@ The following options are describe below:
     When defined, the check will ensure abstract class names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: AbstractClassIgnoredRegexp
+
+    Identifier naming checks won't be enforced for abstract class names
+    matching this regular expression.
+
 .. option:: AbstractClassSuffix
 
     When defined, the check will ensure abstract class names will add the
@@ -199,6 +204,11 @@ After if AggressiveDependentMemberLookup is ``1``:
     When defined, the check will ensure class names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ClassIgnoredRegexp
+
+    Identifier naming checks won't be enforced for class names matching
+    this regular expression.
+
 .. option:: ClassSuffix
 
     When defined, the check will ensure class names will add the
@@ -242,6 +252,11 @@ After:
     When defined, the check will ensure class constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ClassConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for class constant names
+    matching this regular expression.
+
 .. option:: ClassConstantSuffix
 
     When defined, the check will ensure class constant names will add the
@@ -283,6 +298,11 @@ After:
     When defined, the check will ensure class member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ClassMemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for class member names
+    matching this regular expression.
+
 .. option:: ClassMemberSuffix
 
     When defined, the check will ensure class member names will add the
@@ -324,6 +344,11 @@ After:
     When defined, the check will ensure class method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ClassMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for class method names
+    matching this regular expression.
+
 .. option:: ClassMethodSuffix
 
     When defined, the check will ensure class method names will add the
@@ -365,6 +390,11 @@ After:
     When defined, the check will ensure constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constant names
+    matching this regular expression.
+
 .. option:: ConstantSuffix
 
     When defined, the check will ensure constant names will add the
@@ -400,6 +430,11 @@ After:
     When defined, the check will ensure constant member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstantMemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constant member names
+    matching this regular expression.
+
 .. option:: ConstantMemberSuffix
 
     When defined, the check will ensure constant member names will add the
@@ -439,6 +474,11 @@ After:
     When defined, the check will ensure constant parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstantParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constant parameter names
+    matching this regular expression.
+
 .. option:: ConstantParameterSuffix
 
     When defined, the check will ensure constant parameter names will add the
@@ -474,6 +514,11 @@ After:
     When defined, the check will ensure constant pointer parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstantPointerParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constant pointer parameter
+    names matching this regular expression.
+
 .. option:: ConstantPointerParameterSuffix
 
     When defined, the check will ensure constant pointer parameter names will add the
@@ -509,6 +554,11 @@ After:
     When defined, the check will ensure constexpr function names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstexprFunctionIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constexpr function names
+    matching this regular expression.
+
 .. option:: ConstexprFunctionSuffix
 
     When defined, the check will ensure constexpr function names will add the
@@ -544,6 +594,11 @@ After:
     When defined, the check will ensure constexpr method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstexprMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constexpr method names
+    matching this regular expression.
+
 .. option:: ConstexprMethodSuffix
 
     When defined, the check will ensure constexpr method names will add the
@@ -585,6 +640,11 @@ After:
     When defined, the check will ensure constexpr variable names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ConstexprVariableIgnoredRegexp
+
+    Identifier naming checks won't be enforced for constexpr variable names
+    matching this regular expression.
+
 .. option:: ConstexprVariableSuffix
 
     When defined, the check will ensure constexpr variable names will add the
@@ -620,6 +680,11 @@ After:
     When defined, the check will ensure enumeration names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: EnumConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for enumeration names
+    matching this regular expression.
+
 .. option:: EnumSuffix
 
     When defined, the check will ensure enumeration names will add the
@@ -655,6 +720,11 @@ After:
     When defined, the check will ensure enumeration constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: EnumConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for enumeration constant names
+    matching this regular expression.
+
 .. option:: EnumConstantSuffix
 
     When defined, the check will ensure enumeration constant names will add the
@@ -690,6 +760,11 @@ After:
     When defined, the check will ensure function names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: FunctionIgnoredRegexp
+
+    Identifier naming checks won't be enforced for function names
+    matching this regular expression.
+
 .. option:: FunctionSuffix
 
     When defined, the check will ensure function names will add the
@@ -732,6 +807,11 @@ After:
     When defined, the check will ensure global constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: GlobalConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for global constant names
+    matching this regular expression.
+
 .. option:: GlobalConstantSuffix
 
     When defined, the check will ensure global constant names will add the
@@ -767,6 +847,11 @@ After:
     When defined, the check will ensure global constant pointer names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: GlobalConstantPointerIgnoredRegexp
+
+    Identifier naming checks won't be enforced for global constant pointer
+    names matching this regular expression.
+
 .. option:: GlobalConstantPointerSuffix
 
     When defined, the check will ensure global constant pointer names will add the
@@ -802,6 +887,11 @@ After:
     When defined, the check will ensure global function names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: GlobalFunctionIgnoredRegexp
+
+    Identifier naming checks won't be enforced for global function names
+    matching this regular expression.
+
 .. option:: GlobalFunctionSuffix
 
     When defined, the check will ensure global function names will add the
@@ -837,6 +927,11 @@ After:
     When defined, the check will ensure global pointer names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: GlobalPointerIgnoredRegexp
+
+    Identifier naming checks won't be enforced for global pointer names
+    matching this regular expression.
+
 .. option:: GlobalPointerSuffix
 
     When defined, the check will ensure global pointer names will add the
@@ -872,6 +967,11 @@ After:
     When defined, the check will ensure global variable names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: GlobalVariableIgnoredRegexp
+
+    Identifier naming checks won't be enforced for global variable names
+    matching this regular expression.
+
 .. option:: GlobalVariableSuffix
 
     When defined, the check will ensure global variable names will add the
@@ -913,6 +1013,11 @@ After:
     When defined, the check will ensure inline namespaces names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: InlineNamespaceIgnoredRegexp
+
+    Identifier naming checks won't be enforced for inline namespaces names
+    matching this regular expression.
+
 .. option:: InlineNamespaceSuffix
 
     When defined, the check will ensure inline namespaces names will add the
@@ -956,6 +1061,11 @@ After:
     When defined, the check will ensure local constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: LocalConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for local constant names
+    matching this regular expression.
+
 .. option:: LocalConstantSuffix
 
     When defined, the check will ensure local constant names will add the
@@ -991,6 +1101,11 @@ After:
     When defined, the check will ensure local constant pointer names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: LocalConstantPointerIgnoredRegexp
+
+    Identifier naming checks won't be enforced for local constant pointer names
+    matching this regular expression.
+
 .. option:: LocalConstantPointerSuffix
 
     When defined, the check will ensure local constant pointer names will add the
@@ -1026,6 +1141,11 @@ After:
     When defined, the check will ensure local pointer names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: LocalPointerIgnoredRegexp
+
+    Identifier naming checks won't be enforced for local pointer names
+    matching this regular expression.
+
 .. option:: LocalPointerSuffix
 
     When defined, the check will ensure local pointer names will add the
@@ -1061,6 +1181,19 @@ After:
     When defined, the check will ensure local variable names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: LocalVariableIgnoredRegexp
+
+    Identifier naming checks won't be enforced for local variable names
+    matching this regular expression.
+
+For example using values of:
+
+   - LocalVariableCase of ``CamelCase``
+   - LocalVariableIgnoredRegexp of ``\w{1,2}``
+
+Will exclude variables with a length less than or equal to 2 from the
+camel case check applied to other variables.
+
 .. option:: LocalVariableSuffix
 
     When defined, the check will ensure local variable names will add the
@@ -1096,6 +1229,11 @@ After:
     When defined, the check will ensure macro definitions will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: MacroDefinitionIgnoredRegexp
+
+    Identifier naming checks won't be enforced for macro definitions
+    matching this regular expression.
+
 .. option:: MacroDefinitionSuffix
 
     When defined, the check will ensure macro definitions will add the
@@ -1134,6 +1272,11 @@ using the ``-D`` flag.
     When defined, the check will ensure member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: MemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for member names
+    matching this regular expression.
+
 .. option:: MemberSuffix
 
     When defined, the check will ensure member names will add the
@@ -1173,6 +1316,11 @@ After:
     When defined, the check will ensure method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: MethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for method names
+    matching this regular expression.
+
 .. option:: MethodSuffix
 
     When defined, the check will ensure method names will add the
@@ -1212,6 +1360,11 @@ After:
     When defined, the check will ensure namespace names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: NamespaceIgnoredRegexp
+
+    Identifier naming checks won't be enforced for namespace names
+    matching this regular expression.
+
 .. option:: NamespaceSuffix
 
     When defined, the check will ensure namespace names will add the
@@ -1251,6 +1404,11 @@ After:
     When defined, the check will ensure parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for parameter names
+    matching this regular expression.
+
 .. option:: ParameterSuffix
 
     When defined, the check will ensure parameter names will add the
@@ -1286,6 +1444,11 @@ After:
     When defined, the check will ensure parameter pack names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ParameterPackIgnoredRegexp
+
+    Identifier naming checks won't be enforced for parameter pack names
+    matching this regular expression.
+
 .. option:: ParameterPackSuffix
 
     When defined, the check will ensure parameter pack names will add the
@@ -1325,6 +1488,11 @@ After:
     When defined, the check will ensure pointer parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: PointerParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for pointer parameter names
+    matching this regular expression.
+
 .. option:: PointerParameterSuffix
 
     When defined, the check will ensure pointer parameter names will add the
@@ -1360,6 +1528,11 @@ After:
     When defined, the check will ensure private member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: PrivateMemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for private member names
+    matching this regular expression.
+
 .. option:: PrivateMemberSuffix
 
     When defined, the check will ensure private member names will add the
@@ -1401,6 +1574,11 @@ After:
     When defined, the check will ensure private method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: PrivateMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for private method names
+    matching this regular expression.
+
 .. option:: PrivateMethodSuffix
 
     When defined, the check will ensure private method names will add the
@@ -1442,6 +1620,11 @@ After:
     When defined, the check will ensure protected member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ProtectedMemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for protected member names
+    matching this regular expression.
+
 .. option:: ProtectedMemberSuffix
 
     When defined, the check will ensure protected member names will add the
@@ -1475,17 +1658,22 @@ After:
 
 .. option:: ProtectedMethodCase
 
-    When defined, the check will ensure protect method names conform to the
+    When defined, the check will ensure protected method names conform to the
     selected casing.
 
 .. option:: ProtectedMethodPrefix
 
-    When defined, the check will ensure protect method names will add the
+    When defined, the check will ensure protected method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ProtectedMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for protected method names
+    matching this regular expression.
+
 .. option:: ProtectedMethodSuffix
 
-    When defined, the check will ensure protect method names will add the
+    When defined, the check will ensure protected method names will add the
     suffix with the given value (regardless of casing).
 
 For example using values of:
@@ -1524,6 +1712,11 @@ After:
     When defined, the check will ensure public member names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: PublicMemberIgnoredRegexp
+
+    Identifier naming checks won't be enforced for public member names
+    matching this regular expression.
+
 .. option:: PublicMemberSuffix
 
     When defined, the check will ensure public member names will add the
@@ -1565,6 +1758,11 @@ After:
     When defined, the check will ensure public method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: PublicMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for public method names
+    matching this regular expression.
+
 .. option:: PublicMethodSuffix
 
     When defined, the check will ensure public method names will add the
@@ -1606,6 +1804,11 @@ After:
     When defined, the check will ensure scoped enum constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ScopedEnumConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for scoped enum constant names
+    matching this regular expression.
+
 .. option:: ScopedEnumConstantSuffix
 
     When defined, the check will ensure scoped enum constant names will add the
@@ -1641,6 +1844,11 @@ After:
     When defined, the check will ensure static constant names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: StaticConstantIgnoredRegexp
+
+    Identifier naming checks won't be enforced for static constant names
+    matching this regular expression.
+
 .. option:: StaticConstantSuffix
 
     When defined, the check will ensure static constant names will add the
@@ -1676,6 +1884,11 @@ After:
     When defined, the check will ensure static variable names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: StaticVariableIgnoredRegexp
+
+    Identifier naming checks won't be enforced for static variable names
+    matching this regular expression.
+
 .. option:: StaticVariableSuffix
 
     When defined, the check will ensure static variable names will add the
@@ -1711,6 +1924,11 @@ After:
     When defined, the check will ensure struct names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: StructIgnoredRegexp
+
+    Identifier naming checks won't be enforced for struct names
+    matching this regular expression.
+
 .. option:: StructSuffix
 
     When defined, the check will ensure struct names will add the
@@ -1752,6 +1970,11 @@ After:
     When defined, the check will ensure template parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: TemplateParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for template parameter names
+    matching this regular expression.
+
 .. option:: TemplateParameterSuffix
 
     When defined, the check will ensure template parameter names will add the
@@ -1787,6 +2010,11 @@ After:
     When defined, the check will ensure template template parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: TemplateTemplateParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for template template parameter
+    names matching this regular expression.
+
 .. option:: TemplateTemplateParameterSuffix
 
     When defined, the check will ensure template template parameter names will add the
@@ -1824,6 +2052,11 @@ After:
     When defined, the check will ensure type alias names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: TypeAliasIgnoredRegexp
+
+    Identifier naming checks won't be enforced for type alias names
+    matching this regular expression.
+
 .. option:: TypeAliasSuffix
 
     When defined, the check will ensure type alias names will add the
@@ -1859,6 +2092,11 @@ After:
     When defined, the check will ensure typedef names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: TypedefIgnoredRegexp
+
+    Identifier naming checks won't be enforced for typedef names
+    matching this regular expression.
+
 .. option:: TypedefSuffix
 
     When defined, the check will ensure typedef names will add the
@@ -1894,6 +2132,11 @@ After:
     When defined, the check will ensure type template parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: TypeTemplateParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for type template names
+    matching this regular expression.
+
 .. option:: TypeTemplateParameterSuffix
 
     When defined, the check will ensure type template parameter names will add the
@@ -1931,6 +2174,11 @@ After:
     When defined, the check will ensure union names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: UnionIgnoredRegexp
+
+    Identifier naming checks won't be enforced for union names
+    matching this regular expression.
+
 .. option:: UnionSuffix
 
     When defined, the check will ensure union names will add the
@@ -1972,6 +2220,11 @@ After:
     When defined, the check will ensure value template parameter names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: ValueTemplateParameterIgnoredRegexp
+
+    Identifier naming checks won't be enforced for value template parameter
+    names matching this regular expression.
+
 .. option:: ValueTemplateParameterSuffix
 
     When defined, the check will ensure value template parameter names will add the
@@ -2009,6 +2262,11 @@ After:
     When defined, the check will ensure variable names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: VariableIgnoredRegexp
+
+    Identifier naming checks won't be enforced for variable names
+    matching this regular expression.
+
 .. option:: VariableSuffix
 
     When defined, the check will ensure variable names will add the
@@ -2044,6 +2302,11 @@ After:
     When defined, the check will ensure virtual method names will add the
     prefixed with the given value (regardless of casing).
 
+.. option:: VirtualMethodIgnoredRegexp
+
+    Identifier naming checks won't be enforced for virtual method names
+    matching this regular expression.
+
 .. option:: VirtualMethodSuffix
 
     When defined, the check will ensure virtual method names will add the

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
new file mode 100644
index 000000000000..e99edff5cc21
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN:     {key: readability-identifier-naming.ParameterCase, value: CamelCase}, \
+// RUN:     {key: readability-identifier-naming.ParameterIgnoredRegexp, value: "^[a-z]{1,2}$"}, \
+// RUN:     {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
+// RUN:     {key: readability-identifier-naming.ClassIgnoredRegexp, value: "^fo$|^fooo$"}, \
+// RUN:     {key: readability-identifier-naming.StructCase, value: CamelCase}, \
+// RUN:     {key: readability-identifier-naming.StructIgnoredRegexp, value: "sooo|so|soo|$invalidregex["} \
+// RUN:  ]}'
+
+int testFunc(int a, char **b);
+int testFunc(int ab, char **ba);
+int testFunc(int abc, char **cba);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'abc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'cba'
+// CHECK-FIXES: {{^}}int testFunc(int Abc, char **Cba);{{$}}
+int testFunc(int dE, char **eD);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'dE'
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: invalid case style for parameter 'eD'
+// CHECK-FIXES: {{^}}int testFunc(int DE, char **ED);{{$}}
+int testFunc(int Abc, char **Cba);
+
+class fo {
+};
+
+class fofo {
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'fofo'
+  // CHECK-FIXES: {{^}}class Fofo {{{$}}
+};
+
+class foo {
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'foo'
+  // CHECK-FIXES: {{^}}class Foo {{{$}}
+};
+
+class fooo {
+};
+
+class afooo {
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'afooo'
+  // CHECK-FIXES: {{^}}class Afooo {{{$}}
+};
+
+struct soo {
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'soo'
+  // CHECK-FIXES: {{^}}struct Soo {{{$}}
+};


        


More information about the cfe-commits mailing list