Skip to content

Commit 8c298d2

Browse files
committedJan 17, 2018
add ID as a special acronym to objc property declaration check for property names like bundleID.allow using acronyms as suffix.
Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42143 llvm-svn: 322602
1 parent c07e0bd commit 8c298d2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
 

‎clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ constexpr char DefaultSpecialAcronyms[] =
4141
"RGB;"
4242
"CMYK;"
4343
"MIDI;"
44-
"FTP";
44+
"FTP;"
45+
"ID";
4546

4647
/// For now we will only fix 'CamelCase' property to
4748
/// 'camelCase'. For other cases the users need to
@@ -58,13 +59,13 @@ FixItHint generateFixItHint(const ObjCPropertyDecl *Decl) {
5859
return FixItHint();
5960
}
6061

61-
std::string validPropertyNameRegex(const std::vector<std::string> &Prefixes) {
62-
std::vector<std::string> EscapedPrefixes;
63-
EscapedPrefixes.reserve(Prefixes.size());
62+
std::string validPropertyNameRegex(const std::vector<std::string> &Acronyms) {
63+
std::vector<std::string> EscapedAcronyms;
64+
EscapedAcronyms.reserve(Acronyms.size());
6465
// In case someone defines a custom prefix which includes a regex
6566
// special character, escape all the prefixes.
66-
std::transform(Prefixes.begin(), Prefixes.end(),
67-
std::back_inserter(EscapedPrefixes), [](const std::string& s) {
67+
std::transform(Acronyms.begin(), Acronyms.end(),
68+
std::back_inserter(EscapedAcronyms), [](const std::string& s) {
6869
return llvm::Regex::escape(s); });
6970
// Allow any of these names:
7071
// foo
@@ -73,9 +74,11 @@ std::string validPropertyNameRegex(const std::vector<std::string> &Prefixes) {
7374
// urlString
7475
// URL
7576
// URLString
77+
// bundleID
7678
return std::string("::((") +
77-
llvm::join(EscapedPrefixes.begin(), EscapedPrefixes.end(), "|") +
78-
")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*$";
79+
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
80+
")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
81+
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") + ")?$";
7982
}
8083
} // namespace
8184

‎clang-tools-extra/test/clang-tidy/objc-property-declaration.m

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ @interface Foo
77
// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
88
@property(assign, nonatomic) int camelCase;
99
@property(strong, nonatomic) NSString *URLString;
10+
@property(strong, nonatomic) NSString *bundleID;
1011
@property(strong, nonatomic) NSString *URL_string;
1112
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
1213
@end

0 commit comments

Comments
 (0)
Please sign in to comment.