[PATCH] D42464: add prefix with '_' support for property name. Corresponding apple dev doc: https://developer.apple.com/library/content/qa/qa1908/_index.html

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 29 13:50:37 PST 2018


benhamilton accepted this revision.
benhamilton added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:123
+  size_t Start = PropertyName.find_first_of('_');
+  assert(Start != llvm::StringRef::npos);
+  auto Prefix = PropertyName.substr(0, Start);
----------------
Can you also check that Start + 1 < PropertyName.length() (e.g., the string doesn't end with a _)?

I know the regular expression shouldn't match this, so an assert is probably good. (There is logic later which tries to access Start + 1 without checking.)


================
Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:129
+  auto RegexExp =
+      llvm::Regex(llvm::StringRef(validPropertyNameRegex(Acronyms, false)));
+  return RegexExp.match(llvm::StringRef(PropertyName.substr(Start + 1)));
----------------
Don't need to explicitly wrap in llvm::StringRef, that class has an implicit constructor from std::string.

https://github.com/llvm-mirror/llvm/blob/master/include/llvm/ADT/StringRef.h#L95



================
Comment at: test/clang-tidy/objc-property-declaration.m:15-31
+ at interface Foo (Bar)
+ at property(assign, nonatomic) int abc_NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(assign, nonatomic) int abCD_camelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abCD_camelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int abcd_camelCase;
+ at property(assign, nonatomic) int abCD_NotCamelCase;
----------------
Can we add checks for properties whose names end with _?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42464





More information about the cfe-commits mailing list