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/clang-tidy/objc/ObjCTidyModule.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp') diff --git a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp index 674da34..19152c2 100644 --- a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp @@ -10,6 +10,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "AvoidNSErrorInitCheck.h" #include "AvoidSpinlockCheck.h" #include "ForbiddenSubclassingCheck.h" #include "PropertyDeclarationCheck.h" @@ -23,6 +24,8 @@ namespace objc { class ObjCModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "objc-avoid-nserror-init"); CheckFactories.registerCheck( "objc-avoid-spinlock"); CheckFactories.registerCheck( -- cgit v1.1