summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/objc
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlockStephane Moore2019-10-014-75/+0
| | | | | | | | | | | | | | | | | | | | | | | Summary: OSSpinLock* are Apple/Darwin functions, but were previously located with ObjC checks as those were most closely tied to Apple platforms before. Now that there's a specific Darwin module, relocating the check there. This change was prepared by running rename_check.py. Contributed By: mwyman Reviewers: stephanemoore, dmaclach Reviewed By: stephanemoore Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang, #llvm Differential Revision: https://reviews.llvm.org/D68148 llvm-svn: 373392
* [clang-tidy] Add check for classes missing -hash ⚠️Stephane Moore2019-09-214-0/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Apple documentation states that: "If two objects are equal, they must have the same hash value. This last point is particularly important if you define isEqual: in a subclass and intend to put instances of that subclass into a collection. Make sure you also define hash in your subclass." https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418795-isequal?language=objc In many or all versions of libobjc, -[NSObject isEqual:] is a pointer equality check and -[NSObject hash] returns the messaged object's pointer. A relatively common form of developer error is for a developer to override -isEqual: in a subclass without overriding -hash to ensure that hashes are equal for objects that are equal. It is assumed that an override of -isEqual: is a strong signal for changing the object's equality operator to something other than pointer equality which implies that a missing override of -hash could result in distinct objects being equal but having distinct hashes because they are independent instances. This added check flags classes that override -isEqual: but inherit NSObject's implementation of -hash to warn of the potential for unexpected behavior. The proper implementation of -hash is the responsibility of the developer and the check will only verify that the developer made an effort to properly implement -hash. Developers can set up unit tests to verify that their implementation of -hash is appropriate. Test Notes: Ran check-clang-tools. Reviewers: aaron.ballman, benhamilton Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67737 llvm-svn: 372445
* Remove \brief commands from doxygen comments.Dmitri Gribenko2019-08-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | Summary: We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done [This is analogous to LLVM r331272 and CFE r331834] Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66578 llvm-svn: 369643
* [clang-tidy] Migrate objc-super-self to use isDerivedFrom 🚛Stephane Moore2019-08-161-30/+17
| | | | | | | | | | | | | | | | | | | | | Summary: This migrates objc-super-self to `isDerivedFrom` as it now supports matching Objective-C interface declarations. Test Notes: Ran clang tools tests. Reviewers: aaron.ballman, gribozavr Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66270 llvm-svn: 369081
* [clang-tidy] Migrate objc-forbidden-subclassing to use isDerivedFrom 🚛Stephane Moore2019-08-161-28/+1
| | | | | | | | | | | | | | | | | | | | | Summary: This migrates objc-forbidden-subclassing to `isDerivedFrom` as it now supports matching Objective-C interface declarations. Test Notes: Ran clang tools tests. Reviewers: aaron.ballman, gribozavr Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66269 llvm-svn: 369076
* [clang-tidy] Add a check for [super self] in initializers 🔍Stephane Moore2019-04-174-0/+167
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This check aims to address a relatively common benign error where Objective-C subclass initializers call -self on their superclass instead of invoking a superclass initializer, typically -init. The error is typically benign because libobjc recognizes that improper initializer chaining is common¹. One theory for the frequency of this error might be that -init and -self have the same return type which could potentially cause inappropriate autocompletion to -self instead of -init. The equal selector lengths and triviality of common initializer code probably contribute to errors like this slipping through code review undetected. This check aims to flag errors of this form in the interests of correctness and reduce incidence of initialization failing to chain to -[NSObject init]. [1] "In practice, it will be hard to rely on this function. Many classes do not properly chain -init calls." From _objc_rootInit in https://opensource.apple.com/source/objc4/objc4-750.1/runtime/NSObject.mm.auto.html. Test Notes: Verified via `make check-clang-tools`. Subscribers: mgorny, xazax.hun, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59806 llvm-svn: 358620
* [clang-tidy] Switch checks to #include "ClangTidyCheck.h"Alexander Kornienko2019-03-254-4/+4
| | | | llvm-svn: 356892
* Update property prefix regex to allow numbers.Yan Zhang2019-02-201-10/+9
| | | | | | | | Subscribers: jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D56896 llvm-svn: 354485
* [clang-tidy] Delete obsolete objc-property-declaration options ✂️Stephane Moore2019-02-162-23/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: The Acronyms and IncludeDefaultAcronyms options were deprecated in https://reviews.llvm.org/D51832. These options can be removed. Tested by running the clang-tidy tests. This is an amended resubmission of https://reviews.llvm.org/D56945. Reviewers: Eugene.Zelenko, aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57080 llvm-svn: 354195
* Revert rCTE351921 to fix documentation geneeration.Stephane Moore2019-01-232-2/+23
| | | | | | Original review: https://reviews.llvm.org/D56945 llvm-svn: 351922
* [clang-tidy] Delete obsolete objc-property-declaration options ✂️Stephane Moore2019-01-232-23/+2
| | | | | | | | | | | | | | | | | | | | Summary: The `Acronyms` and `IncludeDefaultAcronyms` options were deprecated in https://reviews.llvm.org/D51832. These options can be removed. Tested by running the clang-tidy tests. Reviewers: benhamilton, aaron.ballman Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D56945 llvm-svn: 351921
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-199-36/+27
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-tidy/checks] Update objc-property-declaration check to allow ↵Stephane Moore2018-12-051-129/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | arbitrary acronyms and initialisms 🔧 Summary: §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 Reviewers: benhamilton, Wizard Reviewed By: benhamilton Subscribers: jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D51832 llvm-svn: 348331
* [clang-tidy] Fix reference to -[NSError init] in AvoidNSErrorInitCheck.hStephane Moore2018-11-151-1/+1
| | | | llvm-svn: 347000
* Fix the issue that not recognizing single acronym with prefix as ObjC ↵Yan Zhang2018-11-011-5/+4
| | | | | | | | | | | | | | | | property name. Summary: This will make clang-tidy accept property names like xyz_URL (URL is a common acronym). Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D53955 llvm-svn: 345858
* NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)Erik Pilkington2018-10-303-6/+6
| | | | | | | | | | We haven't supported compiling ObjC1 for a long time (and never will again), so there isn't any reason to keep these separate. This patch replaces LangOpts::ObjC1 and LangOpts::ObjC2 with LangOpts::ObjC. Differential revision: https://reviews.llvm.org/D53547 llvm-svn: 345637
* [clang-tidy/ObjC] Update list of acronyms in PropertyDeclarationCheckBen Hamilton2018-09-071-0/+8
| | | | | | | | | | | | Summary: This adds a few common acronyms we found were missing from PropertyDeclarationCheck. Reviewers: Wizard, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51819 llvm-svn: 341720
* Port getLocStart -> getBeginLocStephen Kelly2018-08-092-2/+2
| | | | | | | | | | Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
* [clang-tidy/ObjC] Add SQL to list of acronymsBen Hamilton2018-07-121-0/+1
| | | | | | | | | | | | | | Summary: SQL is a common acronym. Reviewers: Wizard, hokein Reviewed By: Wizard, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49190 llvm-svn: 336919
* [clang-tidy/ObjC] Add hashing algorithm acronyms to objc-property-declarationBen Hamilton2018-06-271-0/+6
| | | | | | | | | | | | | | | | Summary: This PR adds a few acronyms related to hashing algorithms to the standard list in `objc-property-declaration`. Reviewers: Wizard Reviewed By: Wizard Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48652 llvm-svn: 335770
* - Add "AV" as new default acronym. - Add support for "I" and "A" in ↵Yan Zhang2018-06-111-1/+2
| | | | | | | | | | | | | | | | lowerCamelCase pattern Summary: Now we can support property names like "hasADog" correctly. Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48039 llvm-svn: 334448
* [checks/property-decls] Fix comment in ↵Ben Hamilton2018-06-071-1/+1
| | | | | | | | | | | | | | | | | | clang-tidy/objc/PropertyDeclarationCheck.cpp ✍️ Summary: The comment incorrectly claims that the listed acronyms are all extracted from the linked Apple documentation. Reviewers: Wizard, benhamilton Reviewed By: Wizard, benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46922 Contributed by @stephanemoore. llvm-svn: 334238
* add AR to acronyms of clang-tidy property checkYan Zhang2018-05-151-0/+1
| | | | | | | | | | | | Reviewers: hokein, benhamilton Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46895 llvm-svn: 332382
* Add support for ObjC property name to be a single acronym.Yan Zhang2018-05-041-0/+6
| | | | | | | | | | | | | | | | | | | | | Summary: This change will support cases like: ``` @property(assign, nonatomic) int ID; ``` Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: klimek, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D46374 llvm-svn: 331545
* [clang-tidy] Add Apple prefix acronyms to objc-property-declarationBen Hamilton2018-05-011-0/+8
| | | | | | | | | | | | | | | | | | | | | Summary: This adds a few common Apple first-party API prefixes as acronyms to `objc-property-declaration`. Here's a list showing where these come from: http://nshipster.com/namespacing/ Test Plan: New tests added. Ran tests with: % make -j16 check-clang-tools Reviewers: Wizard, hokein Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D46206 llvm-svn: 331267
* add extra acronyms for objc property namesYan Zhang2018-04-181-0/+5
| | | | | | | | | | | | | | Summary: This is to support general acronyms in Objective-C like 2G/3G/4G/... and coordinates X, Y, Z and W. Reviewers: benhamilton Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45750 llvm-svn: 330286
* do not register matcher for objc-only checks when analyzing non-objc sources ↵Yan Zhang2018-03-073-0/+12
| | | | | | | | | | | | | | | | to save resources Summary: I did not put lang opt check in AvoidSpinlockCheck since OSSpinLock is not objc specific. We won't want to skip it when analyzing some C++ target used by other ObjC sources. Reviewers: hokein, benhamilton Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44174 llvm-svn: 326928
* add UUID to the acronyms list of objc property name checksYan Zhang2018-02-271-0/+2
| | | | | | | | | | | | Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43775 llvm-svn: 326222
* Support special acronyms inside property names and allow plural formsYan Zhang2018-02-061-7/+10
| | | | | | | | | | | | Reviewers: benhamilton, hokein Reviewed By: benhamilton, hokein Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42947 llvm-svn: 324407
* add prefix with '_' support for property name. Corresponding apple dev doc: ↵Yan Zhang2018-01-302-21/+79
| | | | | | | | | | | | | | https://developer.apple.com/library/content/qa/qa1908/_index.html Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42464 llvm-svn: 323722
* [clang-tidy objc-property-declaration] New option IncludeDefaultAcronymsBen Hamilton2018-01-222-67/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The existing option objc-property-declaration.Acronyms replaces the built-in set of acronyms. While this behavior is OK for clients that don't want the default behavior, many clients may just want to add their own custom acronyms to the default list. This revision introduces a new option, objc-property-declaration.IncludeDefaultAcronyms, which controls whether the acronyms in objc-property-declaration.Acronyms are appended to the default list (the default behavior) or whether they replace. I also updated the documentation. Test Plan: make -j12 check-clang-tools Reviewers: Wizard, hokein, klimek Reviewed By: hokein Subscribers: Eugene.Zelenko, cfe-commits Differential Revision: https://reviews.llvm.org/D42261 llvm-svn: 323130
* [clang-tidy objc-property-declaration] Expand list of ObjC acronymsBen Hamilton2018-01-181-12/+50
| | | | | | | | | | | | | | | | | | | | | Summary: We were missing some pretty common acronyms in the camelCase property name check objc-property-declaration. This expands the list and sorts it lexicographically, so we can avoid duplicates. Test Plan: make -j12 check-clang-tools Reviewers: Wizard, hokein, klimek Reviewed By: Wizard Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42253 llvm-svn: 322886
* add ID as a special acronym to objc property declaration check for property ↵Yan Zhang2018-01-171-8/+11
| | | | | | | | | | | | | | names like bundleID.allow using acronyms as suffix. Reviewers: benhamilton, hokein Reviewed By: benhamilton Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42143 llvm-svn: 322602
* add new check to find NSError init invocationYan Zhang2017-11-302-0/+0
| | | | | | | | Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D40528 llvm-svn: 319460
* add new check to find NSError init invocationYan Zhang2017-11-304-0/+77
| | | | | | | | | | | | | | | | | | | Summary: 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 in Xcode. The corresponding information about NSError creation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html Reviewers: hokein, benhamilton Reviewed By: benhamilton Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D40528 llvm-svn: 319459
* add new check to find OSSpinlock usageYan Zhang2017-11-274-0/+77
| | | | | | | | | | | | | | | | | | | | Summary: This check finds the use of methods related to OSSpinlock in Objective-C code, which should be deprecated due to livelock issues. The following method call will be detected: - OSSpinlockLock() - OSSpinlockTry() - OSSpinlockUnlcok() Reviewers: hokein, benhamilton Reviewed By: benhamilton Subscribers: klimek, cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D40325 llvm-svn: 319098
* add new check for property declarationBen Hamilton2017-11-134-0/+163
| | | | | | | | | | | | | | | | | | | | | | Summary: This check 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 or with some particular acronyms as prefix. Example: @property(nonatomic, assign) int lowerCamelCase; @property(nonatomic, strong) NSString *URLString; Test plan: ninja check-clang-tools Reviewers: benhamilton, hokein Reviewed By: hokein Subscribers: cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D39829 llvm-svn: 318117
* [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassingHaojian Wu2017-10-274-1/+164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is part 3 of 3 of a series of changes to improve Objective-C linting in clang-tidy. This adds a new clang-tidy check `objc-forbidden-subclassing` which ensures clients do not create subclasses of Objective-C classes which are not designed to be subclassed. (Note that for code under your control, you should use __attribute__((objc_subclassing_restricted)) instead -- this is intended for third-party APIs which cannot be modified.) By default, the following classes (which are publicly documented as not supporting subclassing) are forbidden from subclassing: ABNewPersonViewController ABPeoplePickerNavigationController ABPersonViewController ABUnknownPersonViewController NSHashTable NSMapTable NSPointerArray NSPointerFunctions NSTimer UIActionSheet UIAlertView UIImagePickerController UITextInputMode UIWebView Clients can set a CheckOption `objc-forbidden-subclassing.ClassNames` to a semicolon-separated list of class names, which overrides this list. Test Plan: `ninja check-clang-tools` Patch by Ben Hamilton! Reviewers: hokein, alexfh Reviewed By: hokein Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun Differential Revision: https://reviews.llvm.org/D39142 llvm-svn: 316744
* [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checksHaojian Wu2017-10-262-0/+52
Summary: This is part 1 of 3 of a series of changes to improve Objective-C linting in clang-tidy. This introduces a new clang-tidy module, `objc`, specifically for Objective-C / Objective-C++ checks. The module is currently empty; D39142 adds the first check. Test Plan: `ninja check-clang-tools` Patch by Ben Hamilton! Reviewers: hokein, alexfh Reviewed By: hokein Subscribers: Wizard, mgorny Differential Revision: https://reviews.llvm.org/D39188 llvm-svn: 316643
OpenPOWER on IntegriCloud