From 8c348b33385e5d1c39d2b8e0af956d889bac65a1 Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Thu, 30 Nov 2017 19:05:08 +0000 Subject: 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 --- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++ clang-tools-extra/docs/clang-tidy/checks/list.rst | 1 + .../docs/clang-tidy/checks/objc-avoid-nserror-init.rst | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 clang-tools-extra/docs/clang-tidy/checks/objc-avoid-nserror-init.rst (limited to 'clang-tools-extra/docs') diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index acc6d9c4f45..f3078fc01a9 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -158,6 +158,11 @@ Improvements to clang-tidy 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 diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 1747ef23187..4feaa490507 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -173,6 +173,7 @@ Clang-Tidy Checks modernize-use-using mpi-buffer-deref mpi-type-mismatch + objc-avoid-nserror-init objc-avoid-spinlock objc-forbidden-subclassing objc-property-declaration diff --git a/clang-tools-extra/docs/clang-tidy/checks/objc-avoid-nserror-init.rst b/clang-tools-extra/docs/clang-tidy/checks/objc-avoid-nserror-init.rst new file mode 100644 index 00000000000..ce09d42413d --- /dev/null +++ b/clang-tools-extra/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 -- cgit v1.2.1