[PATCH] D46895: add AR to acronyms of clang-tidy property check

2018-05-15 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/D46895

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -42,6 +42,7 @@
 "[2-9]G",
 "ACL",
 "API",
+"AR",
 "ARGB",
 "ASCII",
 "BGRA",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -42,6 +42,7 @@
 "[2-9]G",
 "ACL",
 "API",
+"AR",
 "ARGB",
 "ASCII",
 "BGRA",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46895: add AR to acronyms of clang-tidy property check

2018-05-15 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE332382: add AR to acronyms of clang-tidy property check 
(authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46895?vs=146874&id=146886#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46895

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -42,6 +42,7 @@
 "[2-9]G",
 "ACL",
 "API",
+"AR",
 "ARGB",
 "ASCII",
 "BGRA",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -42,6 +42,7 @@
 "[2-9]G",
 "ACL",
 "API",
+"AR",
 "ARGB",
 "ASCII",
 "BGRA",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44539: [Sema][Objective-C] Add check to warn when property of objc type has assign attribute

2018-05-18 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

Is there any case for property of ObjC types that we should use 
`unsafe_unretained` or `assign` rather than `weak`? In my understanding, `weak` 
is for properties of ObjC types as the replacement of `unsafe_unretained` and 
`assign` is for properties of primitive types.


Repository:
  rC Clang

https://reviews.llvm.org/D44539



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


[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜

2018-09-04 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:50
+
+void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
+  // This check should only be applied to Objective-C sources.

Can we do some simple check to see if some easy fix can be provided just like 
`objc-property-declaration` check?
Something like `static bool isPositive` to `static bool IsPositive` and `static 
bool is_upper_camel` to `IsUpperCamel`. Such check can help provide code fix 
for a lot of  very common mistake at a low cost (i.e. if the naming pattern 
cannot be simply recognized, just provide no fix).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51575



___
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 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 "

[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-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 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 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
c

[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&id=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] D43640: add support for constants with appropriate prefix. Start with 'k' is not the only option. This is according to http://google.github.io/styleguide/objcguide.html#constants

2018-02-22 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/D43640

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.m


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -2,7 +2,7 @@
 
 @class NSString;
 static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have an appropriate prefix or a name which starts with 
'k[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 static NSString* MyString = @"hi";
@@ -22,14 +22,15 @@
 // CHECK-FIXES: static NSString* gNoDef;
 
 static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have an appropriate prefix or a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
 static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have an appropriate prefix or a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
 
 static NSString* const kGood = @"hello";
+static NSString* const ABCGood = @"I have a prefix";
 static NSString* gMyIntGood = 0;
 
 @implementation Foo
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -24,15 +24,13 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return Node.isLocalVarDecl();
-}
+AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
 
 FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
   char FC = Decl->getName()[0];
   if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
 // No fix available if first character is not alphabetical character, or it
-// is a single-character variable, since it is difficult to determine the 
+// is a single-character variable, since it is difficult to determine the
 // proper fix in this case. Users should create a proper variable name by
 // their own.
 return FixItHint();
@@ -72,7 +70,7 @@
   this);
   Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
  unless(isLocalVariable()),
- unless(matchesName("::k[A-Z]")))
+ unless(matchesName("::(k|[A-Z]{2,})[A-Z]")))
  .bind("global_const"),
  this);
 }
@@ -87,8 +85,8 @@
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
 diag(Decl->getLocation(),
- "const global variable '%0' must have a name which starts with "
- "'k[A-Z]'")
+ "const global variable '%0' must have an appropriate prefix or a name 
"
+ "which starts with 'k[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, true);
   }
 }


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -2,7 +2,7 @@
 
 @class NSString;
 static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have an appropriate prefix or a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 static NSString* MyString = @"hi";
@@ -22,14 +22,15 @@
 // CHECK-FIXES: static NSString* gNoDef;
 
 static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES: :[[@LIN

[PATCH] D43640: add support for constants with appropriate prefix. Start with 'k' is not the only option. This is according to http://google.github.io/styleguide/objcguide.html#constants

2018-02-22 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D43640#1016287, @stephanemoore wrote:

> I have this change out for review as well:
>  https://reviews.llvm.org/D43581


Ah cool. Your change looks good. Technically the same as mine. I will discard 
this diff.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43640



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


[PATCH] D43581: [clang-tidy/google] Fix the Objective-C global variable declaration check 🔧

2018-02-22 Thread Yan Zhang via Phabricator via cfe-commits
Wizard requested changes to this revision.
Wizard added a comment.
This revision now requires changes to proceed.

Please update the warning info to indicate that prefix 'k' is not the only 
option for constants. Something like:
"const global variable '%0' must have an appropriate prefix or a name which 
starts with 'k[A-Z]'"


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43581



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


[PATCH] D43640: add support for constants with appropriate prefix. Start with 'k' is not the only option. This is according to http://google.github.io/styleguide/objcguide.html#constants

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

fix format


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43640

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.m


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -2,7 +2,7 @@
 
 @class NSString;
 static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have an appropriate prefix or a name which starts with 
'k[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 static NSString* MyString = @"hi";
@@ -22,14 +22,15 @@
 // CHECK-FIXES: static NSString* gNoDef;
 
 static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have an appropriate prefix or a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
 static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have an appropriate prefix or a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
 
 static NSString* const kGood = @"hello";
+static NSString* const ABCGood = @"I have a prefix";
 static NSString* gMyIntGood = 0;
 
 @implementation Foo
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -24,15 +24,15 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return Node.isLocalVarDecl();
+AST_MATCHER(VarDecl, isLocalVariable) { 
+  return Node.isLocalVarDecl(); 
 }
 
 FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
   char FC = Decl->getName()[0];
   if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
 // No fix available if first character is not alphabetical character, or it
-// is a single-character variable, since it is difficult to determine the 
+// is a single-character variable, since it is difficult to determine the
 // proper fix in this case. Users should create a proper variable name by
 // their own.
 return FixItHint();
@@ -72,7 +72,7 @@
   this);
   Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
  unless(isLocalVariable()),
- unless(matchesName("::k[A-Z]")))
+ unless(matchesName("::(k|[A-Z]{2,})[A-Z]")))
  .bind("global_const"),
  this);
 }
@@ -87,8 +87,8 @@
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
 diag(Decl->getLocation(),
- "const global variable '%0' must have a name which starts with "
- "'k[A-Z]'")
+ "const global variable '%0' must have an appropriate prefix or a name 
"
+ "which starts with 'k[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, true);
   }
 }


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -2,7 +2,7 @@
 
 @class NSString;
 static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have an appropriate prefix or a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 static NSString* MyString = @"hi";
@@ -22,14 +22,15 @@
 // CHECK-FIXES: static NSString* gNoDef;
 
 static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES:

[PATCH] D43581: [clang-tidy/google] Fix the Objective-C global variable declaration check 🔧

2018-02-22 Thread Yan Zhang via Phabricator via cfe-commits
Wizard accepted this revision.
Wizard added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D43581#1016318, @stephanemoore wrote:

> In https://reviews.llvm.org/D43581#1016300, @Wizard wrote:
>
> > Please update the warning info to indicate that prefix 'k' is not the only 
> > option for constants. Something like:
> >  "const global variable '%0' must have an appropriate prefix or a name 
> > which starts with 'k[A-Z]'"
>
>
> Is the latest warning info satisfactory? I believe I updated it after adding 
> you as a reviewer.


Hmm I feel it is a bit unfriendly to show users a rather complicated regex in 
the info, but I will leave it to you. Not a big problem.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43581



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


[PATCH] D43581: [clang-tidy/google] Fix the Objective-C global variable declaration check 🔧

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



Comment at: clang-tidy/google/GlobalVariableDeclarationCheck.cpp:92
+ "an appropriate prefix (see "
+ "http://google.github.io/styleguide/objcguide#constants).")
 << Decl->getName() << generateFixItHint(Decl, true);

aaron.ballman wrote:
> We don't usually put hyperlinks in the diagnostic messages, so please remove 
> this.
> 
> My suggestion about describing what constitutes an appropriate prefix was 
> with regards to the style guide wording itself. For instance, that document 
> doesn't mention that two capital letters is good. That's not on you to fix 
> before this patch goes in, of course.
Btw it is actually "2 or more" characters for prefix. I think it makes sense 
because we need at least 2 or more characters to call it a "prefix" :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43581



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


[PATCH] D43581: [clang-tidy/google] Improve the Objective-C global variable declaration check 🔧

2018-02-24 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D43581#1018584, @stephanemoore wrote:

> In https://reviews.llvm.org/D43581#1018499, @aaron.ballman wrote:
>
> > This LGTM! Do you need someone to commit on your behalf?
>
>
> I would be happy to commit assuming that I am able to and can meet submission 
> requirements.
>
> I see a "Submit" button in Phabricator that I assume will land the commit if 
> I press it?
>
> I found some submission guidelines in the LLVM Developer Policy 
> . Are there any other submission 
> guidelines I should follow?
>
> I ran the LLVM and Clang regression tests (by running `make check-all` from 
> my LLVM build directory) and I encountered a failure in "Bindings/Go/go.test":
>
>    TEST 'LLVM :: Bindings/Go/go.test' FAILED 
> 
>   Script:
>   --
>   /Users/mog/projects/llvm-build/bin/llvm-go go=/usr/local/go/bin/go test 
> llvm.org/llvm/bindings/go/llvm
>   --
>   Exit Code: 1
>  
>   Command Output (stdout):
>   --
>   FAILllvm.org/llvm/bindings/go/llvm [build failed]
>  
>   --
>   Command Output (stderr):
>   --
>   # llvm.org/llvm/bindings/go/llvm
>   In file included from 
> /var/folders/qh/4y215hgd4zqg30v9q04czw58005k3k/T/lit_tmp_7sZYWR/gopath735545420/src/llvm.org/llvm/bindings/go/llvm/analysis.go:17:
>   In file included from /Users/mog/projects/llvm/include/llvm-c/Analysis.h:22:
>   In file included from /Users/mog/projects/llvm/include/llvm-c/Types.h:17:
>   /Users/mog/projects/llvm-build/include/llvm/Support/DataTypes.h:35:10: 
> fatal error: 'math.h' file not found
>   #include 
>^~~~
>   1 error generated.
>  
>   --
>  
>   
>
>
> I reran these tests on a clean checkout and I still encountered the failure 
> so I presume that this failure is unrelated?
>
> I have also been trying to run the `test-suite` but I have been encountering 
> Python exceptions while trying to run `lnt` 😕.
>
> If someone wants to submit on my behalf that works for me. If not, I can also 
> continue trying to drive this myself (though verification of submission 
> requirements would be helpful in that case).


You may wanna follow this 
http://llvm.org/docs/Phabricator.html#git-svn-and-arcanist to submit your 
changes. But as aaron.ballman@ mentioned, you may need someone who has acl to 
commit it for you. 
For the error you see it is likely because you only updated the tools/extra 
repo. Usually when we sync this repo, we will have to pull parent repos as well 
(i.e. clang repo and llvm repo).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43581



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


[PATCH] D43581: [clang-tidy/google] Improve the Objective-C global variable declaration check 🔧

2018-02-24 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326046: [clang-tidy/google] Improve the Objective-C global 
variable declaration check 🔧 (authored by Wizard, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D43581?vs=135745&id=135811#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43581

Files:
  clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m


Index: 
clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -72,7 +72,7 @@
   this);
   Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
  unless(isLocalVariable()),
- unless(matchesName("::k[A-Z]")))
+ unless(matchesName("::(k[A-Z]|[A-Z]{2,})")))
  .bind("global_const"),
  this);
 }
@@ -88,7 +88,7 @@
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
- "'k[A-Z]'")
+ "an appropriate prefix")
 << Decl->getName() << generateFixItHint(Decl, true);
   }
 }
Index: 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -2,7 +2,7 @@
 
 @class NSString;
 static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 static NSString* MyString = @"hi";
@@ -22,16 +22,24 @@
 // CHECK-FIXES: static NSString* gNoDef;
 
 static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' 
must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
 static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' 
must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
 
 static NSString* const kGood = @"hello";
+static NSString* const XYGood = @"hello";
 static NSString* gMyIntGood = 0;
 
+extern NSString* const GTLServiceErrorDomain;
+
+enum GTLServiceError {
+  GTLServiceErrorQueryResultMissing = -3000,
+  GTLServiceErrorWaitTimedOut   = -3001,
+};
+
 @implementation Foo
 - (void)f {
 int x = 0;


Index: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -72,7 +72,7 @@
   this);
   Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
  unless(isLocalVariable()),
- unless(matchesName("::k[A-Z]")))
+ unless(matchesName("::(k[A-Z]|[A-Z]{2,})")))
  .bind("global_const"),
  this);
 }
@@ -88,7 +88,7 @@
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
- "'k[A-Z]'")
+ "an appropriate prefix")
 << Decl->getName() << generateFixItHint(Decl, true);
   }
 }
Index: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m

[PATCH] D43775: add UUID to the acronyms list of objc property name checks

2018-02-26 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, klimek.
Wizard added reviewers: benhamilton, hokein.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43775

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -87,6 +87,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -87,6 +87,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43775: add UUID to the acronyms list of objc property name checks

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

resolve comment


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43775

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43775: add UUID to the acronyms list of objc property name checks

2018-02-27 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE326222: add UUID to the acronyms list of objc property 
name checks (authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43775?vs=136100&id=136102#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43775

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43775: add UUID to the acronyms list of objc property name checks

2018-02-27 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326222: add UUID to the acronyms list of objc property name 
checks (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43775

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -50,6 +50,7 @@
 "FTP",
 "GIF",
 "GPS",
+"GUID",
 "HD",
 "HDR",
 "HTML",
@@ -87,6 +88,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44174: do not register matcher for objc-only checks when analyzing non-objc sources to save resources

2018-03-06 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/D44174

Files:
  clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
  clang-tidy/objc/AvoidNSErrorInitCheck.cpp
  clang-tidy/objc/ForbiddenSubclassingCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tidy/objc/ForbiddenSubclassingCheck.cpp
@@ -77,6 +77,10 @@
 }
 
 void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(
   objcInterfaceDecl(
   isSubclassOf(
Index: clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -19,6 +19,11 @@
 namespace objc {
 
 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
+
   Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
   Finder->addMatcher(
   objcMessageExpr(anyOf(hasSelector("raise:format:"),


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tidy/objc/ForbiddenSubclassingCheck.cpp
@@ -77,6 +77,10 @@
 }
 
 void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(
   objcInterfaceDecl(
   isSubclassOf(
Index: clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -19,6 +19,11 @@
 namespace objc {
 
 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (

[PATCH] D44174: do not register matcher for objc-only checks when analyzing non-objc sources to save resources

2018-03-07 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326928: do not register matcher for objc-only checks when 
analyzing non-objc sources to… (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44174

Files:
  clang-tools-extra/trunk/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
@@ -77,6 +77,10 @@
 }
 
 void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(
   objcInterfaceDecl(
   isSubclassOf(
Index: 
clang-tools-extra/trunk/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -19,6 +19,11 @@
 namespace objc {
 
 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
+
   Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
   Finder->addMatcher(
   objcMessageExpr(anyOf(hasSelector("raise:format:"),


Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tools-extra/trunk/cl

[PATCH] D48039: - Add "AV" as new default acronym. - Add support for "I" and "A" in lowerCamelCase pattern

2018-06-11 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added a subscriber: cfe-commits.
Wizard edited the summary of this revision.
Wizard added reviewers: benhamilton, hokein.

Now we can support property names like "hasADog" correctly.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48039

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
@@ -22,6 +22,7 @@
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
 @property(assign, nonatomic) int ID;
+@property(assign, nonatomic) int hasADog;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -45,6 +45,7 @@
 "AR",
 "ARGB",
 "ASCII",
+"AV",
 "BGRA",
 "CA",
 "CF",
@@ -153,7 +154,7 @@
   std::string StartMatcher = UsedInMatcher ? "::" : "^";
   std::string AcronymsMatcher = AcronymsGroupRegex(EscapedAcronyms);
   return StartMatcher + "(" + AcronymsMatcher + "[A-Z]?)?[a-z]+[a-z0-9]*(" +
- AcronymsMatcher + "|([A-Z][a-z0-9]+))*$";
+ AcronymsMatcher + "|([A-Z][a-z0-9]+)|A|I)*$";
 }
 
 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
@@ -22,6 +22,7 @@
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
 @property(assign, nonatomic) int ID;
+@property(assign, nonatomic) int hasADog;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -45,6 +45,7 @@
 "AR",
 "ARGB",
 "ASCII",
+"AV",
 "BGRA",
 "CA",
 "CF",
@@ -153,7 +154,7 @@
   std::string StartMatcher = UsedInMatcher ? "::" : "^";
   std::string AcronymsMatcher = AcronymsGroupRegex(EscapedAcronyms);
   return StartMatcher + "(" + AcronymsMatcher + "[A-Z]?)?[a-z]+[a-z0-9]*(" +
- AcronymsMatcher + "|([A-Z][a-z0-9]+))*$";
+ AcronymsMatcher + "|([A-Z][a-z0-9]+)|A|I)*$";
 }
 
 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] D48039: - Add "AV" as new default acronym. - Add support for "I" and "A" in lowerCamelCase pattern

2018-06-11 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334448: - Add "AV" as new default acronym. - Add 
support for "I" and "A" in… (authored by Wizard, committed 
by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D48039

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -45,6 +45,7 @@
 "AR",
 "ARGB",
 "ASCII",
+"AV",
 "BGRA",
 "CA",
 "CF",
@@ -153,7 +154,7 @@
   std::string StartMatcher = UsedInMatcher ? "::" : "^";
   std::string AcronymsMatcher = AcronymsGroupRegex(EscapedAcronyms);
   return StartMatcher + "(" + AcronymsMatcher + "[A-Z]?)?[a-z]+[a-z0-9]*(" +
- AcronymsMatcher + "|([A-Z][a-z0-9]+))*$";
+ AcronymsMatcher + "|([A-Z][a-z0-9]+)|A|I)*$";
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -22,6 +22,7 @@
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
 @property(assign, nonatomic) int ID;
+@property(assign, nonatomic) int hasADog;
 @end
 
 @interface Foo (Bar)


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -45,6 +45,7 @@
 "AR",
 "ARGB",
 "ASCII",
+"AV",
 "BGRA",
 "CA",
 "CF",
@@ -153,7 +154,7 @@
   std::string StartMatcher = UsedInMatcher ? "::" : "^";
   std::string AcronymsMatcher = AcronymsGroupRegex(EscapedAcronyms);
   return StartMatcher + "(" + AcronymsMatcher + "[A-Z]?)?[a-z]+[a-z0-9]*(" +
- AcronymsMatcher + "|([A-Z][a-z0-9]+))*$";
+ AcronymsMatcher + "|([A-Z][a-z0-9]+)|A|I)*$";
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -22,6 +22,7 @@
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
 @property(assign, nonatomic) int ID;
+@property(assign, nonatomic) int hasADog;
 @end
 
 @interface Foo (Bar)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56896: Update property prefix regex to allow numbers.

2019-01-17 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, jfb.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D56896

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
@@ -46,9 +46,10 @@
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
 @property(strong, nonatomic) NSString *abc_URL;
+@property(strong, nonatomic) NSString *opac2_sourceComponent;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -81,7 +81,8 @@
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
-  auto RegexExp = llvm::Regex("^[a-zA-Z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$");
+  auto RegexExp =
+  llvm::Regex("^[a-zA-Z][a-zA-Z0-9]*_[a-zA-Z0-9][a-zA-Z0-9_]+$");
   return RegexExp.match(PropertyName);
 }
 
@@ -92,8 +93,7 @@
   if (Prefix.lower() != Prefix) {
 return false;
   }
-  auto RegexExp =
-  llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
+  auto RegexExp = llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
   return RegexExp.match(PropertyName.substr(Start + 1));
 }
 }  // namespace
@@ -110,13 +110,12 @@
   // this check should only be applied to ObjC sources.
   if (!getLangOpts().ObjC) return;
 
-  Finder->addMatcher(
-  objcPropertyDecl(
-  // the property name should be in Lower Camel Case like
-  // 'lowerCamelCase'
-  unless(matchesName(validPropertyNameRegex(true
-  .bind("property"),
-  this);
+  Finder->addMatcher(objcPropertyDecl(
+ // the property name should be in Lower Camel Case 
like
+ // 'lowerCamelCase'
+ unless(matchesName(validPropertyNameRegex(true
+ .bind("property"),
+ this);
 }
 
 void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -46,9 +46,10 @@
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
 @property(strong, nonatomic) NSString *abc_URL;
+@property(strong, nonatomic) NSString *opac2_sourceComponent;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -81,7 +81,8 @@
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
-  auto RegexExp = llvm::Regex("^[a-zA-Z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$");
+  auto RegexExp =
+  llvm::Regex("^[a-zA-Z][a-zA-Z0-9]*_[a-zA-Z0-9][a-zA-Z0-9_]+$");
   return RegexExp.match(PropertyName);
 }
 
@@ -92,8 +93,7 @@
   if (Prefix.lower() != Prefix) {
 return false;
   }
-  auto RegexExp =
-  llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
+  auto RegexExp = llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
   return RegexExp.match(PropertyName.substr(Start + 1));
 }
 }  // namespace
@@ -110,13 +110,12 @@
   // this check should only be applied to ObjC sources.
   if (!getLangOpts().ObjC) return;
 
-  Finder->addMatcher(
-  objcPropertyDecl(
-  // the property name should be in Lower Camel Case like
-  // 'lowerCamelCase'
-  unless(matchesName(validPropertyNameRegex(true
-  .bind("property"),
-  this);
+  Finder->addMatcher(objcPropertyDecl(
+ // the property name should be in Lower Camel Case like
+ // 'lowerCamelCase'
+ unless(matchesName(validPropertyNameRegex(true
+ .bind("property"),
+ this);
 }
 
 void PropertyDeclarationCheck::check(const MatchFinder::MatchRe

[PATCH] D53955: :Fix the issue that not recognizing single acronym with prefix as ObjC property name.

2018-10-31 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, jfb.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53955

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
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not 
using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -235,9 +235,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + 
"$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -235,9 +235,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53955: Fix the issue that not recognizing single acronym with prefix as ObjC property name.

2018-11-01 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 172169.
Wizard added a comment.

Format code.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53955

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
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,92 +39,16 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
-"[2-9]G",
-"ACL",
-"API",
-"APN",
-"APNS",
-"AR",
-"ARGB",
-"ASCII",
-"AV",
-"BGRA",
-"CA",
-"CDN",
-"CF",
-"CG",
-"CI",
-"CRC",
-"CV",
-"CMYK",
-"DNS",
-"FPS",
-"FTP",
-"GIF",
-"GL",
-"GPS",
-"GUID",
-"HD",
-"HDR",
-"HMAC",
-"HTML",
-"HTTP",
-"HTTPS",
-"HUD",
-"ID",
-"JPG",
-"JS",
-"JSON",
-"LAN",
-"LZW",
-"LTR",
-"MAC",
-"MD",
-"MDNS",
-"MIDI",
-"NS",
-"OS",
-"P2P",
-"PDF",
-"PIN",
-"PNG",
-"POI",
-"PSTN",
-"PTR",
-"QA",
-"QOS",
-"RGB",
-"RGBA",
-"RGBX",
-"RIPEMD",
-"ROM",
-"RPC",
-"RTF",
-"RTL",
-"SC",
-"SDK",
-"SHA",
-"SQL",
-"SSO",
-"TCP",
-"TIFF",
-"TOS",
-"TTS",
-"UI",
-"URI",
-"URL",
-"UUID",
-"VC",
-"VO",
-"VOIP",
-"VPN",
-"VR",
-"W",
-"WAN",
-"X",
-"XML",
-"Y",
-"Z",
+"[2-9]G", "ACL",  "API",  "APN","APNS", "AR",   "ARGB", "ASCII", "AV",
+"BGRA",   "CA",   "CDN",  "CF", "CG",   "CI",   "CRC",  "CV","CMYK",
+"DNS","FPS",  "FTP",  "GIF","GL",   "GPS",  "GUID", "HD","HDR",
+"HMAC",   "HTML", "HTTP", "HTTPS",  "HUD",  "ID",   "JPG",  "JS","JSON",
+"LAN","LZW",  "LTR",  "MAC","MD",   "MDNS", "MIDI", "NS","OS",
+"P2P","PDF",  "PIN",  "PNG","POI",  "PSTN", "PTR",  "QA","QOS",
+"RGB","RGBA", "RGBX", "RIPEMD", "ROM",  "RPC",  "RTF",  "RTL",   "SC",
+"SDK","SHA",  "SQL",  "SSO","TCP",  "TIFF", "TOS",  "TTS",   "UI",
+"URI","URL",  "UUID", "VC", "VO",   "VOIP", "VPN",  "VR","W",
+"WAN","X","XML",  "Y",  "Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
@@ -201,8 +125,7 @@
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   // this check should only be applied to ObjC sources.
-  if (!getLangOpts().ObjC)
-return;
+  if (!getLangOpts().ObjC) return;
 
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
@@ -235,9 +158,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53955: Fix the issue that not recognizing single acronym with prefix as ObjC property name.

2018-11-01 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 172172.
Wizard added a comment.

format change


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53955

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
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not 
using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -201,8 +201,7 @@
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   // this check should only be applied to ObjC sources.
-  if (!getLangOpts().ObjC)
-return;
+  if (!getLangOpts().ObjC) return;
 
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
@@ -235,9 +234,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + 
"$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -201,8 +201,7 @@
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   // this check should only be applied to ObjC sources.
-  if (!getLangOpts().ObjC)
-return;
+  if (!getLangOpts().ObjC) return;
 
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
@@ -235,9 +234,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53955: Fix the issue that not recognizing single acronym with prefix as ObjC property name.

2018-11-01 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL345858: Fix the issue that not recognizing single acronym 
with prefix as ObjC property… (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53955

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m


Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not 
using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -201,8 +201,7 @@
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   // this check should only be applied to ObjC sources.
-  if (!getLangOpts().ObjC)
-return;
+  if (!getLangOpts().ObjC) return;
 
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
@@ -235,9 +234,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + 
"$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&


Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -38,9 +38,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
+@property(strong, nonatomic) NSString *abc_URL;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -201,8 +201,7 @@
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   // this check should only be applied to ObjC sources.
-  if (!getLangOpts().ObjC)
-return;
+  if (!getLangOpts().ObjC) return;
 
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
@@ -235,9 +234,9 @@
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
 
-  auto AcronymsRegex =
-  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
-  if (AcronymsRegex.match(MatchedDecl->getName())) {
+  auto SingleAcronymRegex =
+  llvm::Regex("^([a-zA-Z]+_)?" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (SingleAcronymRegex.match(MatchedDecl->getName())) {
 return;
   }
   if (CategoryDecl != nullptr &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54288: Fix ClangFormat issue of recognizing ObjC subscription as C++ attributes when message target is a result of a C-style method.

2018-11-08 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D54288

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -352,6 +352,7 @@
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -366,7 +367,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
@@ -2489,6 +2491,7 @@
 LSquareTok.endsSequence(tok::l_square, tok::colon,
 TT_SelectorName));
   };
+
   if (Left.is(tok::l_square))
 return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) 
&&
 SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -352,6 +352,7 @@
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -366,7 +367,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
@@ -2489,6 +2491,7 @@
 LSquareTok.endsSequence(tok::l_square, tok::colon,
 TT_SelectorName));
   };
+
   if (Left.is(tok::l_square))
 return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) &&
 SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54288: Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when message target is a result of a C-style method.

2018-11-08 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 173258.
Wizard added a comment.

remove blank lines


Repository:
  rC Clang

https://reviews.llvm.org/D54288

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54288: Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when message target is a result of a C-style method.

2018-11-09 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL346566: Fix ClangFormat issue of recognizing ObjC subscript 
as C++ attributes when… (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D54288

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54288: Fix ClangFormat issue of recognizing ObjC subscript as C++ attributes when message target is a result of a C-style method.

2018-11-09 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC346566: Fix ClangFormat issue of recognizing ObjC subscript 
as C++ attributes when… (authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54288?vs=173258&id=173457#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54288

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,8 @@
   // specifier parameter, although this is technically valid:
   // [[foo(:)]]
   if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier))
+  AttrTok->startsSequence(tok::identifier, tok::identifier) || 
+  AttrTok->startsSequence(tok::r_paren, tok::identifier))
 return false;
   if (AttrTok->is(tok::ellipsis))
 return true;
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6472,6 +6472,8 @@
   // Make sure we do not mistake attributes for array subscripts.
   verifyFormat("int a() {}\n"
"[[unused]] int b() {}\n");
+  verifyFormat("NSArray *arr;\n"
+   "arr[[Foo() bar]];");
 
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

2019-03-12 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D59283

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.m
  test/clang-tidy/google-objc-global-variable-declaration.mm


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- test/clang-tidy/google-objc-global-variable-declaration.mm
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -35,6 +35,10 @@
 
 extern NSString* const GTLServiceErrorDomain;
 
+class MyTest {
+static int not_objc_style;
+};
+
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
   GTLServiceErrorWaitTimedOut   = -3001,
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,18 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember()) {
+  return;
+}
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember()) {
+  return;
+}
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- test/clang-tidy/google-objc-global-variable-declaration.mm
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -35,6 +35,10 @@
 
 extern NSString* const GTLServiceErrorDomain;
 
+class MyTest {
+static int not_objc_style;
+};
+
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
   GTLServiceErrorWaitTimedOut   = -3001,
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,18 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember()) {
+  return;
+}
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember()) {
+  return;
+}
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

2019-03-13 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 190461.
Wizard added a comment.

Resolve comments


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59283/new/

https://reviews.llvm.org/D59283

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.mm


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,5 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+class MyTest {
+static int not_objc_style;
+};
\ No newline at end of file
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,5 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+class MyTest {
+static int not_objc_style;
+};
\ No newline at end of file
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

2019-03-13 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 190462.
Wizard added a comment.

fix ObjC++ test


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59283/new/

https://reviews.llvm.org/D59283

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.mm


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
\ No newline at end of file
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
\ No newline at end of file
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

2019-03-14 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 190750.
Wizard added a comment.

add new line


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59283/new/

https://reviews.llvm.org/D59283

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.mm


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")


Index: test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- /dev/null
+++ test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.

2019-03-14 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356220: Fixed global constant/variable naming check on C++ 
class for ObjC++ files. (authored by Wizard, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59283/new/

https://reviews.llvm.org/D59283

Files:
  clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm


Index: 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 
'myConstString' must have a name which starts with an appropriate prefix 
[google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
Index: 
clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")


Index: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
===
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
+
+@class NSString;
+static NSString* const myConstString = @"hello";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
+
+class MyTest {
+static int not_objc_style;
+};
Index: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -79,12 +79,16 @@
 void GlobalVariableDeclarationCheck::check(
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "non-const global variable '%0' must have a name which starts with "
  "'g[A-Z]'")
 << Decl->getName() << generateFixItHint(Decl, false);
   }
   if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) {
+if (Decl->isStaticDataMember())
+  return;
 diag(Decl->getLocation(),
  "const global variable '%0' must have a name which starts with "
  "an appropriate prefix")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56896: Update property prefix regex to allow numbers.

2019-02-20 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE354485: Update property prefix regex to allow numbers. 
(authored by Wizard, committed by ).
Herald added a subscriber: jdoerfert.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D56896?vs=182439&id=187599#toc

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56896/new/

https://reviews.llvm.org/D56896

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  test/clang-tidy/objc-property-declaration.m


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -80,7 +80,8 @@
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
-  auto RegexExp = llvm::Regex("^[a-zA-Z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$");
+  auto RegexExp =
+  llvm::Regex("^[a-zA-Z][a-zA-Z0-9]*_[a-zA-Z0-9][a-zA-Z0-9_]+$");
   return RegexExp.match(PropertyName);
 }
 
@@ -91,8 +92,7 @@
   if (Prefix.lower() != Prefix) {
 return false;
   }
-  auto RegexExp =
-  llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
+  auto RegexExp = llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
   return RegexExp.match(PropertyName.substr(Start + 1));
 }
 }  // namespace
@@ -101,13 +101,12 @@
   // this check should only be applied to ObjC sources.
   if (!getLangOpts().ObjC) return;
 
-  Finder->addMatcher(
-  objcPropertyDecl(
-  // the property name should be in Lower Camel Case like
-  // 'lowerCamelCase'
-  unless(matchesName(validPropertyNameRegex(true
-  .bind("property"),
-  this);
+  Finder->addMatcher(objcPropertyDecl(
+ // the property name should be in Lower Camel Case 
like
+ // 'lowerCamelCase'
+ unless(matchesName(validPropertyNameRegex(true
+ .bind("property"),
+ this);
 }
 
 void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -46,9 +46,10 @@
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
 @property(strong, nonatomic) NSString *abc_URL;
+@property(strong, nonatomic) NSString *opac2_sourceComponent;
 @end
 
 @interface Foo ()
 @property(assign, nonatomic) int abc_inClassExtension;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
\ No newline at end of file


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -80,7 +80,8 @@
 }
 
 bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
-  auto RegexExp = llvm::Regex("^[a-zA-Z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$");
+  auto RegexExp =
+  llvm::Regex("^[a-zA-Z][a-zA-Z0-9]*_[a-zA-Z0-9][a-zA-Z0-9_]+$");
   return RegexExp.match(PropertyName);
 }
 
@@ -91,8 +92,7 @@
   if (Prefix.lower() != Prefix) {
 return false;
   }
-  auto RegexExp =
-  llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
+  auto RegexExp = llvm::Regex(llvm::StringRef(validPropertyNameRegex(false)));
   return RegexExp.match(PropertyName.substr(Start + 1));
 }
 }  // namespace
@@ -101,13 +101,12 @@
   // this check should only be applied to ObjC sources.
   if (!getLangOpts().ObjC) return;
 
-  Finder->addMatcher(
-  objcPropertyDecl(
-  // the property name should be in Lower Camel Case like
-  // 'lowerCamelCase'
-  unless(matchesName(validPropertyNameRegex(true
-  .bind("property"),
-  this);
+  Finder->addMatcher(objcPropertyDecl(
+ // the property name should be in Lower Camel Case like
+ // 'lowerCamelCase'
+ unless(matchesName(validPropertyNameRegex(true
+ .bind("property"),
+ this);
 }
 
 void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -46,9 +46,10 @@
 @property(strong, nonatomic) NSString *URLStr;
 @property(assign, nonatomic) int abc_camelCase;
 @property(strong, nonatomic) NSString *abc_URL;
+@property(strong, nonatomic) NSString *opac2

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-12 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: test/clang-tidy/readability-identifier-naming-objc.m:4
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+

alexfh wrote:
> The `--` and the trailing backslash above can be removed as well.
I tried but when I run the test there some error output:
Running ['clang-tidy', 
'/Users/ynzhang/clang-llvm/build/tools/clang/tools/extra/test/clang-tidy/Output/readability-identifier-naming-objc.m.tmp.m',
 '-fix', '--checks=-*,readability-identifier-naming', '-config={CheckOptions:   
[{key: readability-identifier-naming.ObjcIvarPrefix, value: _}]}', 
'-nostdinc++']...
clang-tidy failed:
LLVM ERROR: CommonOptionsParser: failed to parse command-line arguments. 
[CommonOptionsParser]: clang-tidy: Unknown command line argument '-nostdinc++'. 
 Try: 'clang-tidy -help'
clang-tidy: Did you mean '-gpsize'?

No idea where '-nostdinc++' came from, but there is no such problem with these 
stuff added. I actually followed the command pattern in 
objc-forbidden-subclassing-custom.m


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45750: add extra acronyms for objc property names

2018-04-17 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/D45750

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
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enbale2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enbale2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45750: add extra acronyms for objc property names

2018-04-18 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 142985.
Wizard marked 2 inline comments as done.
Wizard added a comment.

resolve comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45750

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
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enable2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enable2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45750: add extra acronyms for objc property names

2018-04-18 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:42
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",

benhamilton wrote:
> Probably should just make this:
> 
>   "\\d+G"
> 
It seems llvm::Regex does not recognize \d somehow. I tried \\d+ does not work 
for the test. Will keep [2-9]G for now.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45750



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


[PATCH] D45750: add extra acronyms for objc property names

2018-04-18 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330286: add extra acronyms for objc property names (authored 
by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D45750

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enable2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,6 +39,7 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
+"[2-9]G",
 "ACL",
 "API",
 "ARGB",
@@ -93,8 +94,12 @@
 "VOIP",
 "VPN",
 "VR",
+"W",
 "WAN",
+"X",
 "XML",
+"Y",
+"Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -17,6 +17,8 @@
 @property(strong, nonatomic) NSString *supportURLsCamelCase;
 @property(strong, nonatomic) NSString *supportURLCamelCase;
 @property(strong, nonatomic) NSString *VCsPluralToAdd;
+@property(assign, nonatomic) int centerX;
+@property(assign, nonatomic) int enable2GBackgroundFetch;
 @end
 
 @interface Foo (Bar)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-20 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE330492: [clang-tidy] add new check to find out objc ivars 
which do not have prefix '_' (authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45392?vs=142057&id=143408#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45912: update test to use ivar in implementation instead of class extension

2018-04-20 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/D45912

Files:
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -6,7 +6,7 @@
 @interface Foo
 @end 
 
-@interface Foo () {
+@implementation Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -6,7 +6,7 @@
 @interface Foo
 @end 
 
-@interface Foo () {
+@implementation Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45912: update test to use ivar in implementation instead of class extension

2018-04-22 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 143494.
Wizard added a comment.

add back objc update for identifier naming check.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45912

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@implementation Foo {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+  
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@implementation Foo {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+  
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45912: update test to use ivar in implementation instead of class extension

2018-04-22 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330559: update test to use ivar in implementation instead of 
class extension (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D45912

Files:
  clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m


Index: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+  
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
Index: 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@implementation Foo {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end


Index: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+  
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
Index: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@implementation Foo {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45936: update readability-identifier-naming-objc test to use interface ivar. Implementation ivars are not supported in 32-bits OS.

2018-04-22 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/D45936

Files:
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -3,13 +3,10 @@
 // RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
 // RUN: --
 
-@interface Foo
-@end 
-
-@implementation Foo {
+@interface Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
 // CHECK-FIXES: int _barWithoutPrefix;
 }
-@end
+@end 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -3,13 +3,10 @@
 // RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
 // RUN: --
 
-@interface Foo
-@end 
-
-@implementation Foo {
+@interface Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
 // CHECK-FIXES: int _barWithoutPrefix;
 }
-@end
+@end 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45936: update readability-identifier-naming-objc test to use interface ivar. Implementation ivars are not supported in 32-bits OS.

2018-04-22 Thread Yan Zhang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE330562: update readability-identifier-naming-objc test to 
use interface ivar. (authored by Wizard, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45936?vs=143496&id=143497#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45936

Files:
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -3,13 +3,10 @@
 // RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
 // RUN: --
 
-@interface Foo
-@end 
-
-@implementation Foo {
+@interface Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
 // CHECK-FIXES: int _barWithoutPrefix;
 }
-@end
+@end 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- test/clang-tidy/readability-identifier-naming-objc.m
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -3,13 +3,10 @@
 // RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
 // RUN: --
 
-@interface Foo
-@end 
-
-@implementation Foo {
+@interface Foo {
 int _bar;
 int barWithoutPrefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
 // CHECK-FIXES: int _barWithoutPrefix;
 }
-@end
+@end 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-02 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/D46374

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
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,75 +39,14 @@
 ///
 /// Keep this list sorted.
 constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = {
-"[2-9]G",
-"ACL",
-"API",
-"ARGB",
-"ASCII",
-"BGRA",
-"CA",
-"CF",
-"CG",
-"CI",
-"CV",
-"CMYK",
-"DNS",
-"FPS",
-"FTP",
-"GIF",
-"GL",
-"GPS",
-"GUID",
-"HD",
-"HDR",
-"HTML",
-"HTTP",
-"HTTPS",
-"HUD",
-"ID",
-"JPG",
-"JS",
-"LAN",
-"LZW",
-"MDNS",
-"MIDI",
-"NS",
-"OS",
-"PDF",
-"PIN",
-"PNG",
-"POI",
-"PSTN",
-"PTR",
-"QA",
-"QOS",
-"RGB",
-"RGBA",
-"RGBX",
-"ROM",
-"RPC",
-"RTF",
-"RTL",
-"SC",
-"SDK",
-"SSO",
-"TCP",
-"TIFF",
-"TTS",
-"UI",
-"URI",
-"URL",
-"UUID",
-"VC",
-"VOIP",
-"VPN",
-"VR",
-"W",
-"WAN",
-"X",
-"XML",
-"Y",
-"Z",
+"[2-9]G", "ACL", "API",  "ARGB", "ASCII", "BGRA",  "CA",   "CF",   "CG",
+"CI", "CV",  "CMYK", "DNS",  "FPS",   "FTP",   "GIF",  "GL",   "GPS",
+"GUID",   "HD",  "HDR",  "HTML", "HTTP",  "HTTPS", "HUD",  "ID",   "JPG",
+"JS", "LAN", "LZW",  "MDNS", "MIDI",  "NS","OS",   "PDF",  "PIN",
+"PNG","POI", "PSTN", "PTR",  "QA","QOS",   "RGB",  "RGBA", "RGBX",
+"ROM","RPC", "RTF",  "RTL",  "SC","SDK",   "SSO",  "TCP",  "TIFF",
+"TTS","UI",  "URI",  "URL",  "UUID",  "VC","VOIP", "VPN",  "VR",
+"W",  "WAN", "X","XML",  "Y", "Z",
 };
 
 /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
@@ -217,6 +156,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+  if (std::any_of(EscapedAcronyms.begin(), EscapedAcronyms.end(),
+  [MatchedDecl](std::string const &s) {
+return s == MatchedDecl->getName();
+  })) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-02 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 144970.
Wizard edited the summary of this revision.
Wizard added a comment.

fix format


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374

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
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+  if (std::any_of(EscapedAcronyms.begin(), EscapedAcronyms.end(),
+  [MatchedDecl](std::string const &s) {
+return s == MatchedDecl->getName();
+  })) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+  if (std::any_of(EscapedAcronyms.begin(), EscapedAcronyms.end(),
+  [MatchedDecl](std::string const &s) {
+return s == MatchedDecl->getName();
+  })) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-03 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:222
+  [MatchedDecl](std::string const &s) {
+return s == MatchedDecl->getName();
+  })) {

benhamilton wrote:
> `s` is a regular expression here, so you need to match it using 
> `llvm::Regex`, not `==`.
> 
> Why not just update `validPropertyNameRegex()` to handle this case?
> 
I would rather not to make the regex more complex as long as the change is 
simple and does bring extra cost. If update the regex it will be something like 
'(originalregex | acronyms)', which seems too much to me.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374



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


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-03 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked 3 inline comments as done.
Wizard added inline comments.



Comment at: test/clang-tidy/objc-property-declaration.m:24
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end

benhamilton wrote:
> Please add a test for a built-in regex (4G) as well as a custom regex in the 
> other test file.
Unable to add single property test of 4G because it is illegal to use digit as 
the first character of property name.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374



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


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

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

resolve comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  test/clang-tidy/objc-property-declaration-custom.m
  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
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' 
not using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,13 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+  if (std::any_of(EscapedAcronyms.begin(), EscapedAcronyms.end(),
+  [MatchedDecl](std::string const &s) {
+auto Acronym  = llvm::Regex("^" + s + "$");
+return Acronym.match(MatchedDecl->getName());
+  })) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,13 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+  if (std::any_of(EscapedAcronyms.begin(), EscapedAcronyms.end(),
+  [MatchedDecl](std::string const &s) {
+auto Acronym  = llvm::Regex("^" + s + "$");
+return Acronym.match(MatchedDecl->getName());
+  })) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

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

optimize matching


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  test/clang-tidy/objc-property-declaration-custom.m
  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
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' 
not using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+
+  auto AcronymsRegex =
+  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (AcronymsRegex.match(MatchedDecl->getName())) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||


Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+
+  auto AcronymsRegex =
+  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (AcronymsRegex.match(MatchedDecl->getName())) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-04 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked an inline comment as done.
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:222
+  [MatchedDecl](std::string const &s) {
+auto Acronym  = llvm::Regex("^" + s + "$");
+return Acronym.match(MatchedDecl->getName());

benhamilton wrote:
> Please be aware this will change the match from running a single regular 
> expression to running ~ 70 regular expressions on every single `@property`. I 
> would expect this to perform pretty poorly.
> 
This is a good point. If using matching instead of equality check, I should not 
use any_of then. Updated it to use AcronymsGroupRegex().


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46374



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


[PATCH] D46374: Add support for ObjC property name to be a single acronym.

2018-05-04 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Wizard marked an inline comment as done.
Closed by commit rL331545: Add support for ObjC property name to be a single 
acronym. (authored by Wizard, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46374

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m


Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: 
clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' 
not using lowerCamelCase style or not prefixed in a category, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a 
category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+
+  auto AcronymsRegex =
+  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (AcronymsRegex.match(MatchedDecl->getName())) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||


Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -21,6 +21,7 @@
 @property(assign, nonatomic) int enable2GBackgroundFetch;
 @property(assign, nonatomic) int shouldUseCFPreferences;
 @property(assign, nonatomic) int enableGLAcceleration;
+@property(assign, nonatomic) int ID;
 @end
 
 @interface Foo (Bar)
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
@@ -14,4 +14,5 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
 @property(assign, nonatomic) int GIFIgnoreStandardAcronym;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+@property(strong, nonatomic) NSString *TGIF;
 @end
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -217,6 +217,12 @@
   assert(MatchedDecl->getName().size() > 0);
   auto *DeclContext = MatchedDecl->getDeclContext();
   auto *CategoryDecl = llvm::dyn_cast(DeclContext);
+
+  auto AcronymsRegex =
+  llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
+  if (AcronymsRegex.match(MatchedDecl->getName())) {
+return;
+  }
   if (CategoryDecl != nullptr &&
   hasCategoryPropertyPrefix(MatchedDecl->getName())) {
 if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcron

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-22 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124011.
Wizard marked an inline comment as done.
Wizard added a comment.

fix nit


https://reviews.llvm.org/D40325

Files:
  clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-spinlock.rst
  test/clang-tidy/objc-avoid-spinlock.m

Index: test/clang-tidy/objc-avoid-spinlock.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-spinlock.m
@@ -0,0 +1,16 @@
+// RUN: %check_clang_tidy %s objc-avoid-spinlock %t
+
+typedef int OSSpinLock;
+void OSSpinlockTry(OSSpinLock *__lock) {}
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: OSSpinlock is deprecated on iOS. Please use other locks or dispatch queue. [objc-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: OSSpinlock is deprecated on iOS. Please use other locks or dispatch queue. [objc-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: OSSpinlock is deprecated on iOS. Please use other locks or dispatch queue. [objc-avoid-spinlock]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-spinlock.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - objc-avoid-spinlock
+
+objc-avoid-spinlock
+===
+
+Finds usages of OSSpinlock in Objective-C files, which is deprecated due to potential
+livelock problems. 
+
+This check will detect following function invocations:
+
+- `OSSpinlockLock`
+- `OSSpinlockTry`
+- `OSSpinlockUnlcok`
+
+The corresponding information about the problem of OSSpinlock: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
performance-faster-string-find
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-spinlock
+  `_ check
+
+  Add new check to detect the use of OSSpinlock in Objective-C files.
+
 - New `google-avoid-throwing-objc-exception
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tidy/objc/AvoidSpinlockCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock in Objective-C files, which is deprecated due to
+/// potential livelock problems.
+///
+/// For the user-facing documentation see:
+//

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124427.
Wizard added a comment.

address comments


https://reviews.llvm.org/D40325

Files:
  clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-spinlock.rst
  test/clang-tidy/objc-avoid-spinlock.m

Index: test/clang-tidy/objc-avoid-spinlock.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-spinlock.m
@@ -0,0 +1,16 @@
+// RUN: %check_clang_tidy %s objc-avoid-spinlock %t
+
+typedef int OSSpinLock;
+void OSSpinlockTry(OSSpinLock *__lock) {}
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: deprecated usage of OSSpinlock; Please use other locks or dispatch queue [objc-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: deprecated usage of OSSpinlock; Please use other locks or dispatch queue [objc-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: deprecated usage of OSSpinlock; Please use other locks or dispatch queue [objc-avoid-spinlock]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-spinlock.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - objc-avoid-spinlock
+
+objc-avoid-spinlock
+===
+
+Finds usages of OSSpinlock in Objective-C files, which is deprecated due to potential
+livelock problems. 
+
+This check will detect following function invocations:
+
+- `OSSpinlockLock`
+- `OSSpinlockTry`
+- `OSSpinlockUnlock`
+
+The corresponding information about the problem of OSSpinlock: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
performance-faster-string-find
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-spinlock
+  `_ check
+
+  Add new check to detect the use of OSSpinlock in Objective-C files.
+
 - New `google-avoid-throwing-objc-exception
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tidy/objc/AvoidSpinlockCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock in Objective-C files, which is deprecated due to
+/// potential livelock problems.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-ti

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked 4 inline comments as done.
Wizard added inline comments.



Comment at: clang-tidy/objc/CMakeLists.txt:4
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp

benhamilton wrote:
> IMHO this is really a check which should apply to products built on Apple 
> SDKs, not for Objective-C.
> 
> I don't know if that means we should move this to an `apple` submodule or if 
> there is a better solution.
> 
> You don't have to move it in this review, but let's open up a discussion to 
> figure out where non-ObjC checks should go.
Sure. It would be a good time to move them when we have more `apple` checks 
like this.


https://reviews.llvm.org/D40325



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


[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124434.
Wizard marked 5 inline comments as done.
Wizard added a comment.

fix doc


https://reviews.llvm.org/D40325

Files:
  clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-spinlock.rst
  test/clang-tidy/objc-avoid-spinlock.m

Index: test/clang-tidy/objc-avoid-spinlock.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-spinlock.m
@@ -0,0 +1,16 @@
+// RUN: %check_clang_tidy %s objc-avoid-spinlock %t
+
+typedef int OSSpinLock;
+void OSSpinlockTry(OSSpinLock *__lock) {}
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-spinlock.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - objc-avoid-spinlock
+
+objc-avoid-spinlock
+===
+
+Finds usages of OSSpinlock, which is deprecated due to potential
+livelock problems. 
+
+This check will detect following function invocations:
+
+- `OSSpinlockLock`
+- `OSSpinlockTry`
+- `OSSpinlockUnlock`
+
+The corresponding information about the problem of OSSpinlock: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
performance-faster-string-find
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-spinlock
+  `_ check
+
+  Add new check to detect the use of OSSpinlock.
+
 - New `google-avoid-throwing-objc-exception
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tidy/objc/AvoidSpinlockCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
+/// problems.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked an inline comment as done.
Wizard added inline comments.



Comment at: test/clang-tidy/objc-avoid-spinlock.m:4
+typedef int OSSpinLock;
+void OSSpinlockTry(OSSpinLock *__lock) {}
+

benhamilton wrote:
> Not sure why you declared (and defined?) this one but not the others.
> 
> Either declare them all (no definition needed) or don't..
> 
Oh I added this when I tested the first method since I thought it is needed. 
But looks like I don't have to. Removed it.


https://reviews.llvm.org/D40325



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


[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124448.
Wizard added a comment.

fix test


https://reviews.llvm.org/D40325

Files:
  clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-spinlock.rst
  test/clang-tidy/objc-avoid-spinlock.m

Index: test/clang-tidy/objc-avoid-spinlock.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-spinlock.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s objc-avoid-spinlock %t
+
+typedef int OSSpinLock;
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-spinlock.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - objc-avoid-spinlock
+
+objc-avoid-spinlock
+===
+
+Finds usages of OSSpinlock, which is deprecated due to potential
+livelock problems. 
+
+This check will detect following function invocations:
+
+- `OSSpinlockLock`
+- `OSSpinlockTry`
+- `OSSpinlockUnlock`
+
+The corresponding information about the problem of OSSpinlock: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -175,6 +175,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
performance-faster-string-find
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-spinlock
+  `_ check
+
+  Add new check to detect the use of OSSpinlock.
+
 - New `google-avoid-throwing-objc-exception
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tidy/objc/AvoidSpinlockCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
+/// problems.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-spinlock.html
+class AvoidSpinlockCheck : public Clang

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124456.
Wizard added a comment.
Herald added a subscriber: klimek.

fix conflict


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40325

Files:
  clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-spinlock.rst
  test/clang-tidy/objc-avoid-spinlock.m

Index: test/clang-tidy/objc-avoid-spinlock.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-spinlock.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s objc-avoid-spinlock %t
+
+typedef int OSSpinLock;
+
+@implementation Foo
+- (void)f {
+int i = 1;
+OSSpinlockLock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockTry(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+OSSpinlockUnlock(&i);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [objc-avoid-spinlock]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-spinlock.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-spinlock.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - objc-avoid-spinlock
+
+objc-avoid-spinlock
+===
+
+Finds usages of OSSpinlock, which is deprecated due to potential
+livelock problems. 
+
+This check will detect following function invocations:
+
+- `OSSpinlockLock`
+- `OSSpinlockTry`
+- `OSSpinlockUnlock`
+
+The corresponding information about the problem of OSSpinlock: https://blog.postmates.com/why-spinlocks-are-bad-on-ios-b69fc5221058
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -174,6 +174,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
performance-faster-string-find
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-spinlock
+  `_ check
+
+  Add new check to detect the use of OSSpinlock.
+
 - The 'misc-move-constructor-init' check was renamed to `performance-move-constructor-init
   `_
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tidy/objc/AvoidSpinlockCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
+/// problems.
+///
+/// For the user-facing documentation see:
+

[PATCH] D40325: add new check to find OSSpinlock usage

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319098: add new check to find OSSpinlock usage (authored by 
Wizard).

Repository:
  rL LLVM

https://reviews.llvm.org/D40325

Files:
  clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
  clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/objc-avoid-spinlock.rst
  clang-tools-extra/trunk/test/clang-tidy/objc-avoid-spinlock.m

Index: clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
 
@@ -22,6 +23,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
   PropertyDeclarationCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
+/// problems.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-spinlock.html
+class AvoidSpinlockCheck : public ClangTidyCheck {
+ public:
+  AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp
@@ -0,0 +1,37 @@
+//===--- AvoidSpinlockCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AvoidSpinlockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee((functionDecl(hasAnyName(
+   "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry")
+  .bind("spinlock"),
+  this);
+}
+
+void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("spinlock");
+  diag(MatchedExpr->getLocStart(),
+   "use os_unfair_lock_lock() or dispatch queue APIs instead of the "
+   "deprecated OSSpinLock");
+}
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
I

[PATCH] D40528: add new check to find NSError init invocation

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, mgorny, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528

Files:
  clang-tidy/objc/AvoidNserrorInitCheck.cpp
  clang-tidy/objc/AvoidNserrorInitCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  test/clang-tidy/objc-avoid-nserror-init.m

Index: test/clang-tidy/objc-avoid-nserror-init.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-nserror-init.m
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+@interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@implementation foo
+- (void)bar {
+NSError *error = [[NSError alloc] init];
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-nserror-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-nserror-init.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-avoid-nserror-init
+
+objc-avoid-nserror-init
+===
+
+This check will find out improper initialization of NSError objects.
+
+According to Apple developer document, we should always use factory method 
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during compilation in Xcode.
+
+The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -174,6 +174,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New `objc-avoid-spinlock
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNserrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidNserrorInitCheck.cpp
   AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
Index: clang-tidy/objc/AvoidNserrorInitCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidNserrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNserrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of [NSSError init]. It is not the proper way of creating
+/// NSError. errorWithDomain:code:userInfo: should be used instead.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.ht

[PATCH] D40528: add new check to find NSError init invocation

2017-11-27 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124486.
Wizard added a comment.

new line for doc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528

Files:
  clang-tidy/objc/AvoidNserrorInitCheck.cpp
  clang-tidy/objc/AvoidNserrorInitCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  test/clang-tidy/objc-avoid-nserror-init.m

Index: test/clang-tidy/objc-avoid-nserror-init.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-nserror-init.m
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+@interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@implementation foo
+- (void)bar {
+NSError *error = [[NSError alloc] init];
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-nserror-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-nserror-init.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-avoid-nserror-init
+
+objc-avoid-nserror-init
+===
+
+This check will find out improper initialization of NSError objects.
+
+According to Apple developer document, we should always use factory method 
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during compilation in Xcode.
+
+The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -174,6 +174,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New `objc-avoid-spinlock
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNserrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidNserrorInitCheck.cpp
   AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
Index: clang-tidy/objc/AvoidNserrorInitCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidNserrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNserrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of [NSSError init]. It is not the proper way of creating
+/// NSError. errorWithDomain:code:userInfo: should be used instead.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.html
+class AvoidNserrorIni

[PATCH] D40528: add new check to find NSError init invocation

2017-11-28 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: docs/clang-tidy/checks/objc-avoid-nserror-init.rst:10
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during compilation in Xcode.

hokein wrote:
> What's the warning message in Xcode? I suspect whether there is a diagnostic 
> flag in clang already. 
It was discussed originally here 
https://buganizer.corp.google.com/issues/62445078 I think


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528



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


[PATCH] D40528: add new check to find NSError init invocation

2017-11-29 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: docs/clang-tidy/checks/objc-avoid-nserror-init.rst:10
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during compilation in Xcode.

hokein wrote:
> Wizard wrote:
> > hokein wrote:
> > > What's the warning message in Xcode? I suspect whether there is a 
> > > diagnostic flag in clang already. 
> > It was discussed originally here 
> > https://buganizer.corp.google.com/issues/62445078 I think
> Thanks. Please don't include any internal links next time.
> 
> Looks like the error message 
> (https://stackoverflow.com/questions/33720042/why-does-nserror-alloc-init-in-xcode-throw-an-error)
>  is shown during runtime, instead of compilation. Could you please confirm 
> it, and update the document here? 
> 
> > [NSError init] called; this results in an invalid NSError instance. It will 
> > raise an exception in a future release. Please call 
> > errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This 
> > message shown only once.
Oh yes it is shown during runtime. Will update the doc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528



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


[PATCH] D40528: add new check to find NSError init invocation

2017-11-29 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124818.
Wizard marked 3 inline comments as done.
Wizard added a comment.

address comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528

Files:
  clang-tidy/objc/AvoidNserrorInitCheck.cpp
  clang-tidy/objc/AvoidNserrorInitCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  test/clang-tidy/objc-avoid-nserror-init.m

Index: test/clang-tidy/objc-avoid-nserror-init.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-nserror-init.m
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+@interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@implementation foo
+- (void)bar {
+NSError *error = [[NSError alloc] init];
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-nserror-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-nserror-init.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-avoid-nserror-init
+
+objc-avoid-nserror-init
+===
+
+This check will find out improper initialization of NSError objects.
+
+According to Apple developer document, we should always use factory method 
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during runtime.
+
+The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -174,6 +174,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New `objc-avoid-spinlock
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidNSErrorInitCheck.cpp
   AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
Index: clang-tidy/objc/AvoidNserrorInitCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidNserrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNSErrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of [NSSError init]. It is not the proper way of creating
+/// NSError. errorWithDomain:code:userInfo: should be used instead.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-ti

[PATCH] D40528: add new check to find NSError init invocation

2017-11-30 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124971.
Wizard added a comment.

change file name cases


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528

Files:
  clang-tidy/objc/AvoidNSEErrorInitCheck.cpp
  clang-tidy/objc/AvoidNSEErrorInitCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  test/clang-tidy/objc-avoid-nserror-init.m

Index: test/clang-tidy/objc-avoid-nserror-init.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-nserror-init.m
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+@interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@implementation foo
+- (void)bar {
+NSError *error = [[NSError alloc] init];
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-nserror-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-nserror-init.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-avoid-nserror-init
+
+objc-avoid-nserror-init
+===
+
+This check will find out improper initialization of NSError objects.
+
+According to Apple developer document, we should always use factory method 
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during runtime.
+
+The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -173,6 +173,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New module `fuchsia` for Fuchsia style checks.
 
 - New module `objc` for Objective-C style checks.
@@ -158,6 +163,11 @@
   Finds uses of bitwise operations on signed integer types, which may lead to 
   undefined or implementation defined behaviour.
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New `objc-avoid-spinlock
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidNSErrorInitCheck.cpp
   AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
Index: clang-tidy/objc/AvoidNSEErrorInitCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidNSEErrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNSErrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINI

[PATCH] D40528: add new check to find NSError init invocation

2017-11-30 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319459: add new check to find NSError init invocation 
(authored by Wizard).

Changed prior to commit:
  https://reviews.llvm.org/D40528?vs=124972&id=124974#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40528

Files:
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
  clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  clang-tools-extra/trunk/test/clang-tidy/objc-avoid-nserror-init.m

Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNSErrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of [NSSError init]. It is not the proper way of creating
+/// NSError. errorWithDomain:code:userInfo: should be used instead.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.html
+class AvoidNSErrorInitCheck : public ClangTidyCheck {
+ public:
+  AvoidNSErrorInitCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
@@ -0,0 +1,37 @@
+//===--- AvoidNSErrorInitCheck.cpp - clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AvoidNSErrorInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(objcMessageExpr(hasSelector("init"),
+ hasReceiverType(asString("NSError *")))
+ .bind("nserrorInit"),
+ this);
+}
+
+void AvoidNSErrorInitCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr =
+  Result.Nodes.getNodeAs("nserrorInit");
+  diag(MatchedExpr->getLocStart(),
+   "use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to "
+   "create a new NSError");
+}
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/objc/C

[PATCH] D40528: add new check to find NSError init invocation

2017-11-30 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 124972.
Wizard added a comment.

restore file names


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40528

Files:
  clang-tidy/objc/AvoidNSErrorInitCheck.cpp
  clang-tidy/objc/AvoidNSErrorInitCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-nserror-init.rst
  test/clang-tidy/objc-avoid-nserror-init.m

Index: test/clang-tidy/objc-avoid-nserror-init.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-nserror-init.m
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+@interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+@end
+
+@implementation foo
+- (void)bar {
+NSError *error = [[NSError alloc] init];
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+@end
Index: docs/clang-tidy/checks/objc-avoid-nserror-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-nserror-init.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-avoid-nserror-init
+
+objc-avoid-nserror-init
+===
+
+This check will find out improper initialization of NSError objects.
+
+According to Apple developer document, we should always use factory method 
+``errorWithDomain:code:userInfo:`` to create new NSError objects instead
+of ``[NSError alloc] init]``. Otherwise it will lead to a warning message
+during runtime.
+
+The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -173,6 +173,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New module `fuchsia` for Fuchsia style checks.
 
 - New module `objc` for Objective-C style checks.
@@ -158,6 +163,11 @@
   Finds uses of bitwise operations on signed integer types, which may lead to 
   undefined or implementation defined behaviour.
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New `objc-avoid-spinlock
   `_ check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
 #include "PropertyDeclarationCheck.h"
@@ -23,6 +24,8 @@
 class ObjCModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"objc-avoid-nserror-init");
 CheckFactories.registerCheck(
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
Index: clang-tidy/objc/CMakeLists.txt
===
--- clang-tidy/objc/CMakeLists.txt
+++ clang-tidy/objc/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  AvoidNSErrorInitCheck.cpp
   AvoidSpinlockCheck.cpp
   ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
Index: clang-tidy/objc/AvoidNSErrorInitCheck.h
===
--- /dev/null
+++ clang-tidy/objc/AvoidNSErrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNSErrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H

[PATCH] D40528: add new check to find NSError init invocation

2017-11-30 Thread Yan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319460: add new check to find NSError init invocation 
(authored by Wizard).

Changed prior to commit:
  https://reviews.llvm.org/D40528?vs=124972&id=124973#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40528

Files:
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst

Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h
@@ -0,0 +1,36 @@
+//===--- AvoidNSErrorInitCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds usages of [NSSError init]. It is not the proper way of creating
+/// NSError. errorWithDomain:code:userInfo: should be used instead.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.html
+class AvoidNSErrorInitCheck : public ClangTidyCheck {
+ public:
+  AvoidNSErrorInitCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -0,0 +1,37 @@
+//===--- AvoidNSErrorInitCheck.cpp - clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "AvoidNSErrorInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(objcMessageExpr(hasSelector("init"),
+ hasReceiverType(asString("NSError *")))
+ .bind("nserrorInit"),
+ this);
+}
+
+void AvoidNSErrorInitCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr =
+  Result.Nodes.getNodeAs("nserrorInit");
+  diag(MatchedExpr->getLocStart(),
+   "use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to "
+   "create a new NSError");
+}
+
+}  // namespace objc
+}  // namespace tidy
+}  // namespace clang
Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-avoid-nserror-init
+  `_ check
+
+  Add new check to detect the use of [NSError init].
+
 - New module `fuchsia` for Fuchsia style checks.
 
 - New module `objc` for Objective-C style checks.
Index: clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
@@ -1,37 +0,0 @@
-//===--- AvoidNSErrorInitCheck.cpp - clang-tidy===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===

[PATCH] D44634: [clang-format] Detect Objective-C for #import

2018-03-21 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

Why do we only detect system framework? I think any #import could indicate ObjC 
header.


Repository:
  rC Clang

https://reviews.llvm.org/D44634



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


[PATCH] D44634: [clang-format] Detect Objective-C for #import

2018-03-21 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

For some ObjC headers it uses #import to import other headers instead of system 
framework, so I think we should also detect #import "*.h" as well.

The only usage of #import in C++  is to import type library, which won't have 
suffix of ".h".


Repository:
  rC Clang

https://reviews.llvm.org/D44634



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


[PATCH] D45392: add new check to find out objc ivars which do not have prefix '_'

2018-04-06 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, mgorny, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/IvarDeclarationCheck.cpp
  clang-tidy/objc/IvarDeclarationCheck.h
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-ivar-declaration.rst
  test/clang-tidy/objc-ivar-declaration.m

Index: test/clang-tidy/objc-ivar-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-ivar-declaration.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-ivar-declaration %t
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: instance variable 'barWithoutPrefix' not using '_' as prefix [objc-ivar-declaration]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: docs/clang-tidy/checks/objc-ivar-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-ivar-declaration.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - objc-ivar-declaration
+
+objc-ivar-declaration
+=
+
+Finds ivar declarations in Objective-C files that do not follow the pattern
+in Apple's programming guide. The ivar name should be fixed with '_'.
+
+For code of ivar declaration:
+
+.. code-block:: objc
+
+   int barWithoutPrefix;
+
+The fix will be:
+
+.. code-block:: objc
+
+   int _barWithoutPrefix;
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
+   objc-ivar-declaration
objc-property-declaration
performance-faster-string-find
performance-for-range-copy
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New :doc:`objc-ivar-declaration
+  ` check
+
+  New check that finds Objective-C ivars that do not have a '_' prefix.
+
 - New module `abseil` for checks related to the `Abseil `_
   library.
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
+#include "IvarDeclarationCheck.h"
 #include "PropertyDeclarationCheck.h"
 
 using namespace clang::ast_matchers;
@@ -30,6 +31,8 @@
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
+CheckFactories.registerCheck(
+"objc-ivar-declaration");
 CheckFactories.registerCheck(
 "objc-property-declaration");
   }
Index: clang-tidy/objc/IvarDeclarationCheck.h
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.h
@@ -0,0 +1,35 @@
+//===--- IvarDeclarationCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C ivars which do not have '_' prefix.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-ivar-declaration.html
+class IvarDeclarationCheck : public ClangTidyCheck {
+public:
+  IvarDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
Index: clang-tidy/objc/IvarDeclarationCheck.cpp
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.cpp
@@ -0,0 +1,52 @@
+//===--- Iv

[PATCH] D45392: add new check to find out objc ivars which do not have prefix '_'

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

fix doc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/IvarDeclarationCheck.cpp
  clang-tidy/objc/IvarDeclarationCheck.h
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-ivar-declaration.rst
  test/clang-tidy/objc-ivar-declaration.m

Index: test/clang-tidy/objc-ivar-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-ivar-declaration.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-ivar-declaration %t
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: instance variable 'barWithoutPrefix' not using '_' as prefix [objc-ivar-declaration]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: docs/clang-tidy/checks/objc-ivar-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-ivar-declaration.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - objc-ivar-declaration
+
+objc-ivar-declaration
+=
+
+Finds ivar declarations in Objective-C files that do not follow the pattern
+in Apple's programming guide. The ivar name should be fixed with '_'.
+
+For code of ivar declaration:
+
+.. code-block:: objc
+
+   int barWithoutPrefix;
+
+The fix will be:
+
+.. code-block:: objc
+
+   int _barWithoutPrefix;
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
+   objc-ivar-declaration
objc-property-declaration
performance-faster-string-find
performance-for-range-copy
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New :doc:`objc-ivar-declaration
+  ` check
+
+  New check that finds Objective-C ivars that do not have a '_' prefix.
+
 - New module `abseil` for checks related to the `Abseil `_
   library.
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
+#include "IvarDeclarationCheck.h"
 #include "PropertyDeclarationCheck.h"
 
 using namespace clang::ast_matchers;
@@ -30,6 +31,8 @@
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
+CheckFactories.registerCheck(
+"objc-ivar-declaration");
 CheckFactories.registerCheck(
 "objc-property-declaration");
   }
Index: clang-tidy/objc/IvarDeclarationCheck.h
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.h
@@ -0,0 +1,35 @@
+//===--- IvarDeclarationCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C ivars which do not have '_' prefix.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-ivar-declaration.html
+class IvarDeclarationCheck : public ClangTidyCheck {
+public:
+  IvarDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
Index: clang-tidy/objc/IvarDeclarationCheck.cpp
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.cpp
@@ -0,0 +1,52 @@
+//===--- IvarDeclarationCheck.cpp - clang-tid

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked 4 inline comments as done.
Wizard added a comment.

In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:

> If this is Apple guideline, check name should reflect this. I think will be 
> good idea to have general check for Apple naming conventions instead of 
> separate checks for specific situations like //objc-ivar-declaration// and 
> //objc-property-declaration//.


Thanks for the suggestion. I understand your point that they are both naming 
convention, however, they are about different components and using totally 
different naming rules. PropertyDeclarationCheck is already a very complicated 
check (the most complicated one for ObjC), I would rather not make it more 
heavy and try my best to split independent logic to different checks.




Comment at: clang-tidy/objc/IvarDeclarationCheck.cpp:23
+
+FixItHint generateFixItHint(const ObjCIvarDecl *Decl) {
+  auto IvarName = Decl->getName();

Eugene.Zelenko wrote:
> Please use static instead of anonymous namespace.
Using anonymous namespace was suggested by others for private methods that are 
only used within the check (e.g. ForbiddenSubclassingCheck, 
PropertyDeclarationCheck, etc). I would rather keep this pattern consistent 
with other checks.



Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`objc-ivar-declaration
+  ` check

Eugene.Zelenko wrote:
> Please place in new check list in alphabetical order.
I did not see a "new check list" in alphabetical order in this file. I believe 
they are ordered by commit time.If you mean the list.rst, they are already 
ordered alphabetically.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 141515.
Wizard edited the summary of this revision.
Wizard added a comment.

resolve comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/IvarDeclarationCheck.cpp
  clang-tidy/objc/IvarDeclarationCheck.h
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-ivar-declaration.rst
  test/clang-tidy/objc-ivar-declaration.m

Index: test/clang-tidy/objc-ivar-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-ivar-declaration.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-ivar-declaration %t
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: instance variable 'barWithoutPrefix' not using '_' as prefix [objc-ivar-declaration]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: docs/clang-tidy/checks/objc-ivar-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-ivar-declaration.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - objc-ivar-declaration
+
+objc-ivar-declaration
+=
+
+Finds Objective-C ivars that do not have a '_' prefix.
+According to Apple's programming guide, the ivar names should be 
+prefixed with '_'.
+
+For code of ivar declaration:
+
+.. code-block:: objc
+
+   int barWithoutPrefix;
+
+The fix will be:
+
+.. code-block:: objc
+
+   int _barWithoutPrefix;
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
+   objc-ivar-declaration
objc-property-declaration
performance-faster-string-find
performance-for-range-copy
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New :doc:`objc-ivar-declaration
+  ` check
+
+  Finds Objective-C ivars that do not have a '_' prefix.
+
 - New module `abseil` for checks related to the `Abseil `_
   library.
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
+#include "IvarDeclarationCheck.h"
 #include "PropertyDeclarationCheck.h"
 
 using namespace clang::ast_matchers;
@@ -30,6 +31,8 @@
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
+CheckFactories.registerCheck(
+"objc-ivar-declaration");
 CheckFactories.registerCheck(
 "objc-property-declaration");
   }
Index: clang-tidy/objc/IvarDeclarationCheck.h
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.h
@@ -0,0 +1,35 @@
+//===--- IvarDeclarationCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C ivars which do not have '_' prefix.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-ivar-declaration.html
+class IvarDeclarationCheck : public ClangTidyCheck {
+public:
+  IvarDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
Index: clang-tidy/objc/IvarDeclarationCheck.cpp
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.cpp
@@ -0,0 +1,52 @@
+//===--- Iva

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-07 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D45392#1060854, @Eugene.Zelenko wrote:

> In https://reviews.llvm.org/D45392#1060845, @Wizard wrote:
>
> > In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:
> >
> > > If this is Apple guideline, check name should reflect this. I think will 
> > > be good idea to have general check for Apple naming conventions instead 
> > > of separate checks for specific situations like //objc-ivar-declaration// 
> > > and //objc-property-declaration//.
> >
> >
> > Thanks for the suggestion. I understand your point that they are both 
> > naming convention, however, they are about different components and using 
> > totally different naming rules. PropertyDeclarationCheck is already a very 
> > complicated check (the most complicated one for ObjC), I would rather not 
> > make it more heavy and try my best to split independent logic to different 
> > checks.
>
>
> See readability-identifier-naming 
> 
>  as example of multiple rules in one check.


I took a look at IdentifierNamingCheck. Here's my thought:

1. IdentifierNamingCheck is trying to apply configurable naming convention to 
C++ identifiers, and all the identifiers will share the same style set. That is 
not the case of ObjC, where we follow Apple's programming guide, and different 
types of identifiers are using different style.
2. Such pattern can handle complicated requirements but to me it is not simple 
enough to read and maintain. I would rather keep things simple and clear as 
long as we have choice.

However, this check provides a good example of refactoring if in the future we 
have the needs of organizing complicated naming styles. Moving from simplicity 
to complexity is always easier. Thanks for pointing this out for us.




Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`objc-ivar-declaration
+  ` check

Eugene.Zelenko wrote:
> Wizard wrote:
> > Eugene.Zelenko wrote:
> > > Please place in new check list in alphabetical order.
> > I did not see a "new check list" in alphabetical order in this file. I 
> > believe they are ordered by commit time.If you mean the list.rst, they are 
> > already ordered alphabetically.
> Please read starting words in list of changes.
Hmm line 96 is "- New :doc:`fuchsia-multiple-inheritance 
` check", while line 101 is "- 
New :doc:`abseil-string-find-startswith 
` check". And similar thing 
happened to line 138. I thought it wasn't alphabetical. But that's probably 
mistakes from others. I will fix this one.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-08 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D45392#1060971, @Eugene.Zelenko wrote:

> In https://reviews.llvm.org/D45392#1060912, @Wizard wrote:
>
> > In https://reviews.llvm.org/D45392#1060854, @Eugene.Zelenko wrote:
> >
> > > In https://reviews.llvm.org/D45392#1060845, @Wizard wrote:
> > >
> > > > In https://reviews.llvm.org/D45392#1060485, @Eugene.Zelenko wrote:
> > > >
> > > > > If this is Apple guideline, check name should reflect this. I think 
> > > > > will be good idea to have general check for Apple naming conventions 
> > > > > instead of separate checks for specific situations like 
> > > > > //objc-ivar-declaration// and //objc-property-declaration//.
> > > >
> > > >
> > > > Thanks for the suggestion. I understand your point that they are both 
> > > > naming convention, however, they are about different components and 
> > > > using totally different naming rules. PropertyDeclarationCheck is 
> > > > already a very complicated check (the most complicated one for ObjC), I 
> > > > would rather not make it more heavy and try my best to split 
> > > > independent logic to different checks.
> > >
> > >
> > > See readability-identifier-naming 
> > > 
> > >  as example of multiple rules in one check.
> >
> >
> > I took a look at IdentifierNamingCheck. Here's my thought:
> >
> > 1. IdentifierNamingCheck is trying to apply configurable naming convention 
> > to C++ identifiers, and all the identifiers will share the same style set. 
> > That is not the case of ObjC, where we follow Apple's programming guide, 
> > and different types of identifiers are using different style.
> > 2. Such pattern can handle complicated requirements but to me it is not 
> > simple enough to read and maintain. I would rather keep things simple and 
> > clear as long as we have choice.
> >
> >   However, this check provides a good example of refactoring if in the 
> > future we have the needs of organizing complicated naming styles. Moving 
> > from simplicity to complexity is always easier. Thanks for pointing this 
> > out for us.
>
>
> My point is not flexibility of configuration, but handling of various types 
> of identifiers in same check, even if conventions are different.


Yes I understand but I mean "flexibility of configuration" is one of the 
reasons of handling of various types of identifiers in same check, but we don't 
need it here.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-08 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 141574.
Wizard added a comment.

reorder release note for alphabetical order


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/IvarDeclarationCheck.cpp
  clang-tidy/objc/IvarDeclarationCheck.h
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-ivar-declaration.rst
  test/clang-tidy/objc-ivar-declaration.m

Index: test/clang-tidy/objc-ivar-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-ivar-declaration.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-ivar-declaration %t
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: instance variable 'barWithoutPrefix' not using '_' as prefix [objc-ivar-declaration]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: docs/clang-tidy/checks/objc-ivar-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-ivar-declaration.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - objc-ivar-declaration
+
+objc-ivar-declaration
+=
+
+Finds Objective-C ivars that do not have a '_' prefix.
+According to Apple's programming guide, the ivar names should be 
+prefixed with '_'.
+
+For code of ivar declaration:
+
+.. code-block:: objc
+
+   int barWithoutPrefix;
+
+The fix will be:
+
+.. code-block:: objc
+
+   int _barWithoutPrefix;
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
objc-avoid-nserror-init
objc-avoid-spinlock
objc-forbidden-subclassing
+   objc-ivar-declaration
objc-property-declaration
performance-faster-string-find
performance-for-range-copy
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -124,6 +124,11 @@
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
+- New :doc:`objc-ivar-declaration
+  ` check
+
+  Finds Objective-C ivars that do not have a '_' prefix.
+
 - New :doc:`portability-simd-intrinsics
   ` check
 
Index: clang-tidy/objc/ObjCTidyModule.cpp
===
--- clang-tidy/objc/ObjCTidyModule.cpp
+++ clang-tidy/objc/ObjCTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "AvoidNSErrorInitCheck.h"
 #include "AvoidSpinlockCheck.h"
 #include "ForbiddenSubclassingCheck.h"
+#include "IvarDeclarationCheck.h"
 #include "PropertyDeclarationCheck.h"
 
 using namespace clang::ast_matchers;
@@ -30,6 +31,8 @@
 "objc-avoid-spinlock");
 CheckFactories.registerCheck(
 "objc-forbidden-subclassing");
+CheckFactories.registerCheck(
+"objc-ivar-declaration");
 CheckFactories.registerCheck(
 "objc-property-declaration");
   }
Index: clang-tidy/objc/IvarDeclarationCheck.h
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.h
@@ -0,0 +1,35 @@
+//===--- IvarDeclarationCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+/// Finds Objective-C ivars which do not have '_' prefix.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/objc-ivar-declaration.html
+class IvarDeclarationCheck : public ClangTidyCheck {
+public:
+  IvarDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_IVARDECLARATIONCHECK_H
Index: clang-tidy/objc/IvarDeclarationCheck.cpp
===
--- /dev/null
+++ clang-tidy/objc/IvarDeclarationCheck.cpp
@@ -0,0 +1,52 @@
+//===--- IvarDecl

[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-09 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D45392#1061433, @alexfh wrote:

> I wonder whether the readability-identifier-naming check could be extended to 
> support this use case instead of adding a new check specifically for 
> underscores in ivar names?


Hmm readability-identifier-naming is a C++ check but this one is only for ObjC. 
I prefer putting them in separate places unless they work for both languages.
Moreover, readability-identifier-naming always runs all matchers and apply the 
same checks on all identifiers. We have to change at least part of the 
structure to make it applicable for this check. And 
readability-identifier-naming is not in google default clang-tidy check list 
yet. We will even need more work to import it.
So I think creating a new simple ObjC-specific check is a better way here.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-10 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 141938.
Wizard added a comment.

move check to readability-identifier-naming


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,20 @@
+// Remove UNSUPPORTED for powerpc64le when the problem introduced by
+// r288563 is resolved.
+// UNSUPPORTED: powerpc64le
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}, \
+// RUN:   ]}' -- -fno-delayed-template-parsing \
+// RUN:   -I%S/Inputs/readability-identifier-naming \
+// RUN:   -isystem %S/Inputs/readability-identifier-naming/system
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,20 @@
+// Remove UNSUPPORTED for powerpc64le when the problem introduced by
+// r288563 is resolved.
+// UNSUPPORTED: powerpc64le
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}, \
+// RUN:   ]}' -- -fno-delayed-template-parsing \
+// RUN:   -I%S/Inputs/readability-identifier-naming \
+// RUN:   -isystem %S/Inputs/readability-identifier-naming/system
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-10 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

In https://reviews.llvm.org/D45392#1063164, @alexfh wrote:

> In https://reviews.llvm.org/D45392#1061960, @Wizard wrote:
>
> > In https://reviews.llvm.org/D45392#1061433, @alexfh wrote:
> >
> > > I wonder whether the readability-identifier-naming check could be 
> > > extended to support this use case instead of adding a new check 
> > > specifically for underscores in ivar names?
> >
> >
> > Hmm readability-identifier-naming is a C++ check but this one is only for 
> > ObjC. I prefer putting them in separate places unless they work for both 
> > languages.
>
>
> I see no reasons why this check can't work for ObjC, if the handling of 
> ObjC-specific AST nodes is added to it.
>
> > Moreover, readability-identifier-naming always runs all matchers and apply 
> > the same checks on all identifiers.
>
> It has some sort of a hierarchical structure of rules that allow it to only 
> touch a certain subset of identifiers. E.g. configure different naming styles 
> for local variables and local constants. What it's lacking is a good 
> documentation for all of these options =\
>
> > We have to change at least part of the structure to make it applicable for 
> > this check.
>
> Yes, the existing check may need some modifications to do what this check 
> needs to do, but I'd expect these modifications to be quite small, and we 
> would potentially get a much more useful and generic tool instead of "one 
> check per type of named entity per naming style" situation.
>
> > And readability-identifier-naming is not in google default clang-tidy check 
> > list yet. We will even need more work to import it.
>
> IIUC, it can be configured to only verify certain kinds of named entities. 
> Thus there's no requirement to make it work with every aspect of our naming 
> rules.
>
> > So I think creating a new simple ObjC-specific check is a better way here.
>
> I'll respectfully disagree here. I would prefer to have a generic solution, 
> if it's feasible. And so far, it looks like it is.


Done. Yes it is very small changes to integrate this into it. I like it. The 
only annoying part was the doc is not that good and I spent a lot of time 
understanding the whole structure. Just one question, when we enable it in 
google by default, do we need to take care of the flags in the tests like 
-I%S/Inputs/readability-identifier-naming and -isystem 
%S/Inputs/readability-identifier-naming/system?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-11 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 142057.
Wizard added a comment.

remove unnecessary flags


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming-objc.m


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 


Index: test/clang-tidy/readability-identifier-naming-objc.m
===
--- /dev/null
+++ test/clang-tidy/readability-identifier-naming-objc.m
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+@interface Foo
+@end 
+
+@interface Foo () {
+int _bar;
+int barWithoutPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+// CHECK-FIXES: int _barWithoutPrefix;
+}
+@end
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -109,6 +109,7 @@
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
+m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
+  if (isa(D) && NamingStyles[SK_ObjcIvar])
+return SK_ObjcIvar;
+
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45392: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-11 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: test/clang-tidy/readability-identifier-naming-objc.m:8-9
+// RUN:   ]}' -- -fno-delayed-template-parsing \
+// RUN:   -I%S/Inputs/readability-identifier-naming \
+// RUN:   -isystem %S/Inputs/readability-identifier-naming/system
+

alexfh wrote:
> It looks like these flags are not needed, since there are no #include 
> directives in this test.
So we won't worry about those flags when using this check in google codebase 
right?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45392



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


[PATCH] D39829: add new check for property declaration

2017-11-09 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 122319.
Wizard marked 6 inline comments as done.
Wizard added a comment.

address comments


https://reviews.llvm.org/D39829

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-property-declaration.m
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t
+
+@interface Foo
+@property(assign, nonatomic) int NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property 'NotCamelCase' is not in proper format according to property naming convention [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
+@property(assign, nonatomic) int camelCase;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:34: warning: property 'camelCase' is not in proper format according to property naming convention [objc-property-declaration]
+@end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - objc-property-declaration
+
+objc-property-declaration
+=
+
+Finds property declarations in Objective-C files that do not follow the pattern
+of property names in Apple's programming guide. The property name should be
+in the format of Lower Camel Case.
+
+For code:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int LowerCamelCase;
+
+The fix will be:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int lowerCamelCase;
+
+The check will do best effort to give a fix, however, in some cases it is
+difficult to give a proper fix since the property name could be complicated.
+Users will need to come up with a proper name by their own.
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -173,15 +173,16 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-forbidden-subclassing
+   objc-property-declaration
performance-faster-string-find
performance-for-range-copy
performance-implicit-conversion-in-loop
performance-inefficient-string-concatenation
performance-inefficient-vector-operation
performance-type-promotion-in-math-fn
performance-unnecessary-copy-initialization
performance-unnecessary-value-param
-   objc-forbidden-subclassing
readability-avoid-const-params-in-decls
readability-braces-around-statements
readability-container-size-empty
Index: docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
===
--- docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
+++ docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
@@ -3,7 +3,7 @@
 google-objc-global-variable-declaration
 ===
 
-Finds global variable declarations in Objective-C files that are not follow the pattern
+Finds global variable declarations in Objective-C files that do not follow the pattern
 of variable names in Google's Objective-C Style Guide.
 
 The corresponding style guide rule:
@@ -16,26 +16,31 @@
 For code:
 
 .. code-block:: objc
+
   static NSString* myString = @"hello";
 
 The fix will be:
 
 .. code-block:: objc
+
   static NSString* gMyString = @"hello";
 
 Another example of constant:
 
 .. code-block:: objc
+
   static NSString* const myConstString = @"hello";
 
 The fix will be:
 
 .. code-block:: objc
+
   static NSString* const kMyConstString = @"hello";
 
 However for code that prefixed with non-alphabetical characters like:
 
 .. code-block:: objc
+
   static NSString* __anotherString = @"world";
 
 The check will give a warning message but will not be able to suggest a fix. The user
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `objc-property-declaration
+  `_ check
+
+  FIXME: add release notes.
+
 - New `google-objc-global-variable-declaration
   

[PATCH] D39829: add new check for property declaration

2017-11-09 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:25
+/// we will do best effort to generate a fix, however, if the
+/// case can not be solved with a simple fix (e.g. remove prefix or change 
first
+/// character), we will leave the fix to the user.

benhamilton wrote:
> hokein wrote:
> > I might miss some background context. 
> > 
> > The fix of the check seems to me that it does more things it should. It 
> > removes all the non-alphabetical prefix characters, I'd be conservative of 
> > the fix here (just fix the case "CamelCase", and only give a warning for 
> > other cases).
> I agree, removing a prefix is not a good idea. Warning is fine.
> 
> We could probably also change `snake_case` variables to `CamelCase` 
> automatically. Not sure if it's worth doing in this review, but @Wizard can 
> file a bug to follow up and add a TODO comment here mentioning the bug.
Will do


https://reviews.llvm.org/D39829



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


[PATCH] D39829: add new check for property declaration

2017-11-10 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added inline comments.



Comment at: test/clang-tidy/objc-property-declaration.m:8
+@property(assign, nonatomic) int camelCase;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:34: warning: property 'camelCase' is not 
in proper format according to property naming convention 
[objc-property-declaration]
+@end

hokein wrote:
> Why does the check catch this case? Isn't `camelCase` a correct name?
This is CHECK-MESSAGES-NOT


https://reviews.llvm.org/D39829



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


[PATCH] D39829: add new check for property declaration

2017-11-10 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 122552.
Wizard marked 9 inline comments as done.
Wizard added a comment.

add custom options


https://reviews.llvm.org/D39829

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration-custom.m
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-property-declaration.m
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSString;
+
+@interface Foo
+@property(assign, nonatomic) int NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property 'NotCamelCase' is not in proper format according to property naming convention. It should be in the format of lowerCamelCase or has special acronyms [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
+@property(assign, nonatomic) int camelCase;
+@property(strong, nonatomic) NSString *URLString;
+@end
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- /dev/null
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \
+// RUN: --
+
+@interface Foo
+@property(assign, nonatomic) int AbcNotRealPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property 'AbcNotRealPrefix' is not in proper format according to property naming convention. It should be in the format of lowerCamelCase or has special acronyms [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int abcNotRealPrefix;
+@property(assign, nonatomic) int ABCCustomPrefix;
+@end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -0,0 +1,43 @@
+.. title:: clang-tidy - objc-property-declaration
+
+objc-property-declaration
+=
+
+Finds property declarations in Objective-C files that do not follow the pattern
+of property names in Apple's programming guide. The property name should be
+in the format of Lower Camel Case.
+
+For code:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int LowerCamelCase;
+
+The fix will be:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int lowerCamelCase;
+
+The check will only fix 'CamelCase' to 'camelCase'. In some other cases we will
+only provide warning messages since the property name could be complicated.
+Users will need to come up with a proper name by their own.
+
+This check also accepts special acronyms as prefix. Such prefix will suppress
+the check of Lower Camel Case according to the guide:
+https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
+
+For a full list of well-known acronyms:
+https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
+
+Options
+---
+
+.. option:: Acronyms
+
+   Semicolon-separated list of acronys that can be used as prefix
+   of property names.
+
+   Defaults to ``ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP``.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -173,15 +173,16 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-forbidden-subclassing
+   objc-property-declaration
performance-faster-string-find
performance-for-range-copy
performance-implicit-conversion-in-loop
performance-inefficient-string-concatenation
performance-inefficient-vector-operation
performance-type-promotion-in-math-fn
performance-unnecessary-copy-initialization
performance-unnecessary-value-param
-   objc-forbidden-subclassing
readability-avoid-const-params-in-decls
readability-braces-around-statements
readability-container-size-empty
Index: docs/clang-tidy/checks/google-objc-global-variable-declaration.rst

[PATCH] D39829: add new check for property declaration

2017-11-10 Thread Yan Zhang via Phabricator via cfe-commits
Wizard marked 2 inline comments as done.
Wizard added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:27
+FixItHint generateFixItHint(const ObjCPropertyDecl *Decl) {
+  if (isupper(Decl->getName()[0])) {
+auto NewName = Decl->getName().str();

hokein wrote:
> nit: I would add an assert to make sure the name is not empty.
Added it to the line before generating the warning message.



Comment at: docs/clang-tidy/checks/google-objc-global-variable-declaration.rst:1
 .. title:: clang-tidy - google-objc-global-variable-declaration
 

benhamilton wrote:
> Let's remove "google-" everywhere and mention only Apple's style guide.
Discussed offline. The change here is for another doc. Irrelevant to the new 
check.


https://reviews.llvm.org/D39829



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


[PATCH] D39829: add new check for property declaration

2017-11-13 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 122714.
Wizard marked 2 inline comments as done.
Wizard added a comment.

address nits


https://reviews.llvm.org/D39829

Files:
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration-custom.m
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- /dev/null
+++ test/clang-tidy/objc-property-declaration.m
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSString;
+
+@interface Foo
+@property(assign, nonatomic) int NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property 'NotCamelCase' is not in proper format according to property naming convention [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
+@property(assign, nonatomic) int camelCase;
+@property(strong, nonatomic) NSString *URLString;
+@end
Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- /dev/null
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \
+// RUN: --
+
+@interface Foo
+@property(assign, nonatomic) int AbcNotRealPrefix;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property 'AbcNotRealPrefix' is not in proper format according to property naming convention [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int abcNotRealPrefix;
+@property(assign, nonatomic) int ABCCustomPrefix;
+@end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -0,0 +1,43 @@
+.. title:: clang-tidy - objc-property-declaration
+
+objc-property-declaration
+=
+
+Finds property declarations in Objective-C files that do not follow the pattern
+of property names in Apple's programming guide. The property name should be
+in the format of Lower Camel Case.
+
+For code:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int LowerCamelCase;
+
+The fix will be:
+
+.. code-block:: objc
+
+@property(nonatomic, assign) int lowerCamelCase;
+
+The check will only fix 'CamelCase' to 'camelCase'. In some other cases we will
+only provide warning messages since the property name could be complicated.
+Users will need to come up with a proper name by their own.
+
+This check also accepts special acronyms as prefix. Such prefix will suppress
+the check of Lower Camel Case according to the guide:
+https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
+
+For a full list of well-known acronyms:
+https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+
+The corresponding style rule: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-1001757
+
+Options
+---
+
+.. option:: Acronyms
+
+   Semicolon-separated list of acronyms that can be used as prefix
+   of property names.
+
+   Defaults to ``ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP``.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -173,15 +173,16 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   objc-forbidden-subclassing
+   objc-property-declaration
performance-faster-string-find
performance-for-range-copy
performance-implicit-conversion-in-loop
performance-inefficient-string-concatenation
performance-inefficient-vector-operation
performance-type-promotion-in-math-fn
performance-unnecessary-copy-initialization
performance-unnecessary-value-param
-   objc-forbidden-subclassing
readability-avoid-const-params-in-decls
readability-braces-around-statements
readability-container-size-empty
Index: docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
===
--- docs/clang-tidy/checks/google-objc-global-variable-declaration.rst
+++ docs/clang-tidy/checks/google-objc-global-variable-declaration.rst

[PATCH] D39829: add new check for property declaration

2017-11-13 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

LGTM


https://reviews.llvm.org/D39829



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


[PATCH] D40058: add check to avoid throwing objc exception according to Google Objective-C guide

2017-11-14 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 122953.
Wizard added a comment.

new line


https://reviews.llvm.org/D40058

Files:
  clang-tidy/google/AvoidThrowingObjcExceptionCheck.cpp
  clang-tidy/google/AvoidThrowingObjcExceptionCheck.h
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GoogleTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/google-objc-avoid-throwing-exception.m

Index: test/clang-tidy/google-objc-avoid-throwing-exception.m
===
--- /dev/null
+++ test/clang-tidy/google-objc-avoid-throwing-exception.m
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t
+@class NSString;
+
+@implementation Foo
+- (void)f {
+NSString *foo = @"foo";
+@throw foo;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: avoid using @throw to handle Objective-C exceptions [google-objc-avoid-throwing-exception]
+}
+@end
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -60,6 +60,7 @@
google-default-arguments
google-explicit-constructor
google-global-names-in-headers
+   google-objc-avoid-throwing-exception
google-objc-global-variable-declaration
google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
Index: docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - google-objc-avoid-throwing-exception
+
+google-objc-avoid-throwing-exception
+===
+
+This check finds @throw usages in Objective-C files. According to Google's Objective-C
+Guide, we should not use @throw to handle exceptions.
+
+The corresponding style guide rule:
+http://go/objc-style#Avoid_Throwing_Exceptions
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `google-avoid-throwing-objc-exception
+  `_ check
+
+  Add new check to detect usage of @throw in Objective-C code, which should be avoided.
+
 - New `objc-property-declaration
   `_ check
 
Index: clang-tidy/google/GoogleTidyModule.cpp
===
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -15,6 +15,7 @@
 #include "../readability/NamespaceCommentCheck.h"
 #include "../readability/RedundantSmartptrGetCheck.h"
 #include "AvoidCStyleCastsCheck.h"
+#include "AvoidThrowingObjcExceptionCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "ExplicitConstructorCheck.h"
 #include "ExplicitMakePairCheck.h"
@@ -49,6 +50,8 @@
 "google-explicit-constructor");
 CheckFactories.registerCheck(
 "google-global-names-in-headers");
+CheckFactories.registerCheck(
+"google-objc-avoid-throwing-exception");
 CheckFactories.registerCheck(
 "google-objc-global-variable-declaration");
 CheckFactories.registerCheck(
Index: clang-tidy/google/CMakeLists.txt
===
--- clang-tidy/google/CMakeLists.txt
+++ clang-tidy/google/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_library(clangTidyGoogleModule
   AvoidCStyleCastsCheck.cpp
+  AvoidThrowingObjcExceptionCheck.cpp
   DefaultArgumentsCheck.cpp
   ExplicitConstructorCheck.cpp
   ExplicitMakePairCheck.cpp
Index: clang-tidy/google/AvoidThrowingObjcExceptionCheck.h
===
--- /dev/null
+++ clang-tidy/google/AvoidThrowingObjcExceptionCheck.h
@@ -0,0 +1,39 @@
+//===--- AvoidThrowingObjcExceptionCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace google {
+namespace objc {
+
+/// The check is to find usage of @throw invocation in Objective-C code.
+/// We should avoid using @throw for Objective-C exceptions according to
+/// Goo

[PATCH] D40058: add check to avoid throwing objc exception according to Google Objective-C guide

2017-11-15 Thread Yan Zhang via Phabricator via cfe-commits
Wizard updated this revision to Diff 123079.
Wizard marked 10 inline comments as done.
Wizard added a comment.

address comments


https://reviews.llvm.org/D40058

Files:
  clang-tidy/google/AvoidThrowingObjcExceptionCheck.cpp
  clang-tidy/google/AvoidThrowingObjcExceptionCheck.h
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GoogleTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/google-objc-avoid-throwing-exception.m

Index: test/clang-tidy/google-objc-avoid-throwing-exception.m
===
--- /dev/null
+++ test/clang-tidy/google-objc-avoid-throwing-exception.m
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t
+@class NSString;
+
+@interface NSException
+
++ (void)raise:(NSString *)name format:(NSString *)format;
+
+@end
+
+@implementation Foo
+- (void)f {
+NSString *foo = @"foo";
+@throw foo;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
+}
+
+- (void)f2 {
+[NSException raise:@"TestException" format:@"Test"];
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
+}
+@end
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -60,6 +60,7 @@
google-default-arguments
google-explicit-constructor
google-global-names-in-headers
+   google-objc-avoid-throwing-exception
google-objc-global-variable-declaration
google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
Index: docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - google-objc-avoid-throwing-exception
+
+google-objc-avoid-throwing-exception
+
+
+This check finds @throw usages in Objective-C files. For the same reason as the
+Google C++ style guide, we prefer not throwing exceptions from Objective-C code.
+
+Instead, prefer passing in ``NSError **`` and return ``BOOL`` to indicate success or failure.
+
+A counterexample:
+
+.. code-block:: objc
+
+  - (void)readFile {
+if ([self isError]) {
+  @throw [NSException exceptionWithName:...];
+}
+  }
+
+Instead, returning an error via ``NSError **`` is preferred:
+
+.. code-block:: objc
+
+  - (BOOL)readFileWithError:(NSError **)error {
+if ([self isError]) {
+  *error = [NSError errorWithDomain:...];
+  return NO;
+}
+return YES;
+  }
+
+The corresponding style guide rule:
+https://google.github.io/styleguide/cppguide.html#Exceptions
+http://google.github.io/styleguide/objcguide.html#avoid-throwing-exceptions
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `google-avoid-throwing-objc-exception
+  `_ check
+
+  Add new check to detect usage of @throw in Objective-C code, which should be avoided.
+
 - New `objc-property-declaration
   `_ check
 
Index: clang-tidy/google/GoogleTidyModule.cpp
===
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -15,6 +15,7 @@
 #include "../readability/NamespaceCommentCheck.h"
 #include "../readability/RedundantSmartptrGetCheck.h"
 #include "AvoidCStyleCastsCheck.h"
+#include "AvoidThrowingObjCExceptionCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "ExplicitConstructorCheck.h"
 #include "ExplicitMakePairCheck.h"
@@ -49,6 +50,8 @@
 "google-explicit-constructor");
 CheckFactories.registerCheck(
 "google-global-names-in-headers");
+CheckFactories.registerCheck(
+"google-objc-avoid-throwing-exception");
 CheckFactories.registerCheck(
 "google-objc-global-variable-declaration");
 CheckFactories.registerCheck(
Index: clang-tidy/google/CMakeLists.txt
===
--- clang-tidy/google/CMakeLists.txt
+++ clang-tidy/google/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_library(clangTidyGoogleModule
   AvoidCStyleCastsCheck.cpp
+  AvoidThrowingObjcExceptionCheck.cpp
   DefaultArgumentsCheck.cpp
   Explicit

  1   2   >