Skip to content

Commit

Permalink
Support special acronyms inside property names and allow plural forms
Browse files Browse the repository at this point in the history
Reviewers: benhamilton, hokein

Reviewed By: benhamilton, hokein

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D42947

llvm-svn: 324407
  • Loading branch information
ynzhang0509 committed Feb 6, 2018
1 parent f3fb983 commit ae5bc5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
Expand Up @@ -12,8 +12,8 @@
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/STLExtras.h"
#include "clang/Basic/CharInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Regex.h"

Expand Down Expand Up @@ -118,6 +118,12 @@ FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, NamingStyle Style) {
return FixItHint();
}

std::string AcronymsGroupRegex(llvm::ArrayRef<std::string> EscapedAcronyms) {
return "(" +
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
"s?)";
}

std::string validPropertyNameRegex(llvm::ArrayRef<std::string> EscapedAcronyms,
bool UsedInMatcher) {
// Allow any of these names:
Expand All @@ -129,12 +135,9 @@ std::string validPropertyNameRegex(llvm::ArrayRef<std::string> EscapedAcronyms,
// URLString
// bundleID
std::string StartMatcher = UsedInMatcher ? "::" : "^";

return StartMatcher + "((" +
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
")?$";
std::string AcronymsMatcher = AcronymsGroupRegex(EscapedAcronyms);
return StartMatcher + "(" + AcronymsMatcher + "[A-Z]?)?[a-z]+[a-z0-9]*(" +
AcronymsMatcher + "|([A-Z][a-z0-9]+))*$";
}

bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/test/clang-tidy/objc-property-declaration.m
Expand Up @@ -14,6 +14,9 @@ @interface Foo
@property(strong, nonatomic) UIViewController *notificationsVC;
@property(strong, nonatomic) NSString *URL_string;
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
@property(strong, nonatomic) NSString *supportURLsCamelCase;
@property(strong, nonatomic) NSString *supportURLCamelCase;
@property(strong, nonatomic) NSString *VCsPluralToAdd;
@end

@interface Foo (Bar)
Expand Down

0 comments on commit ae5bc5a

Please sign in to comment.