[PATCH] D42947: Support special acronyms inside property names and allow plural forms
Yan Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 5 22:37:27 PST 2018
Wizard created this revision.
Herald added subscribers: cfe-commits, klimek.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D42947
Files:
clang-tidy/objc/PropertyDeclarationCheck.cpp
docs/clang-tidy/checks/objc-property-declaration.rst
test/clang-tidy/objc-property-declaration.m
Index: test/clang-tidy/objc-property-declaration.m
===================================================================
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -14,6 +14,7 @@
@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]
+ at property(strong, nonatomic) NSString *supportURLsCamelCase;
@end
@interface Foo (Bar)
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===================================================================
--- docs/clang-tidy/checks/objc-property-declaration.rst
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -36,8 +36,12 @@
lowercase letters followed by a '_' to avoid naming conflict. For example:
.. code-block:: objc
+<<<<<<< HEAD
+ at property(nonatomic, assign) int abc_lowerCamelCase;
+=======
@property(nonatomic, assign) int abc_lowerCamelCase;
+>>>>>>> d0b498636947064abd7c3ea08e728cf668b54e14
The corresponding style rule: https://developer.apple.com/library/content/qa/qa1908/_index.html
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===================================================================
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -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"
@@ -118,6 +118,15 @@
return FixItHint();
}
+std::string AcronymsGroupRegex(llvm::ArrayRef<std::string> EscapedAcronyms,
+ bool SupportPlural) {
+ std::string Spliter = SupportPlural ? "s?|" : "|";
+ std::string RegexEnd = SupportPlural ? "s?)" : ")";
+ return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), Spliter) +
+ RegexEnd;
+}
+
std::string validPropertyNameRegex(llvm::ArrayRef<std::string> EscapedAcronyms,
bool UsedInMatcher) {
// Allow any of these names:
@@ -130,11 +139,9 @@
// 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(), "|") +
- ")?$";
+ return StartMatcher + "(" + AcronymsGroupRegex(EscapedAcronyms, false) +
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" +
+ AcronymsGroupRegex(EscapedAcronyms, true) + "|([A-Z][a-z0-9]+))*$";
}
bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42947.132937.patch
Type: text/x-patch
Size: 3022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180206/90128223/attachment-0001.bin>
More information about the cfe-commits
mailing list