Skip to content

Commit

Permalink
add ID as a special acronym to objc property declaration check for pr…
Browse files Browse the repository at this point in the history
…operty 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
  • Loading branch information
ynzhang0509 committed Jan 17, 2018
1 parent c07e0bd commit 8c298d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
Expand Up @@ -41,7 +41,8 @@ constexpr char DefaultSpecialAcronyms[] =
"RGB;"
"CMYK;"
"MIDI;"
"FTP";
"FTP;"
"ID";

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

std::string validPropertyNameRegex(const std::vector<std::string> &Prefixes) {
std::vector<std::string> EscapedPrefixes;
EscapedPrefixes.reserve(Prefixes.size());
std::string validPropertyNameRegex(const std::vector<std::string> &Acronyms) {
std::vector<std::string> EscapedAcronyms;
EscapedAcronyms.reserve(Acronyms.size());
// In case someone defines a custom prefix which includes a regex
// special character, escape all the prefixes.
std::transform(Prefixes.begin(), Prefixes.end(),
std::back_inserter(EscapedPrefixes), [](const std::string& s) {
std::transform(Acronyms.begin(), Acronyms.end(),
std::back_inserter(EscapedAcronyms), [](const std::string& s) {
return llvm::Regex::escape(s); });
// Allow any of these names:
// foo
Expand All @@ -73,9 +74,11 @@ std::string validPropertyNameRegex(const std::vector<std::string> &Prefixes) {
// urlString
// URL
// URLString
// bundleID
return std::string("::((") +
llvm::join(EscapedPrefixes.begin(), EscapedPrefixes.end(), "|") +
")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*$";
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") + ")?$";
}
} // namespace

Expand Down
Expand Up @@ -7,6 +7,7 @@ @interface Foo
// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
@property(assign, nonatomic) int camelCase;
@property(strong, nonatomic) NSString *URLString;
@property(strong, nonatomic) NSString *bundleID;
@property(strong, nonatomic) NSString *URL_string;
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
@end

0 comments on commit 8c298d2

Please sign in to comment.