[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
Jacob Bandes-Storch via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 09:33:30 PDT 2017
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<size_t>(*Style.Case)].match(Name))
Matches = false;
@@ -367,10 +372,12 @@
static std::string
fixupWithStyle(StringRef Name,
const IdentifierNamingCheck::NamingStyle &Style) {
- 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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32333.96762.patch
Type: text/x-patch
Size: 1876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170426/dcbb316c/attachment-0001.bin>
More information about the cfe-commits
mailing list