Commit Graph

32 Commits

Author SHA1 Message Date
Yan Zhang 19bceda879 Update property prefix regex to allow numbers.
Subscribers: jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D56896

llvm-svn: 354485
2019-02-20 17:32:41 +00:00
Stephane Moore 358f99c7fe [clang-tidy] Delete obsolete objc-property-declaration options ✂️
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
2019-02-16 04:27:12 +00:00
Stephane Moore 05a449b481 Revert rCTE351921 to fix documentation geneeration.
Original review: https://reviews.llvm.org/D56945

llvm-svn: 351922
2019-01-23 02:58:59 +00:00
Stephane Moore be9eca442e [clang-tidy] Delete obsolete objc-property-declaration options ✂️
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
2019-01-23 02:34:21 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
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
2019-01-19 08:50:56 +00:00
Stephane Moore af4755aca8 [clang-tidy/checks] Update objc-property-declaration check to allow 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
2018-12-05 03:44:03 +00:00
Stephane Moore 20cd5f2e20 [clang-tidy] Fix reference to -[NSError init] in AvoidNSErrorInitCheck.h
llvm-svn: 347000
2018-11-15 22:38:39 +00:00
Yan Zhang cc1e9c414b Fix the issue that not recognizing single acronym with prefix as ObjC 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
2018-11-01 17:36:18 +00:00
Erik Pilkington fa98390b3c NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)
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
2018-10-30 20:31:30 +00:00
Ben Hamilton 2f0a1286f3 [clang-tidy/ObjC] Update list of acronyms in PropertyDeclarationCheck
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
2018-09-07 22:02:38 +00:00
Stephen Kelly 43465bf3fd Port getLocStart -> getBeginLoc
Reviewers: javed.absar

Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D50354

llvm-svn: 339400
2018-08-09 22:42:26 +00:00
Ben Hamilton 13af794726 [clang-tidy/ObjC] Add SQL to list of acronyms
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
2018-07-12 17:32:55 +00:00
Ben Hamilton 7ea884c58f [clang-tidy/ObjC] Add hashing algorithm acronyms to objc-property-declaration
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
2018-06-27 19:13:09 +00:00
Yan Zhang 72cecf9a63 - Add "AV" as new default acronym. - Add support for "I" and "A" in 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
2018-06-11 22:44:06 +00:00
Ben Hamilton 1ca21bb5e6 [checks/property-decls] Fix comment in 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
2018-06-07 21:30:56 +00:00
Yan Zhang 6a528854c4 add AR to acronyms of clang-tidy property check
Reviewers: hokein, benhamilton

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D46895

llvm-svn: 332382
2018-05-15 18:13:51 +00:00
Yan Zhang 4f9ead2356 Add support for ObjC property name to be a single acronym.
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
2018-05-04 18:14:08 +00:00
Ben Hamilton d4fb951ce3 [clang-tidy] Add Apple prefix acronyms to objc-property-declaration
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
2018-05-01 14:48:51 +00:00
Yan Zhang 0313614f4d add extra acronyms for objc property names
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
2018-04-18 20:09:10 +00:00
Yan Zhang c7faee73cc do not register matcher for objc-only checks when analyzing non-objc sources 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
2018-03-07 18:59:25 +00:00
Yan Zhang ee6303921b add UUID to the acronyms list of objc property name checks
Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D43775

llvm-svn: 326222
2018-02-27 18:35:53 +00:00
Yan Zhang ae5bc5aeea Support special acronyms inside property names and allow plural forms
Reviewers: benhamilton, hokein

Reviewed By: benhamilton, hokein

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D42947

llvm-svn: 324407
2018-02-06 21:40:38 +00:00
Yan Zhang 75b3b541d5 add prefix with '_' support for property name. Corresponding apple dev doc: 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
2018-01-30 01:44:00 +00:00
Ben Hamilton f94c10d91a [clang-tidy objc-property-declaration] New option IncludeDefaultAcronyms
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
2018-01-22 15:45:25 +00:00
Ben Hamilton 55c3a321a8 [clang-tidy objc-property-declaration] Expand list of ObjC acronyms
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
2018-01-18 20:51:24 +00:00
Yan Zhang 8c298d2ff2 add ID as a special acronym to objc property declaration check for property 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
2018-01-17 00:19:35 +00:00
Yan Zhang 9ecb33edbe add new check to find NSError init invocation
Subscribers: klimek, mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D40528

llvm-svn: 319460
2017-11-30 19:05:09 +00:00
Yan Zhang 8c348b3338 add new check to find NSError init invocation
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
2017-11-30 19:05:08 +00:00
Yan Zhang 2f20b36cc3 add new check to find OSSpinlock usage
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
2017-11-27 21:30:10 +00:00
Ben Hamilton 52161a5abd add new check for property declaration
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
2017-11-13 23:54:31 +00:00
Haojian Wu e010406e28 [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing
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
2017-10-27 07:41:36 +00:00
Haojian Wu abcd64ccbf [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks
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
2017-10-26 08:23:20 +00:00