[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE324407: Support special acronyms inside property names and 
allow plural forms (authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42947?vs=133069=133071#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -129,12 +135,9 @@
   // 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) {


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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -129,12 +135,9 @@
   // 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]*(" +
+ 

[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 133069.
Wizard added a comment.

minor fix according to comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -129,12 +135,9 @@
   // 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) {


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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -129,12 +135,9 @@
   // 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) {
___
cfe-commits mailing list

[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton accepted this revision.
benhamilton added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:144
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" +
+ AcronymsGroupRegex(EscapedAcronyms, true) + "|([A-Z][a-z0-9]+))*$";
 }

Wizard wrote:
> benhamilton wrote:
> > Why do we not allow singular acronyms in the middle of the property name?
> > 
> > I think we should allow singular and plural acronyms anywhere.
> Actually we do. AcronymsGroupRegex(EscapedAcronyms, true) will support both 
> while AcronymsGroupRegex(EscapedAcronyms, false) only supports singular. Will 
> update test cases.
Ah, this is why I find boolean flags to be confusing :) Anyway, it's gone now.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:139
 
-  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) +
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" + AcronymsGroupRegex(EscapedAcronyms) +

Since `AcronymsGroupRegex()` is called twice with the same parameter, please 
store the result in a local variable instead of doing the work twice.



Comment at: test/clang-tidy/objc-property-declaration.m:12
 @property(strong, nonatomic) NSString *URLString;
 @property(strong, nonatomic) NSString *bundleID;
 @property(strong, nonatomic) NSData *RGBABytes;

Add a check for a plural at the end, please.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 133066.
Wizard added a comment.

resolve comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -130,11 +136,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) +
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" + AcronymsGroupRegex(EscapedAcronyms) +
+ "|([A-Z][a-z0-9]+))*$";
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {


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,9 @@
 @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)
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,12 @@
   return FixItHint();
 }
 
+std::string AcronymsGroupRegex(llvm::ArrayRef EscapedAcronyms) {
+  return "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "s?|") +
+ "s?)";
+}
+
 std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
bool UsedInMatcher) {
   // Allow any of these names:
@@ -130,11 +136,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) +
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" + AcronymsGroupRegex(EscapedAcronyms) +
+ "|([A-Z][a-z0-9]+))*$";
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:142
 
-  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]*(" +

benhamilton wrote:
> Why do we not allow plural acronyms at the start of the property name? For 
> example:
> 
> ```lang=objc
> @property(nonatomic) NSArray *URLsToFetch;
> ```
> 
> should be allowed.
> 
Hmm I was thinking that prefix should not have plural form. Will enable plural 
forms everywhere.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:144
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" +
+ AcronymsGroupRegex(EscapedAcronyms, true) + "|([A-Z][a-z0-9]+))*$";
 }

benhamilton wrote:
> Why do we not allow singular acronyms in the middle of the property name?
> 
> I think we should allow singular and plural acronyms anywhere.
Actually we do. AcronymsGroupRegex(EscapedAcronyms, true) will support both 
while AcronymsGroupRegex(EscapedAcronyms, false) only supports singular. Will 
update test cases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton requested changes to this revision.
benhamilton added a comment.
This revision now requires changes to proceed.

Can you add test cases for non-plural acronyms in the middle of the string and 
plural acronyms at the start/end of the string, please?




Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:142
 
-  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]*(" +

Why do we not allow plural acronyms at the start of the property name? For 
example:

```lang=objc
@property(nonatomic) NSArray *URLsToFetch;
```

should be allowed.




Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:144
+ "[A-Z]?)?[a-z]+[a-z0-9]*(" +
+ AcronymsGroupRegex(EscapedAcronyms, true) + "|([A-Z][a-z0-9]+))*$";
 }

Why do we not allow singular acronyms in the middle of the property name?

I think we should allow singular and plural acronyms anywhere.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-05 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 132938.
Wizard added a comment.

resolve conflict in doc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42947

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  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]
+@property(strong, nonatomic) NSString *supportURLsCamelCase;
 @end
 
 @interface Foo (Bar)
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 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 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) {


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]
+@property(strong, nonatomic) NSString *supportURLsCamelCase;
 @end
 
 @interface Foo (Bar)
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 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 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) {

[PATCH] D42947: Support special acronyms inside property names and allow plural forms

2018-02-05 Thread Yan Zhang via Phabricator via cfe-commits
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]
+@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
+@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 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 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) {


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]
+@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
+@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