[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
This revision was automatically updated to reflect the committed changes. Closed by commit rL348331: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary… (authored by stephanemoore, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D51832?vs=176756=176759#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D51832/new/ https://reviews.llvm.org/D51832 Files: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-additional.m 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 @@ -1,8 +1,12 @@ // RUN: %check_clang_tidy %s objc-property-declaration %t +@class CIColor; +@class NSArray; @class NSData; @class NSString; @class UIViewController; +typedef void *CGColorRef; + @interface Foo @property(assign, nonatomic) int NotCamelCase; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration] @@ -23,6 +27,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @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 @@ -29,104 +29,12 @@ // For CategoryProperty especially in categories of system class, // to avoid naming conflict, the suggested naming style is // 'abc_lowerCamelCase' (adding lowercase prefix followed by '_'). +// Regardless of the style, all acronyms and initialisms should be capitalized. enum NamingStyle { StandardProperty = 1, CategoryProperty = 2, }; -/// The acronyms are aggregated from multiple sources including -/// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE -/// -/// 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", -}; - /// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to /// 'camelCase' or 'abc_camelCase'. For other cases the users need to /// come up with a proper name by their own. @@ -150,26 +58,26 @@ 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) { +std::string validPropertyNameRegex(bool UsedInMatcher) { // Allow any of these names: // foo // fooBar // url // urlString + // ID + // IDs // URL // URLString // bundleID + // CIColor + // + // Disallow names of this form: + // LongString + // + // aRbITRaRyCapS is allowed to avoid generating false positives for names + // like isVitaminBSupplement, CProgrammingLanguage, and isBeforeM.
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore updated this revision to Diff 176756. stephanemoore added a comment. Rebased changes and resolved merge conflicts. Moved release notes update next to other release notes regarding updates to existing checks. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D51832/new/ https://reviews.llvm.org/D51832 Files: clang-tidy/objc/PropertyDeclarationCheck.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/objc-property-declaration.rst test/clang-tidy/objc-property-declaration-additional.m 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 @@ -1,8 +1,12 @@ // RUN: %check_clang_tidy %s objc-property-declaration %t +@class CIColor; +@class NSArray; @class NSData; @class NSString; @class UIViewController; +typedef void *CGColorRef; + @interface Foo @property(assign, nonatomic) int NotCamelCase; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration] @@ -23,6 +27,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @end @interface Foo (Bar) Index: test/clang-tidy/objc-property-declaration-custom.m === --- test/clang-tidy/objc-property-declaration-custom.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}, \ -// RUN: {key: objc-property-declaration.IncludeDefaultAcronyms, value: 0}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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: test/clang-tidy/objc-property-declaration-additional.m === --- test/clang-tidy/objc-property-declaration-additional.m +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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 GIFShouldIncludeStandardAcronym; -@end 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 @@ -47,23 +47,8 @@ .. option:: Acronyms - Semicolon-separated list of custom acronyms that can be used as a prefix - or a suffix of property names. - - By default, appends to the list of default acronyms ( - ``IncludeDefaultAcronyms`` set to ``1``). - If ``IncludeDefaultAcronyms`` is set to ``0``, instead replaces the - default list of acronyms. + This option is deprecated and ignored. .. option:: IncludeDefaultAcronyms - Integer value
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore added a comment. Chatted with Ben offline and he's okay with proceeding. Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D51832/new/ https://reviews.llvm.org/D51832 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore added a comment. I believe that it should be safe to remove the `Acronyms` and `IncludeDefaultAcronyms` options but if it's alright with you, I would prefer to separate that into a followup change. Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:28-31 // For StandardProperty the naming style is 'lowerCamelCase'. // For CategoryProperty especially in categories of system class, // to avoid naming conflict, the suggested naming style is // 'abc_lowerCamelCase' (adding lowercase prefix followed by '_'). benhamilton wrote: > These comments are no longer accurate. I think the comments are still more or less accurate? I think we have just changed the level of enforcement that we are applying. We allow aRbITRaRyCapS now but that's based on the concession that it's fundamentally hard to identify appropriate lowerCamelCase with high precision (i.e., it is hard to reject "aRbITRaRyCapS" as a representation of "a rb IT ra ry cap S" without human judgment). I added a note that acronyms and initialisms are capitalized regardless of style though. ❧ Sidenote: A spark of curiosity led to me realizing that the previous approach would also have allowed aRbITRaRyCapS if all letters of the alphabet were to be whitelisted as acronyms. The previous check already included several letters in the default special acronyms and provided special treatment for "A" and "I" in the matching regex. I can't say for certain that every letter of the alphabet would have ended up being whitelisted but I audited the letters of the alphabet and I think I managed to construct a list of terms that could conceivably have been used in code and might have led to the whitelisting of each individual letter of the alphabet (attached below¹). [1] List of Letters in English Alphabet and Terms Containing Them in Isolation * A: https://en.wikipedia.org/wiki/A_value * B: https://en.wikipedia.org/wiki/B_vitamins * C: https://en.wikipedia.org/wiki/C_major * D: https://en.wikipedia.org/wiki/D_major * E: https://en.wikipedia.org/wiki/E_major * F: https://en.wikipedia.org/wiki/F-number * G: https://en.wikipedia.org/wiki/G_major * H: https://en.wikipedia.org/wiki/H-index * I: https://en.wikipedia.org/wiki/I_band_(NATO) * J: https://en.wikipedia.org/wiki/J_operator * K: https://en.wikipedia.org/wiki/Vitamin_K * L: https://en.wikipedia.org/wiki/L-notation * M: https://en.wikipedia.org/wiki/M_postcode_area * N: https://en.wikipedia.org/wiki/N_ray * O: https://en.wikipedia.org/wiki/Big_O_notation * P: https://en.wikipedia.org/wiki/Extrinsic_semiconductor#P-type_semiconductors * Q: https://en.wikipedia.org/wiki/Q_Score * R: https://en.wikipedia.org/wiki/R-value_(insulation) * S: https://en.wikipedia.org/wiki/S_postcode_area * T: https://en.wikipedia.org/wiki/F-number#T-stop * U: https://en.wikipedia.org/wiki/U_language * V: https://en.wikipedia.org/wiki/V_band * W: https://en.wikipedia.org/wiki/W_and_Z_bosons * X: https://en.wikipedia.org/wiki/X-ray * Y: https://en.wikipedia.org/wiki/Y_chromosome * Z: https://en.wikipedia.org/wiki/Z-buffering Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore updated this revision to Diff 172285. stephanemoore marked an inline comment as done. stephanemoore added a comment. Updated comments, release notes, and documentation to be consistent with the implemented changes. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 Files: clang-tidy/objc/PropertyDeclarationCheck.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/objc-property-declaration.rst test/clang-tidy/objc-property-declaration-additional.m 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 @@ -1,8 +1,12 @@ // RUN: %check_clang_tidy %s objc-property-declaration %t +@class CIColor; +@class NSArray; @class NSData; @class NSString; @class UIViewController; +typedef void *CGColorRef; + @interface Foo @property(assign, nonatomic) int NotCamelCase; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration] @@ -23,6 +27,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @end @interface Foo (Bar) Index: test/clang-tidy/objc-property-declaration-custom.m === --- test/clang-tidy/objc-property-declaration-custom.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}, \ -// RUN: {key: objc-property-declaration.IncludeDefaultAcronyms, value: 0}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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: test/clang-tidy/objc-property-declaration-additional.m === --- test/clang-tidy/objc-property-declaration-additional.m +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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 GIFShouldIncludeStandardAcronym; -@end 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 @@ -47,23 +47,8 @@ .. option:: Acronyms - Semicolon-separated list of custom acronyms that can be used as a prefix - or a suffix of property names. - - By default, appends to the list of default acronyms ( - ``IncludeDefaultAcronyms`` set to ``1``). - If ``IncludeDefaultAcronyms`` is set to ``0``, instead replaces the - default list of acronyms. + This option is deprecated and ignored. .. option:: IncludeDefaultAcronyms - Integer value (defaults to ``1``) to
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
benhamilton accepted this revision. benhamilton added a comment. This revision is now accepted and ready to land. This is fine, but please update the comments (and docs?) to make it clear that we no longer enforce camelCase but allow aRBiTraRYcAsE now. Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:28-31 // For StandardProperty the naming style is 'lowerCamelCase'. // For CategoryProperty especially in categories of system class, // to avoid naming conflict, the suggested naming style is // 'abc_lowerCamelCase' (adding lowercase prefix followed by '_'). These comments are no longer accurate. Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:73-74 + // + // Disallow names of this form: + // LongString std::string StartMatcher = UsedInMatcher ? "::" : "^"; Just to be clear, this also allows things like aRbITRaRyCapS, right? We should comment that this is explicitly by design. Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:113-115 // the property name should be in Lower Camel Case like // 'lowerCamelCase' + unless(matchesName(validPropertyNameRegex(true This comment is no longer accurate. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore updated this revision to Diff 164583. stephanemoore added a comment. Sorted forward declared classes in `objc-property-declaration.m`. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 Files: clang-tidy/objc/PropertyDeclarationCheck.cpp test/clang-tidy/objc-property-declaration-additional.m 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 @@ -1,8 +1,12 @@ // RUN: %check_clang_tidy %s objc-property-declaration %t +@class CIColor; +@class NSArray; @class NSData; @class NSString; @class UIViewController; +typedef void *CGColorRef; + @interface Foo @property(assign, nonatomic) int NotCamelCase; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration] @@ -23,6 +27,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @end @interface Foo (Bar) Index: test/clang-tidy/objc-property-declaration-custom.m === --- test/clang-tidy/objc-property-declaration-custom.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}, \ -// RUN: {key: objc-property-declaration.IncludeDefaultAcronyms, value: 0}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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: test/clang-tidy/objc-property-declaration-additional.m === --- test/clang-tidy/objc-property-declaration-additional.m +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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 GIFShouldIncludeStandardAcronym; -@end Index: clang-tidy/objc/PropertyDeclarationCheck.cpp === --- clang-tidy/objc/PropertyDeclarationCheck.cpp +++ clang-tidy/objc/PropertyDeclarationCheck.cpp @@ -34,91 +34,6 @@ CategoryProperty = 2, }; -/// The acronyms are aggregated from multiple sources including -/// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE -/// -/// Keep this list sorted. -constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = { -"[2-9]G", -"ACL", -"API", -"AR", -"ARGB", -"ASCII", -"AV", -"BGRA", -"CA", -"CF", -"CG", -"CI", -"CRC", -"CV", -"CMYK", -"DNS", -"FPS", -"FTP", -"GIF", -"GL", -"GPS", -"GUID", -"HD", -"HDR", -
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore updated this revision to Diff 164582. stephanemoore added a comment. Fix a couple issues: • Forward declare `NSArray` in `objc-property-declaration.m`. • Remove unnecessary lightweight generics declaration from `IDs` property in `objc-property-declaration.m` to fix compilation error. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 Files: clang-tidy/objc/PropertyDeclarationCheck.cpp test/clang-tidy/objc-property-declaration-additional.m 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 @@ -1,7 +1,11 @@ // RUN: %check_clang_tidy %s objc-property-declaration %t @class NSData; +@class NSArray; @class NSString; @class UIViewController; +@class CIColor; + +typedef void *CGColorRef; @interface Foo @property(assign, nonatomic) int NotCamelCase; @@ -23,6 +27,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @end @interface Foo (Bar) Index: test/clang-tidy/objc-property-declaration-custom.m === --- test/clang-tidy/objc-property-declaration-custom.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}, \ -// RUN: {key: objc-property-declaration.IncludeDefaultAcronyms, value: 0}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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: test/clang-tidy/objc-property-declaration-additional.m === --- test/clang-tidy/objc-property-declaration-additional.m +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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 GIFShouldIncludeStandardAcronym; -@end Index: clang-tidy/objc/PropertyDeclarationCheck.cpp === --- clang-tidy/objc/PropertyDeclarationCheck.cpp +++ clang-tidy/objc/PropertyDeclarationCheck.cpp @@ -34,91 +34,6 @@ CategoryProperty = 2, }; -/// The acronyms are aggregated from multiple sources including -/// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE -/// -/// Keep this list sorted. -constexpr llvm::StringLiteral DefaultSpecialAcronyms[] = { -"[2-9]G", -"ACL", -"API", -"AR", -"ARGB", -"ASCII", -"AV", -"BGRA", -"CA", -"CF", -"CG", -"CI", -"CRC", -"CV", -"CMYK", -"DNS", -"FPS", -"FTP", -"GIF", -"GL", -"GPS", -"GUID", -"HD", -"HDR", -"HMAC", -"HTML", -"HTTP", -"HTTPS", -"HUD",
[PATCH] D51832: [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms
stephanemoore created this revision. stephanemoore added reviewers: benhamilton, Wizard. Herald added subscribers: cfe-commits, jfb. §1 Description This changes the objc-property-declaration check to allow arbitrary acronyms and initialisms instead of using whitelisted acronyms. In Objective-C it is relatively common to use project prefixes in property names for the purposes of disambiguation. For example, the CIColor¹ and CGColor² properties on UIColor both represent symbol prefixes being used in proeprty names outside of Apple's accepted acronyms³. The union of Apple's accepted acronyms and all symbol prefixes that might be used for disambiguation in property declarations effectively allows for any arbitrary sequence of capital alphanumeric characters to be acceptable in property declarations. This change updates the check accordingly. The test variants with custom configurations are deleted as part of this change because their configurations no longer impact behavior. The acronym configurations are currently preserved for backwards compatibility of check configuration. [1] https://developer.apple.com/documentation/uikit/uicolor/1621951-cicolor?language=objc [2] https://developer.apple.com/documentation/uikit/uicolor/1621954-cgcolor?language=objc [3] https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE §2 Test Notes Changes verified by: • Running clang-tidy unit tests. • Used check_clang_tidy.py to verify expected output of processing objc-property-declaration.m Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51832 Files: clang-tidy/objc/PropertyDeclarationCheck.cpp test/clang-tidy/objc-property-declaration-additional.m 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 @@ -2,6 +2,9 @@ @class NSData; @class NSString; @class UIViewController; +@class CIColor; + +typedef void *CGColorRef; @interface Foo @property(assign, nonatomic) int NotCamelCase; @@ -23,6 +26,9 @@ @property(assign, nonatomic) int enableGLAcceleration; @property(assign, nonatomic) int ID; @property(assign, nonatomic) int hasADog; +@property(nonatomic, readonly) CGColorRef CGColor; +@property(nonatomic, readonly) CIColor *CIColor; +@property(nonatomic, copy) NSArray *IDs; @end @interface Foo (Bar) Index: test/clang-tidy/objc-property-declaration-custom.m === --- test/clang-tidy/objc-property-declaration-custom.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}, \ -// RUN: {key: objc-property-declaration.IncludeDefaultAcronyms, value: 0}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString *ABC_custom_prefix; -// 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: test/clang-tidy/objc-property-declaration-additional.m === --- test/clang-tidy/objc-property-declaration-additional.m +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %check_clang_tidy %s objc-property-declaration %t \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \ -// RUN: -- -@class NSString; - -@interface Foo -@property(assign, nonatomic) int AbcNotRealPrefix; -// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'AbcNotRealPrefix' 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 abcNotRealPrefix; -@property(assign, nonatomic) int ABCCustomPrefix; -@property(strong, nonatomic) NSString