[PATCH] D32333: [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
Alexander Kornienko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 09:52:06 PDT 2017
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&id=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<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.96771.patch
Type: text/x-patch
Size: 2020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170426/1fd0ceac/attachment.bin>
More information about the cfe-commits
mailing list