[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
This revision was automatically updated to reflect the committed changes. Closed by commit rL301431: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing… (authored by alexfh). Changed prior to commit: https://reviews.llvm.org/D32333?vs=96762=96771#toc Repository: rL LLVM https://reviews.llvm.org/D32333 Files: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; 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 @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.empty()) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; 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 @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.empty()) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
alexfh added a comment. In https://reviews.llvm.org/D32333#738266, @jtbandes wrote: > Done, thanks for the review! > > What is the procedure for merging patches in? I'm sure I don't have > permissions to do it myself. I'll commit the patch for you. Thank you for working on this! https://reviews.llvm.org/D32333 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
jtbandes marked an inline comment as done. jtbandes added a comment. Done, thanks for the review! What is the procedure for merging patches in? I'm sure I don't have permissions to do it myself. https://reviews.llvm.org/D32333 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
jtbandes updated this revision to Diff 96762. jtbandes added a comment. Fixed nit https://reviews.llvm.org/D32333 Files: clang-tidy/readability/IdentifierNamingCheck.cpp 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.empty()) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( Index: test/clang-tidy/readability-identifier-naming.cpp === --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.empty()) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. LG with a nit. Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:378 + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; Mid.empty() https://reviews.llvm.org/D32333 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
jtbandes updated this revision to Diff 96181. jtbandes added a comment. Cleanup https://reviews.llvm.org/D32333 Files: clang-tidy/readability/IdentifierNamingCheck.cpp 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( Index: test/clang-tidy/readability-identifier-naming.cpp === --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
jtbandes updated this revision to Diff 96180. jtbandes edited the summary of this revision. jtbandes added a comment. Remove unnecessary checks for empty prefix/suffix https://reviews.llvm.org/D32333 Files: clang-tidy/readability/IdentifierNamingCheck.cpp 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,13 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_")) +Matches = false; + if (Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +374,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( Index: test/clang-tidy/readability-identifier-naming.cpp === --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,13 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_")) +Matches = false; + if (Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +374,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
jtbandes created this revision. The goal of this change is to fix the following suboptimal replacements currently suggested by clang-tidy: // with MemberPrefix == "_" int __foo; // accepted without complaint // with MemberPrefix == "m_" int _foo; ^~ m__foo I fixed this by - updating `matchesStyle()` to reject names which have a leading underscore after a prefix has already been stripped, or a trailing underscore if a suffix has already been stripped; - updating `fixupWithStyle()` to strip leading & trailing underscores before adding the user-defined prefix and suffix. The replacements are now: // MemberPrefix == "_" int __foo; ^~ _foo // MemberPrefix == "m_" int _foo; ^ m_foo Future improvements might elect to add .clang-tidy flags to improve what is being stripped. For instance, stripping `m_` could allow `m_foo` to be automatically replaced with `_foo`. https://reviews.llvm.org/D32333 Files: clang-tidy/readability/IdentifierNamingCheck.cpp 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 @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,13 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (!Style.Prefix.empty() && Name.startswith("_")) +Matches = false; + if (!Style.Suffix.empty() && Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +374,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( Index: test/clang-tidy/readability-identifier-naming.cpp === --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3; Index: clang-tidy/readability/IdentifierNamingCheck.cpp === --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,13 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (!Style.Prefix.empty() && Name.startswith("_")) +Matches = false; + if (!Style.Suffix.empty() && Name.endswith("_")) +Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +374,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle ) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.size() == 0) +Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind(